Contact Less Switch

by Gaganram PM in Circuits > Arduino

2194 Views, 5 Favorites, 0 Comments

Contact Less Switch

IMG20200913210704.jpg
download (11).jpg
relay.jpg
sonar sennsor.jpg
jumper.jpg
Arduino contactless Switch #Arduino #COVID 19

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.

Supplies

1.Arduino UNO: Amazon

2. Ultrasonic sensor: Amazon

3. Relay Module: Amazon

4. Jumper Wires :Amazon

Make the Connections!

circuit.JPG
  • 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.

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
  delayMicroseconds(2);
  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
  Serial.println(distance);
  // 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
    }

  
  delay(500);
}<br>

Upload the Code and Test Them OUT!!!!

Contactless Switch 1

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