Saturday, April 15, 2017

Home Automation Controls - Simple Esp8266 Wifi Relay Part 1

Follow Along as I play with this. I'm just wingin it. Relay Control Server The esp8266s are great. They've got a lot of punch and built in wifi. Plus, being Arduino compatible, getting a prototype up and running is pretty fast.

A Simple Relay Server

A relay server should be able to operate a relay and accept wifi Http requests. The requests should include getting the state of the relay and switching the state of the relay. That seems like a decent set of simple requirements. So, this first iterations should be pretty simple with items we listed above. We should have a GET endpoint /relaystate?relaynumber=#, where relaynumber is a number we define for an individual relay. This will be more clear later. Let's also make two other GET endpoints to turn the relays on and off, /relayon?relaynumber=#, /relayoff?relaynumber=#. Using these endpoints we can set the state of each relay individually. This seems like a good enough start and we can get fancy later on.

Arduino Esp8266 Webserver

This webserver library makes putting things on a network a super simple. Check out the esp8266 Webserver example that comes with the esp8266 library in the Arduino ide.

Driving Relay Coils

Like many microcontrollers, the esp8266 has plenty of power in terms of computing and peripherals, but the output from the pins are not enough to power much. At 3.3V, the esp8266 lacks the current and voltage to drive current hungry modules, but this is common. We'll need to select a device to help us drive the relatively large coils. 

A transistor is a great way drive larger loads, like a motor or an LED. They're pretty simple devices that can be thought of like a voltage controlled switch. The PN2222A is a general purpose transistor and just about every tinkerer has a few of these floating around their tool box. They can be picked up at Radioshack. The interesting part about the transistor is when we put the transistor into "saturation" mode, the transistor becomes a sort of switch. You can also use other devices that are analogous to a transistor like a mosfet or motor driver IC's.

I happen to have a few L293D motor drivers, another fantastic little IC to use in your projects. Inside a L293 is four half H bridge drivers with flyback/kickback diodes. Awesome. I'm going to use these to drive my relays. 


No comments:

Post a Comment