Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Webotricks
Published

How to make a touch control table lamp with Arduino

In this project, we will learn how to make a touch-control table lamp with Arduino.

BeginnerProtip2 hours98
How to make a touch control table lamp with Arduino

Things used in this project

Hardware components

Touch Sensor
×1
Relay Module
×1
Jumper Wires
×1

Story

Read more

Code

Code

Arduino
#define sensor 3
#define relay 2
 
bool value;
bool checkOne;
bool checkTwo = true;
 
void setup() {
  Serial.begin(9600);
  pinMode(sensor, INPUT);
  pinMode(relay, OUTPUT);
 
  digitalWrite(relay, HIGH);
}
 
void loop() {
  value = digitalRead(sensor);
 
  if (value == 1) {
    if (checkOne) {
      Serial.println("ON");
      digitalWrite(relay,LOW);
      checkTwo = false;
    } else {
      Serial.println("OFF");
      digitalWrite(relay,HIGH);
      checkTwo = true;
    }
  } else if (value == 0) {
    if (checkTwo == true) {
      checkOne = true;
    } else {
      checkOne = false;
    }
 
  }
}

Credits

Webotricks
28 projects • 9 followers
Contact

Comments

Please log in or sign up to comment.