How to make AC/DC touch switch with arduino.

Posted by moudud 08/05/2019 0 Comment(s)
How to make AC/DC touch switch with arduino.
 
 


 

 

A touch switch is a type of switch that only has to be touched by an object to operate. It is used in many lamps and wall switches that have a metal exterior as well as on public computer terminals. A touchscreen includes an array of touch switches on a display. A touch switch is the simplest kind of tactile sensor.

 

 


Circuit Diagram :


 

 

Touch sensor & Relay Module connection with Arduino
 PinArduino
Touch SensorVCC5V
GNDGND
OUT/SignalD2
Relay ModuleVCC5V
GNDGND
SignalD13

 

 

 


Code

 

int inPin = 2;         // the number of the input pin
int outPin = 13;       // the number of the output pin

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
}

void loop()
{
  reading = digitalRead(inPin);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    
  }

  digitalWrite(outPin, state);

  previous = reading;
}

 

 

 

Write a Comment