TOUCH SENSOR
TOUCH SENSOR
Application:
- It can be used as Light switches for computers and peripherals.
- It can be used in Home appliances for Door-lock systems.
- It is used in Game consoles and toys in Industrial control.
Sample Project With Arduino:
Materials required:
- ARDUINO UNO Board
- Touch Sensor
- Relay
- Bulb
Circuit:
#define TouchSensor 9 // defining touch
sensor in pin 9
int relay = 2; // initializing relay in pin 2
boolean currentState = LOW; //initializing current state of touch sensor
as LOW
boolean lastState = LOW; //initializing last state of the touch sensor
as also LOW
boolean RelayState = LOW; //initializing state of
the relay as LOW
void setup()
{
Serial.begin(9600); // enabling serial
communication
pinMode(relay, OUTPUT); //defining relay as
output
pinMode(TouchSensor, INPUT); //defining touch sensor
as input
}
void loop() {
currentState
= digitalRead(TouchSensor); // Read the sensor state and store it in a
variable
if
(currentState == HIGH && lastState == LOW) //Checking the current & last state of
the sensor
{
Serial.println("pressed"); //if the condition is true, print on serial
monitor
delay(1);
if (RelayState == HIGH) //Checking condition for state of the
relay to be high
{
digitalWrite(relay, LOW); // writing value LOW to relay
RelayState = LOW; //now the
relaystate is turns LOW
}
else
{
digitalWrite(relay, HIGH); // if the condition is not true, write
value HIGH to relay
RelayState = HIGH; // now the relay state turns HIGH
}
}
lastState =
currentState; // store the current state value as the
last state value
}
Comments
Post a Comment