Today, a simple Arduino project that permit you to power on something connected to a 220v power using a simple relay.
What you need for this example:
- Arduino (Uno, Micro, Nano, Lillypad… any)
- A small breadboard
- 1 Relay (220v)
- 1 Pyro Sensor (*)
- 1 Photocell Diode (LDR) (*)
- 1 Lamp (OR a fan, a door, a washing machine…) (220v) (*)
(*) these sensors, are optional, you can change with your favorite input sensor, according to the needs.
In this example we want use a simple lamp (classic one, the cheapest from Ikea).
Scope of the circuit:
Get out of bed in the morning without power-on the chandelier but only a soft lamp on the nightstand.
This lamp is powered if the room is dark and if a movement is detected. If you walk in your room during the day, anything will be ignored and lamp still power-off.
It’s very-very simple project and a useless thing, but in the spare time everything is good.
Let’s start:
I not go more in deep, but fundamentally the pyro is connected to digital pin 3 and the photo-diod is connected to analog pin A0. It’s just an example.
The relay is connected to digital pin 4.
Vcc and ground are connected to vcc and ground of Arduino.
How components works?
Light sensor:
A Light Sensor generates an output signal indicating the intensity of light by measuring the radiant energy that exists in a very narrow range of frequencies basically called “light”, and which ranges in frequency from “Infra-red” to “Visible” up to “Ultraviolet” light spectrum.
Pyro sensor:
A pyroelectric sensor has an infrared filter window that admits IR within the 5 to 15 micrometer wavelength range. One end of the two series-connected elements in an analog sensor is connected to pin 3 that is normally grounded. The other end connects internally to the gate of a Field Effect Transistor and to a very high value pulldown resistor. Power is applied to FET drain pin 1 and the output signal comes from FET source pin 2 which usually connects through an external pulldown resistor to ground and to an amplifier. A digital sensor not shown here, includes internal processing circuits and outputs digital pulses.
With few lines of code we are able to detect the intensity of light and an eventual movements.
Combining these results we can power-on something attached to a 220v.
Or simply power-on only when is dark, like this snippet:
[code lang=”cpp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]void loop()
{
// give power to relay if room is dark, else shutdown.
digitalWrite ( relayPin, isDark() ? HIGH : LOW );
}
bool isDark()
{
// read from photo-diod (Analog pin A0) the intensity and decide your limit.
return analogRead( A0 ) > 900;
}[/code]
The code for pyro sensor is well explained on the Arduino playground site:
http://playground.arduino.cc/Code/PIRsense
You can adapt to your exigence.
The coolest thing is that you can control anything you want with a few line of codes and few wire link.
I give you some inspirations…
- use a Soil Moisture sensor to detect the humidity of the terrain and if you want power-on the garden’s pump!
- use a Temperature sensor to detect the temperature. If is too hot.. start a fan!
- use a Fingerprint sensor to detect your finger and open a door!
- use a Microphone sensor to detect a clap and power-on the sexy ambient lightof room house!
- use a Wifi/Ethernet shield to control remotely your washing machine!
- and many mooooore…. only fantasy!
enjoy with your home automation!