Sunday 25 June 2017

Interfacing of Arduino with Touch Sensor and Appliance

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;
}

Circuit Diagram:



0 comments:

Post a Comment

if you have any doubt please let me know