How to automate almost anything

This will be the first of a series of two articles about peripheral automation (writing about home automation would take considerably more time). The aim here will be to explain how would be possible to control objects that could be automated through power line, anything that can be connected directly in the wall, that cutting the power and turning it on again would be enough to stop and start working again (for example a lampshade, a lamp, a fan, etc). There is still the possibility to automate infrared, a.k.a. remote control, controlled devices (tv, cable boxes, air conditioner, stereo systems, etc). All controlled by cellphone, from anywhere there is internet access.

The main requirements are:

  • basic knowledge of Arduino;
  • WiFi network available.

Regarding Arduino usage, there are several tutorials , including Arduino homepage, teaching developing for it (it is really very easy, anyone with a basic knowledge of algorithms and programming is able to do it).

In order to have the device we want automated connected in the internet, we will use a module called ESP8266 that is nothing more (roughly speaking) than an Arduino compatible device, in terms of programming and it is already able to connect to WiFi routers.

Automating a power outlet

Turning on or off a power outlet using a cellphone can be made through a component called relay (that acts like a software controlled on/off switch) connected to an ESP8266 micro controller and let it turn on and turn off the relay depending on the user’s decision.

Relay module

The following image shows an ESP8266 module connected to a relay that is connected to a power extension.

Source: http://www.instructables.com/id/ESP8266-Automatic-Router-Restart/

In the previous image it is possible realise the relay acting as a power switch, turning on and cutting the wire’s power. That validates what was previously shown, everything that can be controlled using a power on/off approach can be automated this way.

Automating using an infra-vermelho controller

In order to automating any infrared device it is necessary at first to discover all codes used by the device’s remote controller. An infrared LED is basically a LED lamp that blinks as a Morse Code and cannot be seen by the human eye (using a cellphone camera it can be seen blinking). There are two ways to get a remote controller key’s code: finding it on internet from who had already discovered it or copying the codes from the original remote.

Internet’s copied code

Each keys code is, in most of cases, represented by a byte and looks like the following inside the program:

unsigned int Sony_map_code[] = {
  0xA90,    //  "power",     
  0x910,    //  "0",         
   0x10,    //  "1",         
  0x810,    //  "2",         
  0x410,    //  "3",         
  0xc10,    //  "4",         
  0x210,    //  "5",         
  0xa10,    //  "6",         
  0x610,    //  "7",         
  0xe10,    //  "8",         
  0x110,    //  "9",         
  0x490,    //  "Vol Up",    
  0xc90,    //  "Vol Dn",    
   0x90,    //  "Chan Up",   
  0x890,    //  "Chan Dn",   
  0x190,    //  "Picture Up",
  0x990,    //  "Picture Dn",
  0xA50,    //  "TV/Video",  
  0x2d0,    //  "Clear",     
  0xdd0,    //  "Jump",      
  0xe90,    //  "MTS",       
  0x5d0,    //  "Display",   
  0x5d0,    //  "Sleep",     
  0x290,    //  "Muting",    
  0xd9a,    //  "Rewind",    
  0x59a,    //  "Play",      
  0x99a,    //  "Pause",     
  0x19a,    //  "Stop",      
  0xb9a,    //  "Record",    
  0x39a,    //  "FF",        
  0xcd0,    //  "AM/PM",     
  0xd10,    //  "Enter",     
  0x69a,    //  "Eject" 
};

Decoding the keys of a remote controller

In order to find out  a remote key’s code, just assemble a circuit (using Arduino or ESP8266), using an infrared receiver (small transistor able to “see” the i.r. blinks) and printing on the editor’s screen (it is possible to print to the user any information while connected into a PC).

Infrared transistor

The previous image shows an infrared receiver. All remote controlled device (controlled by an i.r. remote controller) has on transistor like that inside.

The following image is from a circuit able to decode any infrared sign. A tutorial for this circuit is available in Instructables.

Arduino UNO receiving an i.r. signal

After the remote key’s code are available, it is enough to add them in the software that will be stored into ESP8266. In order to send these signals, it is necessary to add an infrared LED in ESP8266 and import a remote control library (that will do all signal coding hard work and will transmit and activate the LED). For the transmission succeed the LED must be placed in a position that can be “seen” by the receiver inside the device we want to control.

Automation using WiFi

Regardless what is wanted to automate, it would be necessary to connect ESP8266 in an WiFi network. The ssid can be hard coded or a temporary network can be created and the user can enter all values on the first sign. After the connection is up, a static HTML page can be added inside the module containing buttons that trigger actions in the code, or a high level home automation protocol such as MQTT can be used.  Regardless the choice, the goal is to send user actions to a certain ESP8266 through WiFi and let ESP8266 translates these actions to relay or i.r. commands.

The next article will be about how to automate an specific device.

Leave a Reply

Your email address will not be published. Required fields are marked *