Contact Less Switch

Introduction: Contact Less Switch

Now we all know that the world has a very bad situation and people are scared for touching things.

So during the Lockdowns I made this contactless switch. Which is very easy to make and code.

This is very useful to stop spread of COVID-19.

I am Studying in 9th grade.


1.Arduino UNO: Amazon

2. Ultrasonic sensor: Amazon

3. Relay Module: Amazon

4. Jumper Wires :Amazon

Step 1: Make the Connections!

  • Connect the GND pin of the Ultrasonic to GND pin of Arduino.
  • Connect the VCC pin of the Ultrasonic to the 5V pin of the Arduino.
  • Connect the TRIGG pin of the Ultrasonic to the Digital pin 9 of the Arduino.
  • Connect the ECHO pin of the Ultrasonic to the Digital pin 10 of the Arduino.
  • Connect the GND and VCC pin of relay to the GND and 5V pin of Arduino.
  • Connect the IN pin of the relay to the Digital pin 2 of Arduino.
  • NOTE: The connections in the above Figure is Different.

Step 2: Time to Code!!

Use the Below code to programme the Arduino<br>
bool x = 0;                          //holds one of two values, true or false
int relayPin = 2;                    //defines PIN 2 as relay
const int trigPin = 9;               //defines PIN 9 as trigPin of Ultrasonic sensor
const int echoPin = 10;              //defines PIN 10 as echoPin of Ultrasonic sensor
long duration;                       //defines a variable
int distance;                        //defines a variable
void setup() {
  pinMode(trigPin, OUTPUT);          //sets trigPin as OUTPUT
  pinMode(echoPin, INPUT);           //sets echoPin as INPUT
  pinMode(relayPin, OUTPUT);         //sets relayPin as OUTPUT
  Serial.begin(9600);                //starts the Serial Communication
void loop() {
  digitalWrite(trigPin, LOW);        // Clears the trigPin
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);             // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, LOW);        // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;   // Calculating the distance
  Serial.print("Distance: ");        // Prints the distance on the Serial Monitor
  // The minimum distance needed to activate the switch
  if (distance < 10)  {
    x = !x;

    if (x == 0) {
      digitalWrite(relayPin, HIGH);  // ON the Light
      Serial.println("Light is OFF"); //prints light is OFF
  if (x == 1) {
    digitalWrite(relayPin, LOW);     // OFF the Light
    Serial.println("Light is ON");  //prints light is ON


Step 3: Upload the Code and Test Them OUT!!!!

Plug the arduino to the computer and upload the code.

If you Like the Project Please VOTE me to the "CAN'T TOUCH THIS" CONTEST

"Can't Touch This" Family Contest

Participated in the
"Can't Touch This" Family Contest

Be the First to Share


    • Anything Goes Contest

      Anything Goes Contest


    Mickey The Maker
    Mickey The Maker

    Question 1 year ago

    it does not work. the relay goes on off on off on off.


    2 years ago

    Makes sense, looks useful! But picture this: you have a bunch of arduinos around your room, easily the small Attiny85 or Wemos D1 mini boards (they are very cheap and you only need a couple of pins, right), was with a laser sensor (a detector). And you have a laser pointer around your bed. Wouldn`t it be cool to do things depending on what of the sensors you aim?

    Or better yet, have the same with IR sensors and an old TV remote as I have it. :d)
    ...or for a DIY remote look at ;o)