arduino home automation - amazon web services home automation this is a relatively simple controller...

16
Arduino Home automation This is a relatively simple controller for controlling equipment in your home. I control my central heating, security and lighting. By sending commands from my home computer. Written By: Feitan Arduino Home automation © 2017 www.botsbits.org Page 1 of 16

Upload: nguyennhi

Post on 26-May-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Arduino Home automationThis is a relatively simple controller for controlling equipment in your home. I control my central

heating, security and lighting. By sending commands from my home computer.

Written By: Feitan

Arduino Home automation

© 2017 www.botsbits.org Page 1 of 16

TOOLS:Soldering iron (1)

Solder (1)

Cutters (1)

PARTS:arduino board (1)

homeeasy controller - part numberHE300 (1)

prototype board - Vero board (1)

10 resistors - 47 ohm (1)

10 led's (1)

4 opto isolators - RS part 308-613 (1)

Some ribbon cable. (1)

a strip of pins to connect to the headerson the arduino board. (1)

1 box - to put it all in. (1)

some HE302S - remote control socket(1)

Arduino Home automation

© 2017 www.botsbits.org Page 2 of 16

Step 1 — Arduino Home automation

Hardware: Basically the arduinoboard when programmed will switchthe digital outputs high. Which willsend 5 volts through the resistor andlight the led's. Which will activate theopto isolator which will connect thecontacts on the remote control.

which will send the comand to theremote control sockets And turn onor off the lights, heating or anythingyou want.

Software: I programed the softwareso when I pressed (H) in theterminal the arduino board will senda 1 second pulse to my remotecontrol and switch my heating on.when I press(h) the board will send a1 second pulse my heating switchesoff.

(S) for security on (s) for security off

(G) garden lights on (g) garden lightsoff

and so on this can be changed toany button you want

Arduino Home automation

© 2017 www.botsbits.org Page 3 of 16

Step 2

The board I built on some prototype project board available from most electronic stores. It was justa matter of soldering on the components as show in the circuit diagram. And making sure therewere no short circuits.

the first led connects to pin 1 on the opto isolator, led 2 connects to pin 4 on the opto isolator. pins2 and 3 are then connected to ground. which is next to digital pin 13 on the arduino board.

opto isolator pins 6 and 7 are connected together and go to the center contact on the remotecontrol for the first on off buttons. opto isolator pin 8 goes to the left track on the remote. pin 5 goesto the right track on the remote.

and then it's just a matter of repeating the circuit for the other channels.

Arduino Home automation

© 2017 www.botsbits.org Page 4 of 16

Step 3

I unscrewed the screw under the rear label. And carefully prised open the case. When open youwill see the PCB. On the PCB there is one track on the left which when connected to the centrecontacts will switch devices on. And there is a track on the right which when connected to thecentre contacts will switch equipment off.

I just attached the contacts to my circuit as shown in my diagram. and soldered on a link in placeof the remote switch. Next I attached the battery to the 3v output on the arduino board. You don'thave to do this. But I did it so I wouldn't need a battery in the remote control.

Step 4

Picture of the software the arduinoboard is controlled from it's ownsoftware this can be downloadedfrom here.http://www.arduino.cc/en/Main/Software you can then copy and paste thiscode in to the arduino software andupload it to the board.

Arduino Home automation

© 2017 www.botsbits.org Page 5 of 16

char val; // variable to receive datafrom the serial port int ledpin = 2; //LED connected to pin 2 (on-boardLED) void setup() { pinMode(ledpin =2, OUTPUT); // pin 2 (on-board LED)as OUTPUT pinMode(ledpin = 3,OUTPUT); // pin 3 (on-board LED)as OUTPUT

pinMode(ledpin = 4, OUTPUT); // pin4 (on-board LED) as OUTPUTpinMode(ledpin = 5, OUTPUT); // pin5 (on-board LED) as OUTPUTpinMode(ledpin = 6, OUTPUT); // pin6 (on-board LED) as OUTPUTpinMode(ledpin = 7, OUTPUT); // pin7 (on-board LED) as OUTPUTpinMode(ledpin = 8, OUTPUT); // pin8 (on-board LED) as OUTPUT

pinMode(ledpin = 9, OUTPUT); // pin9 (on-board LED) as OUTPUTpinMode(ledpin = 10, OUTPUT); //pin 9 (on-board LED) as OUTPUTpinMode(ledpin = 11, OUTPUT); //pin 9 (on-board LED) as OUTPUTSerial.begin(9600); // start serialcommunication at 9600bps }

void loop() { if( Serial.available() ) //if data is available to read {;} val =Serial.read(); // read it and store it in'val' if( val == 'h' ) // if '2' wasreceived

{ digitalWrite(ledpin = 2, HIGH); //turn ON the LED delay(1000); //waits for a second Serial.println("h =Heating off"); digitalWrite(ledpin,LOW); // sets the LED off }

Arduino Home automation

© 2017 www.botsbits.org Page 6 of 16

if( val == 'H' ) // if '3' was received {digitalWrite(ledpin = 3, HIGH); // turnON the LED delay(1000); // waits fora second Serial.println("H = Heatingon"); digitalWrite(ledpin, LOW); //sets the LED off }

if( val == 's' ) // if '4' was received {digitalWrite(ledpin = 4, HIGH); // turnON the LED delay(1000); // waits fora second Serial.println("s = gateoff"); digitalWrite(ledpin, LOW); //sets the LED off }

Step 5

if( val == 'S' ) // if '5' was received {digitalWrite(ledpin = 5, HIGH); // turnON the LED delay(1000); // waits fora second Serial.println("S = gateon"); digitalWrite(ledpin, LOW); //sets the LED off }

if( val == 'g' ) // if '6' was received {digitalWrite(ledpin = 6, HIGH); // turnON the LED delay(1000); // waits fora second Serial.println("g = Gardenlights off"); digitalWrite(ledpin,LOW); // sets the LED off }

if( val == 'G' ) // if '7' was received {digitalWrite(ledpin = 7, HIGH); // turnON the LED delay(1000); // waits fora second Serial.println("G = Gardenlights on"); digitalWrite(ledpin,LOW); // sets the LED off }

Arduino Home automation

© 2017 www.botsbits.org Page 7 of 16

if( val == 'b' ) // if '8' was received {digitalWrite(ledpin = 8, HIGH); // turnON the LED delay(1000); // waits fora second Serial.println("b = Bedroomlight off"); digitalWrite(ledpin, LOW);// sets the LED off }

if( val == 'B' ) // if '9' was received {digitalWrite(ledpin = 9, HIGH); // turnON the LED delay(1000); // waits fora second Serial.println("B =Bedroom light on");digitalWrite(ledpin, LOW); // sets theLED off }

if( val == '9' ) // if '9' was received {digitalWrite(ledpin = 10, HIGH); //turn ON the LED delay(1000); //waits for a second Serial.println("9");digitalWrite(ledpin, LOW); // sets theLED off }

if( val == '0' ) // if '9' was received {digitalWrite(ledpin = 11, HIGH); //turn ON the LED delay(1000); //waits for a second Serial.println("0");digitalWrite(ledpin, LOW); // sets theLED off }}

Arduino Home automation

© 2017 www.botsbits.org Page 8 of 16

Step 6

After I had set up the home easymodule to respond to the remote.(You can find out how to do this inthe instructions for the modules.) Iloaded the software on to the arduinoboard. And ran the command (H)

And my heating switches on. I testedthe other commands for the lightsand security and they all respondedas planned.

Arduino Home automation

© 2017 www.botsbits.org Page 9 of 16

Step 7

The last job was to fix all the boards in a plastic box and made a hole for the USB to plug in to thearduino board

You may find when the boards are in the box the range at which they work is shortened. If thishappens you can mount the remote antenna on the out side of the box as I have done this to solvedthe problem I had with range. But you will have to keep the leads short or they will effect thefrequency at which the antena transmits at.

Arduino Home automation

© 2017 www.botsbits.org Page 10 of 16

Step 8

The computer I have connected to the arduino board is running Linux ubuntu. But this board willwork with windows, mac and Linux. I have 3 ways of remotely controlling the board from theinternet at the moment.

The first way will work with any computer. And that is using VNC to remotely login and control theboard from the desktop. There are other software alternatives to remotely login. Such as windowsremote desktop.

And log me in https://secure.logmein.com/home.asp?lang...

The second way which I use most of the time because of security. Is to login using the Linux SSHterminal from windows using a program called putty. you can also you do it this way using a mac.When logged in You can find out which device the arduino board is, by typing this command.

ls /dev/tty* You should get a screen like this. My device is USB0 but this can be different. Thenyou can send the command. screen /dev/ttyUSB0 9600 to open the tty terminal.

When the tty terminal is open you can then type the command to turn the device on or off. I.e. G org for garden lights. And that is about it.

if you have any problems here are some more usefull commands. these comands will show youwhich tty services are running. ps -lt ttyUSB0 ps ax | grep tty this command will stop the servicerunning. kill (job number)

Arduino Home automation

© 2017 www.botsbits.org Page 11 of 16

Step 9

This is a new update I have just setup to alow me to control the arduinoboard from any web browser. Iwanted to control my homeautomation from my phone but thiswas not very easy using VNC orSSH. So installed webmin on myserver this will give me full control ofthe machine from within a webbrowers.

In web min there is a page calledcommand shell that will allow me torun commands from the webbrowser. I original tried to run thecomands I was using in the SSHterminal. but they didn't work inwebmin. So with help from mybrother we wrote a script.

so now all I have to do is send acommand like "home_auto h1" andthe heating will switch on. or"home_auto h0" to switch the heatingoff. so now it can all be controlledfrom my phone here is a copy of thescript.

#!/bin/bash _usage () { echo "gl1 itwill run this comand echo G >/dev/ttyUSB0 9600 and turn mygarden lights on" echo "gl0 it will runthis comand echo g > /dev/ttyUSB09600 and turn my garden lights off"echo "s1 it will run this comand echoS > /dev/ttyUSB0 9600 and turn mygates on

Arduino Home automation

© 2017 www.botsbits.org Page 12 of 16

echo "s0 it will run this comand echos > /dev/ttyUSB0 9600 and turn mygates off" echo "h1 it will run thiscomand echo H > /dev/ttyUSB09600 and turn my heating on" echo"h0 it will run this comand echo h >/dev/ttyUSB0 9600 and turn myheating off" echo "b21 it will run thiscomand echo B > /dev/ttyUSB0 9600and turn my bedroom 2 lights on"

echo "b20 it will run this comandecho b > /dev/ttyUSB0 9600 and turnmy bedroom 2 lights off" echo "N itwill run this comand echo N >/dev/ttyUSB0 9600 and turn nextbank of outputs on for 5 seconds"echo "R it will run this comand echoR > /dev/ttyUSB0 9600 and turn theRelay on"

echo "r it will run this comand echo r> /dev/ttyUSB0 9600 and turn theRelay off" }

Arduino Home automation

© 2017 www.botsbits.org Page 13 of 16

Step 10

case "$1" in gl1) #garden lights on/bin/echo G > /dev/ttyUSB0 9600 &&echo "Lights On" ;;

gl0) #garden lights off /bin/echo g >/dev/ttyUSB0 9600 && echo "LightsOff" ;;

s1) # gates on /bin/echo S >/dev/ttyUSB0 9600 && echo "GatesOn" ;;

s0) # gates off /bin/echo s >/dev/ttyUSB0 9600 && echo "GatesOff" ;;

h1) #heating on /bin/echo H >/dev/ttyUSB0 9600 && echo "Heatingon" ;;

h0) # heating off /bin/echo h >/dev/ttyUSB0 9600 && echo "HeatingOff" ;;

b21) # bedroom 2 lights on /bin/echoB > /dev/ttyUSB0 9600 && echo"Bedroom 2 Lights On" ;;

b20) #bedroom 2 lights off /bin/echob > /dev/ttyUSB0 9600 && echo"Bedroom 2 Lights Off" ;;

Arduino Home automation

© 2017 www.botsbits.org Page 14 of 16

Step 11

N) #Next Bank on /bin/echo N >/dev/ttyUSB0 9600 && echo "NextBank on for 5 seconds" ;;

R) #Relay on /bin/echo R >/dev/ttyUSB0 9600 && echo "Relayon" ;;

r) #Relay off /bin/echo r >/dev/ttyUSB0 9600 && echo "Relayoff" ;;

*) #echo $0 ": Not a valid command";echo "Please retype command";_usage; ;;

esac

Step 12

Update: I have now added the optionof switching to the next set of button.It was just a matter of wiring in aspdt relay. so when the relay is offthe first bank of buttons areselected. and when the relay isenergised the second bank ofbuttons are selected.

I have also added a second relayincase I want to conect anything upin the future.

Arduino Home automation

© 2017 www.botsbits.org Page 15 of 16

This document was last generated on 2017-06-24 05:45:54 AM.

Arduino Home automation

© 2017 www.botsbits.org Page 16 of 16