Connecting a basic Touch sensor

This example shows how to interface a basic touch sensor to our Wemos Mini (esp8266), this sensor came as part of a kit of 37 sensors and modules, these are extremely popular on the internet and there are various devices in the box such as LEDs, temperature sensors, sound modules and more

touch-sensor

These are connected as follows, the Analog pin you do not have an option with but I just used D0, you could use another

Pin Label Wemos Connection
1 AO Analog input – A0
2 G Ground (GND)
3 + 3v3 volt power
4 DO Digital input – D0

So a quick and easy test is to write a sketch which outputs the digital and analog readings to the serial port and then see if we can get the readings to change

Code

[codesyntax lang=”cpp”]

//D0 and A0 used
const int digital = D0;
const int analog = A0;

void setup()
{
pinMode(digital, INPUT);
Serial.begin(9600);
}

void loop()
{
Serial.print(digitalRead(digital));
Serial.print("-");
Serial.println(analogRead(analog));
delay(250);
}

[/codesyntax]

Now compile and upload this and open the serial monitor and set the baud rate to 115200 and you should see something like the following

touch-serial-monitor-output

As you can see there are 2 sets of readings

The 0 and 1023 is the reading when no touch is detected. The 1 and 113 is the reading when a touch is detected

 

Links

Here are links to the sensor kit, we have included an image of the box you can get, sometimes the sensors do not come in a box and are a bit cheaper : you can get this set for about $25
37 in 1 box Sensor Kit For Arduino Starters brand in stock good quality low price