Hi nerdz,
today i’ll show you how to easily control remotely your room with a stupid motion detector, a piro sensor (or you can use other sensors, like ultrasonic, infrared, light sensor, pressure, etc etc…) and two lines of PHP code and C.
* Useful if you want to know if anyone enter in your room and the time that remains there! *
You can get this sensor from AirWick deo!
How it works?
Your piro sensor, when detect a motion, notify arduino, that was programmed to send to serial port a value (“m” or “n”).
These value are interpreted by a serial reader (c# program, objective-c, java, c++, or somethig else) that call a PHP page that send email if is enabled sending mode.
Second php page, permit you to control arduino (enable/disable/show logs/clear all).
Steps:
Connect your piro sensor to arduino, easy way, like this:
if(val ==110){// "n" = 110 in dec from ascii
mail = HIGH; }elseif(val ==109){//109 = "m" in dec from ascii
mail = LOW;
/* accendo il led*/
digitalWrite(ledPin, HIGH);
/* fischio avviso mail
tipo fischio di fine
partita di calcio */
digitalWrite(beepPin, HIGH);
delay(500);
digitalWrite(beepPin, LOW);
delay(200);
digitalWrite(beepPin, HIGH);
delay(500);
digitalWrite(beepPin, LOW);
delay(200);
digitalWrite(beepPin, HIGH);
delay(3000);
/* rimetto tutto a posto */
digitalWrite(beepPin, LOW);
digitalWrite(ledPin, LOW); } }
After that Arduino code was uploaded to chip and programmed successfully, I make a C# app that loop on “while true” to check google mails every 10 seconds.
If there is a new incoming mail, it send to serial port (COM9, 9600) a char, “m” for new mail and “n” for NO mail that are interpreted from arduino respectly to 109 and 110 in DEC format.
Arduino CODE recognize the DEC (ascii code, m||n) and executed code relatively condition.
If there was a “m” code, it send an HIGH signal (1) to GREEN LED and an HIGH to speacker (temporized).
Until you don’t read your message, it beeps every 10 seconds!!
To do all of this tricks, you need to create a C# Windows || Console app and run on COM9 listening arduino.
This is C# code (VS2010 – C#4.0):
/* SEND / READ SERIAL PORT COM9 DATA */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
try{
SerialPort port =new SerialPort("COM9", 9600, Parity.None, 8, StopBits.One);
port.Open();
Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.
www.arduino.cc
It’s learning time… stay tuned for Videos and Tutorials!!