Interfacing of Arduino with Touch Sensor and Appliance
#define TouchSensor 9 // Pin for touch sensor
int bulb = 3;
boolean currentState = LOW;
boolean lastState = LOW;
boolean bulbState = LOW;
void setup() {
Serial.begin(9600);
pinMode(bulb, OUTPUT);
pinMode(TouchSensor, INPUT);
}
void loop() {
currentState = digitalRead(TouchSensor);
if (currentState == HIGH && lastState == LOW){
Serial.println("pressed");
delay(1);
if (bulbState == HIGH)
digitalWrite(bulb, LOW);
bulbState = LOW;
}
else {
digitalWrite(bulb, HIGH);
bulbState = HIGH;
}
}
lastState = currentState;
}
0 comments:
Post a Comment
if you have any doubt please let me know