Introduction: Power Saving Ultrasonic Switch

Picture of Power Saving Ultrasonic Switch

This is a prototype switch that automatically switches off any appliance that you have connected to your relay being a 2 way up to a 10 way relay for this specific one i am using a 2 way relay and will only be showing how to build the switch NOT CONNECT IT as it is very straight forward, this prototype also save enormous amount of electricity for obvious reasons.

Step 1: First Gather Parts

Picture of First Gather Parts

1. arduino uno R3

2. (2) way relay, any will work

3. jumper cables

4. breadboard (not necessary but easier to work with)

5. HC-SR04 ultrasonic ping sensor

Step 2: Tools

Picture of Tools

All you need are

1. A to B arduino USB

2. Arduino programming software

3. Your hands

Step 3: Assembly

Picture of Assembly

1. take 1 ground and 1 5v jumper cable from your arduino to your breadboard

2. connect the grounds and the vcc from the relay and the sensor to the grd and vcc rail on your breadboard

3. connect all of your relay channels to the breadboard and the to digital pin 10 on your arduino

4. connect the echo pin on the ultrasonic sensor to digital pin12

5. connect the trig pin on the sensor to digital pin13

6. done !!!

Step 4: Coding

Connect your arduino to your pc

make sure you have selected the right board

then upload this sketch


#define trigPin 13

#define echoPin 12

#define led 11

#define led2 10

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(led, OUTPUT);

pinMode(led2, OUTPUT);

}

void loop() {

long duration, distance;

digitalWrite(trigPin, LOW); // Added this line

delayMicroseconds(2); // Added this line

digitalWrite(trigPin, HIGH);

// delayMicroseconds(1000); - Removed this line

delayMicroseconds(10); // Added this line

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if (distance < 4) { // This is where the Relay On/Off happens

digitalWrite(led,HIGH); // Relay on

digitalWrite(led2,LOW);

}

else {

digitalWrite(led,LOW);

digitalWrite(led2,HIGH);

}

if (distance >= 200 || distance <= 200){

Serial.println("Out of range");

}

else {

Serial.print(distance);

Serial.println(" cm");

}

delay(5000);

}


Step 5: Testing

place this setup within a meter of your door and walk through after connecting the relays if you have any problems please feel free to contact me.

Comments

viswadevan (author)2015-01-30

Hi Jandre... Been trying to figure out on the hook up plus the code.

I'm ok with the hook up how do i get around with the code? After using your code i'm getting out of range all the way...

Anyways this will safe alot of money if we were to place it on electronics that is on for no reason... good idea...

About This Instructable

861views

9favorites

License:

More by Jandre395:Power saving Ultrasonic switchThe free energy prototype
Add instructable to: