School project with Capacitive Touch

Hi i am making a school project and i am using a micro bit v2 and attaching a very long 8-9M copper wire to it and i need it to go off when it is touched have have done the basic code and it only works in short distance. how can i fix it/ increase the sensitivity?

any help would be appreciated
Thank you

1 Like

It can help if you can provide code you have made so we can see the issue. Simply asking how to fix it can be a bit ambiguous. Unfortunately, this isn’t a topic I am good in (I’m better for working in makecode arcade then makecode for micro:bit). Also, welcome to the makecode fourm’s @Piggnugget456!

2 Likes

Hello! This happens because the “when pin triggered” block (I forget what it’s actually called) has a certain “activation voltage” that needs to be reached in order for it to count as activated. This is to avoid random activations from lower voltage interferences and such (idk).

What you can probably do is make your own activation voltage by continuously analogue reading the pin and having your activation code run when a certain threshold is crossed. You may have to experiment a bit to find a good balance above activation from random sources but below the signal from touching the very end of the wire.

I suppose it may be that touching the end of the wire is not very different from the random sources, in which case you won’t be able to tell them apart, but I hope not! I would start by having the micro:bit read out the detected voltage when touching the wire vs when not touching the wire, so you know where is an appropriate place to start, then tune it from there. You might even need to consider insulating the wire from sources if the voltage is too close to the random noise voltage, but probably not. Good luck and have fun!

2 Likes

hi thank you i think i figured it out i got chatgpt to help me but i think it works

THIS IS JAVA SCRIPT

// Example for an external capacitive touch sensor connected to pin0
basic.forever(function () {
    // Read the raw capacitive value from pin0
    let touchValue = pins.analogReadPin(AnalogPin.P0);

    // Print the value for debugging (useful to find a good threshold)
    console.log(touchValue);

    // Adjust the threshold for sensitivity as needed (lower = more sensitive)
    if (touchValue > 200) {  // Adjust '200' based on testing
        basic.showIcon(IconNames.Heart);
    } else {
        basic.clearScreen();
    }

    basic.pause(100);
});