Move your Hand around - Lights ON, move hands over again - Lights OFF, sounds cool right?
Today we'll be making an automatic system to control appliances by hand gesture or Motion sensing using just Arduino and PIR sensor.
In our project we'll make an Emergency light that lights On / Off by just moving your hand around it. In another word gesture or wave controlled light system. This can be used as an emergency light - when you reach home it'll automatically switch the lights on.
So our goal is to make a system that switches on once you wave at it, and switches off when you wave it back again.
There's Some issues to keep in mind before you'd work with PIR sensor.
- PIR doesn't work properly for at least one minute when starts.
- PIR output value is always 1 for some seconds.
- It some times doesn't read motions.
To Solve that I've made a simple algorithm that's explained Here.
Circuit Diagram
Circuit is pretty simple, I'm driving some lEDs on but if you want to control home appliances or bigger loads like main light or fan here's a circuit with relay module.
Make the circuit and it should look something like this
Upload Code to arduino Pro mini 5v 16 mHz
See, Arduino pro mini doesn't have USB programming option. So you may Upload code using a USB to TTL converter. Or you may use an Arduino Uno. We all have an uno right?
So let's upload code using an arduino Uno.
- Remove The ATmega IC from Uno (using a screwdriver) [be carefull not to harm the IC]
- Connect Arduino pro mini ------ Uno as following
- TX to tx
- Rx to rx
- Vcc to 5v
- Gnd to gnd
- rst to Reset
Note: You can just upload code to Arduino pro (5v 16 mHz) mini using UNO not the 3.3v one. Check before you buy one.
Now download the code from github
or copy from below
/** Gesture / Motion Controlled Appliance - automatic Light !! ** * by Ashraf Minhaj. * for any query ashraf_minhaj@yahoo.com * Tutorial on http://ashrafminhajfb.blogspot.com * youtube https://youtube.com/c/fusebatti */ int s = 12; //PIR outPin on digital 10 int led1 = 4; //led1 on 4 int led2 = 9; //led2 on 9 void setup() // put your setup code here, to run once: { pinMode(s,INPUT); //Setting Sensor as Input pinMode(led1,OUTPUT); pinMode(led2,OUTPUT); //LED pin as output Serial.begin(9600); //initialize Serial Monitor- for debugging(else not mandatory) } void loop() { digitalWrite(led1,LOW); //By default lights off digitalWrite(led2,LOW); delay(60000); //1 minute delay so that the PIR gets enough hot to function Serial.println("Start"); //Shows a start message goto off; //going to off ON: //the ON statement { Serial.println("ON is running"); digitalWrite(led1,HIGH); digitalWrite(led2,HIGH); if((digitalRead(s))) //if Again sensor input has been read - switch off { digitalWrite(led1,LOW); //switch off digitalWrite(led2,LOW); delay(6500); //around 7 seconds delay /* PIR needs at least 5 seconds to function again*/ goto off; } else //Else just Be ON { goto ON; } } off: //OFF statement { Serial.println("OFF is running"); digitalWrite(led1,LOW); digitalWrite(led2,LOW); if((digitalRead(s))) //if again sensor input has been read - switch ON { digitalWrite(led1,HIGH); //switch on digitalWrite(led2,HIGH); delay(6500); /* PIR needs at least 5 seconds to function again*/ goto ON; } else //just be off { goto off; } } }
Then Upload and
Power it Up
For powering this use 7.4v to 11.4 volts. Although I've said that 5v is okay, its okay as long as loads are limited and you are powering from a 1Amp source.
Power up and- Have fun.
Happy Making!!!!
Thank you for posting this excellent information..it is very useful to me..!
ReplyDeleteClick here:
PIR Sensor