ATtiny Capacitive Touch
I wrote a program that uses the capacitive touch sensor libraryainnsor/ for arduino to detect a finger touching the tip of a wire (or grasping the wire) and associates the sensor value with red, yellow and green leds. If there is a low value / no touch the red led turns on, if there is a light touch detected the yellow led turns on, and if there is a hard touch / finger grabbing the wire detected the green light is turned on.
#include <CapacitiveSensor.h> CapacitiveSensor Sensor = CapacitiveSensor(3, 4); long capVal; #define green 2 #define yellow 1 #define red 0 void setup() { Serial.begin(9600); pinMode(green, OUTPUT); pinMode(red, OUTPUT); pinMode(yellow, OUTPUT); } void loop() { capVal = Sensor.capacitiveSensor(30); //Serial.println(val); if (capVal < 50){ digitalWrite(red,HIGH); digitalWrite(yellow,LOW); digitalWrite(green,LOW); } else if(capVal >= 50 && capVal <100){ digitalWrite(red,LOW); digitalWrite(yellow,HIGH); digitalWrite(green,LOW); } else if (capVal >= 100) { digitalWrite(red,LOW); digitalWrite(yellow,LOW); digitalWrite(green,HIGH); } delay(500); }