Internet Devices for Home Automation

Published on March 2017 | Categories: Documents | Downloads: 32 | Comments: 0 | Views: 206
of 7
Download PDF   Embed   Report

Comments

Content

 

Food  Living 

Outside 

Play 

Technology 

Workshop

Internet Devices for Home Automation by akellyirl akellyirl on  on February 13, 2013

Table of Contents Internet Devices for Home Automation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1

Intro: Internet Devices ffor or Home Home Automat Automation ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2

Step 1: You Will N Need eed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2

Step 2: Prototyping the Arduino Internet Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

Step 3: Connect the Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

Step 4: UDP Communicati Communication on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

Step 5: Here's the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

Step 6: Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

http://www.instructables.com/id/Internet-Devices-for-Home-Automation/ 

 

Intro:   Internet Devices for Home Automation Intro: This instructable shows the principles involved in making devices to control home automation over the internet. We're going to construct a device (or several of them), that talk to each other over the internet to control lights, motors for curtains/blinds, power sockets etc. In contrast to devices controlled from a web browser or phone, these are designed to be simple, Arduino based devices that are capable of talking to each other bidirectionally. They may be in the same house or in different buildings and may have one way communication (e.g. a light switch and light) or two way (e.g. an automation controller). It's possible to have local Device/Relay combinations to control Mains socket power to TVs, Computers etc.. Also you could see this working in building control. Commercial examples that work over local or proprietary interfaces are : Clipsal C-Bus, X10, Bus-SCS. The Picture shows an example of what we're trying to achieve using the commercial C-Bus devices as an example. (http://en.wikipedia.org/wiki/ (http://en. wikipedia.org/wiki/File:CBus_Wiring.gif File:CBus_Wiring.gif). ). But in our case the C-Bus is replaced by the Internet or a Local Network. Practically speaking, it would make most sense to have one device per room with several switches, sensors and possibly low-voltage motors wired into it, and one device at the distribution board controlling relays or dimmers. A major factor in Energy Waste is having Lights on too brightly during periods when a room is adequately lit from Natural Light. Adding a Light Sensor Device in a Room with a Dimmable Light Device significantly increases Energy Efficiency by controlling the Room Light i n response to the sensed light in the room. ========== By the way. If you li ke this Instructable, you might also like: Digital Thermometer for your Home: http://www.instructab http://ww w.instructables.com/id/An-Ar les.com/id/An-Arduino-Thermomet duino-Thermometer-with-Digita er-with-Digital-Display/  l-Display/  Internet-Radio: http://www.instructab http://ww w.instructables.com/id/Arduinoles.com/id/Arduino-Raspberry-Pi-I Raspberry-Pi-Internet-Rad nternet-Radio/  io/  Make your own "Wii-Remote" like control of a PC Fli ght Simulator http://www.instructab http://ww w.instructables.com/id/Flight-Sim les.com/id/Flight-Simulator-with-Ar ulator-with-Arduino-and-Python/  duino-and-Python/  ==========

Step 1: You 1: You Will Need For each Device you will need: * An Arduino (Uno) * An Ethernet shield (or Wifi) To prototype: * A breadboard * Some LEDs, Wires and Switches For Mains Control: * A Mains Relay Arduino Shield (e.g. http://ww http://www.dfrobot.c w.dfrobot.com/index.php?rou om/index.php?route=product/pr te=product/product&product_id= oduct&product_id=496 496 )  ) We won't be covering the Mains Control because it's covered in lots of tutorials and there are a lot of shields available.

http://www.instructables.com/id/Internet-Devices-for-Home-Automation/ 

 

Step 2: Prototyping 2: Prototyping the Arduino Internet Device We'll be concentrating on the principles of the Device itself. To do that we'll be prototyping it with LEDs and Switches. Once the Arduinos are talking and controlling LEDs, making it work with Mains Relay shields and motor shields is straight forward. We're going to construct a device with switches and LEDs, and we'll connect 2 of them over Ethernet. That way we'll be protoyping both the Switch function and the Light Control function at the same time and demonstrating bi-directional comm's. For many Devices we should connect them via a Router. If we only have 2 devices (as we do here) then we can connect them to each other . other . The Ethernet IC takes care of the required Crossover Crossover .  . We need to give some thought to how one device knows the address of the device it wants to communicate with. Here's how we'll approach it: Each Device has its own static-IP address. Each Device "knows" which device it wants to talk to. Therefore we can hard-code the Static-IP address of the destination device in the Arduino Code of the Transmitting Device. Not the most elegant solution. But completely practical.

Step 3: Connect 3: Connect the Circuit Build an example Device as shown i n the diagrams. In fact, build two of them. We'll need one to talk to the other. Each Device consists of: 1. An Arduino (Uno) 2. An Ethernet Shield 3. An LED and Resistor to represent an Output Light. 4. Two Switches to represent an ON/OFF Switch panel or UP/DN Dimmer (for example). Once you've built them plug both into your PC USB for programming. Plug an Ethernet cable from Device 1 to Device 2 (the crossover is taken care of in the Ethernet Shield).

http://www.instructables.com/id/Internet-Devices-for-Home-Automation/ 

 

http://www.instructables.com/id/Internet-Devices-for-Home-Automation/ 

 

Step 4: UDP 4: UDP Communication We're going to use UDP for communication over the Internet. UDP is an Internet Protocol (so is TCP). So our communications will be UDP/IP. http://en.wikipedia.org/wiki/U http://en.w ikipedia.org/wiki/User_Datagram ser_Datagram_Protocol _Protocol To Send a UDP packet we use the Arduino Ethernet library as follows: 1. First we have to define our IP address and the address of the receiving device, as well as the Ports we're sending and receiving on: byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x85, 0x46 }; IPAddress ip(192, 168, 2, 177); IPAddress rem_ip(192, 168, 2, 178); unsigned int int remPort localPort==8888; 8887; // //remote local port unsigned porttotolisten sendon to 2. We start up the Ethernet and then UDP services (remember it's UDP over Ethernet -UDP/IP) Ethernet.begin(mac,ip); Udp.begin(localPort); 3. When we want to send a message it needs a start, beginning and end: Udp.beginPacket(rem_ip, Udp.beginPacket( rem_ip, remPort); Udp.write(snd); Udp.endPacket(); 4. For Receiving we look for a non-zero packet size being received: int packetSize = Udp.parsePacket( Udp.parsePacket(); ); and read it into the rcv rcv buffer:  buffer: Udp.read(&cv,size); So what do we send? Very simply, we could send '0' for Switch 0 Pressed and '1' for Switch 1 Pressed. If Devices had sensors attached you may need more data e.g. {State_sw0, State_sw1, Sensor_val} Whatever you decide in your application it can be sent as a String over UDP in the same way.

Step 5: Here's 5: Here's the Code  /* This sketch Sends a UDP message string Anthony Kelly 07/11/2012 adapted from UDPSendReceive UDPSendReceive.pde: .pde: 21 Aug 2010 by Michael Margolis This code is in the public domain. */  #include <SPI.h>  // needed for for Arduino versions later than 0018 0018 #include <Ethernet.h> #include <EthernetUdp.h>  // UDP library library from: [email protected] [email protected] ord.edu 12/30/2008 12/30/2008  // Enter a MAC address and IP address for your controller controller below.

http://www.instructables.com/id/Internet-Devices-for-Home-Automation/ 

 

 // The IP address dependent on your local network: address will be dependent byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x85, 0x46 }; IPAddress ip(192, 168, 2, 177); IPAddress rem_ip(192, 168, 2, 178); unsigned int localPort = 8887;  // local port to listen on unsigned int remPort = 8888;  // remote port to send to char rcv;  // Receive character (make (make this an Array Array for String Rx) char snd;  // Transmit character character (make (make this an Array Array for String Rx)  // Define the the Arduino connections connections int swPin0 = A0; int swPin1 = A1; int LEDPin = 9; int sw0, sw1, swd0, swd1;  // An EthernetUDP EthernetUDP instance instance to let us send send and receive packets packets over UDP UDP EthernetUDP Udp; void setup() {  // start the the Ethernet and and UDP: Serial.begin(9600); Ethernet.begin(mac,ip); Serial.print("server Serial.print ("server is at "); Serial.println(Ethernet.l Serial.print ln(Ethernet.localIP()); ocalIP()); Udp.begin(localPort); pinMode(LEDPin,OUTPUT);  // Set the pins to inputs and and Enable the pullups so we don't need  // external pullup pullup resistors for for the Switches Switches pinMode(swPin0,INPUT); pinMode(swPin1,INPUT); digitalWrite(swPin0,HIGH);  // Enable Pullup digitalWrite(swPin1,HIGH);  // Enable Pullup } void loop() { if (RcvPkt()) {  // We just received a UDP UDP packet so Act Act on that. if (rcv=='1') { digitalWrite(LEDPin,HIGH); Serial.println("on"); } else if (rcv=='0') { digitalWrite(LEDPin,LOW); Serial.println("off"); } }  // Did Someone Someone just Push a Button ? swd0 = sw0;  // Remember Remember the OLD value of the switch switch sw0 = digitalRead(sw digitalRead(swPin0); Pin0);  // Get the NEW value swd1 = sw1; sw1 = digitalRead(sw digitalRead(swPin1); Pin1);  // then If thethe OLD value wjust as NOT pressed (1) and the pressed the NEW value is pressed (0)  // key waswas pressed. if (swd0 & !sw0) snd = '1'; else if (swd1 & !sw1) snd = '0'; else snd = '-';  // send a packet, packet, to the IP address and port if (snd != '-') { Udp.beginPacket(rem_ip, Udp.beginPacket( rem_ip, remPort); Udp.write(snd); Udp.endPacket(); } delay(100); } int RcvPkt() {  // if there's data available, read read a packet int packetSize = Udp.parsePacket( Udp.parsePacket(); ); if(packetSize) { Serial.print("Received packet of size "); Serial.print("Received Serial.println(packetSize); Serial.print("From Serial.print ("From "); IPAddress remote = Udp.remoteIP() Udp.remoteIP();; for (int i =0; i < 4; i++) { Serial.print(remote[i], DEC);

http://www.instructables.com/id/Internet-Devices-for-Home-Automation/ 

 

if (i < 3) { Serial.print("."); } } Serial.print(", Serial.print (", port "); Serial.println(Udp.remotePort());  // read the packet into packetBufffer packetBufffer Udp.read(&cv,1); Serial.println("Contents:"); Serial.println(rcv); } return packetSize; }

Step 6: Next 6: Next Steps The main ideas have been presented. Some next steps to try: * Make the LED Dimmable under control of the remote Switch * Make a Dimmable LED achieve constant brightness in the presence of Sensed Light Levels in the room - Hint: When the Light Sensor senses increased brightness, the LED Dims and vice.versa - Note : This is a MAJOR factor in energy efficiency. Having Room Lights too bright during periods of increased Natural Light wastes a lot of energy. * Use Port Forwarding on your Router to make this work in different locations. * Make the Message protocol more advanced to allow many different devices on the Network: e.g. {State_sw0, State_sw1, Sensor_val} or {"SWITCH", sw_number, sw_state} {"LIGHT SENSOR", sensor_number, sensor_value} etc... * Make a Handshaking Protocol so Receiver has to send an ACKnowledge back to the Transmitter. * Devise a Dynamic IP Addressing Scheme (Advanced).

Related Instructables

Run Ethernet shield on arduino by arduino  by Linksprite

Arduino desktop application on java in LAN by LAN by nviradia

Making an Android application for Arduino(LED Turn ON/OFF) by nviradia

Smart Home Automation with Android + Ethernet Internet + Arduino by Arduino  by AlanV2

Reginald: a UDP surveillance bot; control via the Internet by Internet by N.fletch

Uber Home Automation w/ Arduino & Pi by Pi by electronichamsters

Advertisements

Comments 3 comments

Add Comment

 cartiman says: what type of modem you use? for this application

 Jun 10, 2014. 11:43 PM REPLY

 Raphango says: Great! =D Congratulations!

 Oct 24, 2013. 4:11 AM REPLY

 ninjanody  says: nice.. hope to see the next steps soon.

 Feb 13, 2013. 4:27 PM REPLY

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close