Introduction: Wireless Illuminated Resistive Touch Button
This is a simple project with idea of creating a resistive touch button that integrates RGB Led. Whenever this button is touched, it will be lighted up and lamp’s color can be customized. It can be used as a portable illuminated touch button through wireless network.
Lets take a look at my videos:
Step 1: B.O.M
Step 2: SCHEMATIC & BOARD ASSEMBLY
- Schematic
- Board assembly
The touch sensor is made from copper wire 6mm2 and 10mm RGB led. Copper wires are bent around RGB led with shape as shown on below picture and soldered to the PCB prototype.
I added one more button for mode selection option, so this touch button can be controlled with some functions like: LOCK MODE, ON/OFF MODE, TOGGLE MODE....
Step 3: EXPLANATION
Let's see schematic below:
When touching, the human finger acts as a resistor and allows small current to flow through it, making slight electrical change at Arduino analog pin. Practically, when I measured voltage between 2 copper wires, it’s shown:
- No finger touched: 3.29V
- With finger touched: 3.24V
Voltage drop 0.05V (50mV) can be detected by Analog pin A0 of NodeMCU. When I read analog input A0 through serial port, it shows:
- With no finger touch, reading value is about 3 in engineering unit.
- With finger touched, reading value fluctuates around 16 in engineering unit.
Due to reading value fluctuation, I have to do average about 20 samples to get accurate value. Please check at next step to see this tip.
Contacting area of touching finger is very important in this case. That why I bent the touch cooper wires with suitable shape to increase contacting area. During testing, this resistive touch button works stably and exactly when it's touched by two fingers.
This resistive touch button works well even if Arduino is powered by battery or power supply.
Step 4: PROGRAM
const int LED_B=5; const int LED_G=4; const int LED_R=0; const int Button=14; const int inputPin = A0; int inputVal=0; int buttonPushCounter = 0; int buttonState = 0; int lastButtonState = 0; const int numReadings = 20; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average int state = 0, LEDstate=0; bool DEBUG = 0; void setup() { pinMode(LED_B,OUTPUT); pinMode(LED_G,OUTPUT); pinMode(LED_R,OUTPUT); for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } Serial.begin(9600); } void loop() { buttonState = digitalRead(Button); if (buttonState != lastButtonState) { if (buttonState == HIGH) { buttonPushCounter++; } else { } } lastButtonState = buttonState; switch (buttonPushCounter % 3) { case 2: // TOGGLE MODE // subtract the last reading: total = total - readings[readIndex]; // read from the sensor: readings[readIndex] = analogRead(inputPin); // add the reading to the total: total = total + readings[readIndex]; // advance to the next position in the array: readIndex = readIndex + 1; // if we're at the end of the array... if (readIndex >= numReadings) { // ...wrap around to the beginning: readIndex = 0; } // calculate the average: average = total / numReadings; if (state == 0 && (average>10) == HIGH) { state = 1; LEDstate=!LEDstate; } if (state == 1 && (average>10) == LOW) { state = 0; } if (LEDstate==HIGH){ analogWrite(LED_B,512); analogWrite(LED_G,0); analogWrite(LED_R,1023); } else{ analogWrite(LED_B,0); analogWrite(LED_G,1023); analogWrite(LED_R,0); } break; case 1: // ON/OFF MODE // subtract the last reading: total = total - readings[readIndex]; // read from the sensor: readings[readIndex] = analogRead(inputPin); // add the reading to the total: total = total + readings[readIndex]; // advance to the next position in the array: readIndex = readIndex + 1; // if we're at the end of the array... if (readIndex >= numReadings) { // ...wrap around to the beginning: readIndex = 0; } // calculate the average: average = total / numReadings; if(average<=10){ analogWrite(LED_B,0); analogWrite(LED_G,0); analogWrite(LED_R,1023); } else { analogWrite(LED_B,0); analogWrite(LED_G,1023); analogWrite(LED_R,0); } break; case 0: // LOCK MODE analogWrite(LED_B,1023); analogWrite(LED_G,1023); analogWrite(LED_R,1023); break; } //For serial monitor if (DEBUG) { for(int i=0;i<average;i++){ Serial.print("-"); } Serial.println(average); } }
Step 5: TOUCH BUTTON IS INTEGRATED TO PLC SYSTEM
For next step, I will integrate this portable button to Siemens PLC system through wireless to turn on & off the lamp. It will be so COOL and take my time!