DIY Touch Sensor/Switch ESP8266 | Node MCU

About: Maker ,Observer ,Reverse Engineer .Everything but theoretical.

NodeMCU has a single ADC(Analog to Digital Converter) input which is not suffice for big complex projects but is definitely enough for small projects which require a single analog sensor or even a simple switch. The in-built analog-to-digital converter of NodeMCU has 10 bit range i.e it gives value between 0 to 1024 and can take maximum input of 3.3v .So 0v input or GND returns value 0 at ADC pin and 3.3v returns 1024.

Now this analog-to-digital converter is very sensitive .It can sense close circuit between itself and the 3.3v pin of the NodeMCU and can return values according to the resistance between them. This can be used for a switching action or even brightness control of a LED. And such a switch can be made easily without any extra parts.

Step 1: Wiring.

Connect a wire to 3.3v pin and one more to the ADC pin.Now place both these wire near each other or use stapler pins or naked jumper wires on the breadboard. Now when we touch both of these terminals the ADC pin is returning values according to the resistance of our finger or thumb (it can't be as good as the capacitive modules .It will work with everything as long as it has some conductivity) .When more pressure is applied the values are higher (the awesome part).

Following code can be used in Arduino IDE to read the ADC values in Serial Monitor and control brightness of inbuilt LED :

const int ain=A0;
const int LED=2;
int inputVal=0;
void setup()
{
pinMode(LED,OUTPUT);
Serial.begin(9600);
}
void loop()
{
inputVal=analogRead(ain);
if(inputVal<=20)
{
analogWrite(LED,1024);
}
else if(inputVal>20 && inputVal<50)analogWrite(LED,768);
else if(inputVal>50 && inputVal<100)analogWrite(LED,512);
else if(inputVal>100 && inputVal<1000)analogWrite(LED,256);
else {analogWrite(LED,0);}
//for serial monitor
for(int i=0;i{
Serial.print("-");
}
Serial.println(inputVal);
}


Step 2: One More Method.

To be more creative ,a touch surface can be made for a long term use using a paper and pencil . :) yes you read that right.

Make sure the graphite layer from the pencil lead is dark and the end terminals are big and dense.

Note that :

1.The traces may fade over time, so they need be drawn again.

2.Sensitivity values can be changed in the code as per requirement by observing serial monitor.

3.Values were unstable when I powered NodeMCU with my laptop and my laptop had its charger plugged in (maybe some grounding issues). With other power sources it worked fine.

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Optics Contest

      Optics Contest

    2 Discussions

    0
    None
    DIY Hacks and How Tos

    4 months ago

    Good idea that is a great way to make a simple custom switch

    0
    None
    AdityaK194

    4 months ago on Step 2

    Wow bro! Why didn't I think that cool.