Skip to main content

Smart Socket : A small step to "Internet of Things"


It was a long weekend and I did not have anything planned. I was on a "couch potato" mode watching 4 movies in a row. It was very unproductive and I was just sitting upright in my bed with a pitcher of water and a sack of chips when the sun sets and it got dark. I needed to turn on the lights in the living room and few lights in the kitchen but i didn't want to stand up. I wished I could just do that with an app on my phone. So after finishing the 4th movie. I jumped into my computer and started searching about such ideas. The first interesting thing that i found was the Wemo, a home automation product by Belkin. They featured a product that is very similar to what I need. They feature of main socket that can be turned ON and OFF from the internet. I then encountered the phrase "Internet of Things" which refers to the technology behind internet connected devices. They are not limited to home but are also getting attention from factories and manufacturers now. I read an article that predicted the market of "Internet of Things" to grow to 17 billion in 4 to 5 years from now.

The Inner Geek Kicks In

Instead of buying that product, why not make my own? I know exactly how they work, I have the skills required to build such electronic hardware and I have more than enough of the software programming skill required for this. Who knows, this could be a potential business in the future. What I needed was the materials, so i searched for tiny micro-controller chips and board with built-it WiFi modules. I have couple of Raspberry Pi development boards but I needed something very small that can fit inside a light switch or inside a mains socket (convenience outlet). This search has lead me to the "Electric Imp". It is a very tiny micro controller with built-in WiFi package inside an SD card form factor. The chips is cloud-enabled. You write the firmware in the cloud and you control and monitor it from the cloud. It is hardwired to communicate to the Electric Imp's cloud platform and services. This make it easier to play around with.

I ordered 2 of the little devil (the Imp card's logo is a little devil) online. They shipped it and deliver to me from New York. Since I have not done electronics for a long while, I don't currently own the required basic tools like a soldering iron with me. So I also ordered a set of tools which included a bread board and generic PCB, soldering iron, etc online from a local provider, element14.com. I also ordered the materials required for the project in the same online store. The orders arrived after 2 days.

Basic tool set including a multimeter.
Power Supply

Yesterday, I finally had some time to put things together to develop a proof of concept prototype that can fit inside a switch box and or a mains junction box. I started out by figuring out where to get a power supply that will generate 5 Volts that is enough to power the Imp's board and the relay coils at the same time. Then i turned my eyes on an unused USB cellphone charger plug that I got from a neighborhood shop for $4. The plug generates 5V at 1A which is more than enough and it quite small. So I took it apart and remove the main board from the plug housing.

The cheap USB cellphone charger.




The Imps 

The Imp cards and the April basic development boards.
The first thing I did after receiving this little devils was to run a very simple program so I took the breadboard and started assembling a simple circuit with a single RGB LED. I made the LED controllable from the web through REST web service. I was able to change the color from red to green to blue. I could also command led to turn on or off or blink at a specified frequency. The experiment was enough to tell that this little thing is awesome. The thing has also built-in Analog to Digital converters that you can use to read analog signals such as temperature, pressure, etc. It can also provide analog output signals through PWM to control analog things such as servo motors. You can read more about it from here -> http://www.electricimp.com/product/

The cloud-based IDE looks like this. The source code is written in Squirrel programming language. In the future Electric IMP is going to migrate to Erlang.


The programming model is purely asynchronous. The communication between the agent and the device is event-driven. It feel like writing nodeJS application.
 
 
Switching Circuit

Time to replace the LED with a relay. To be able to control high current load such as an light bulb or AC or a fan, you need to channel the signal from the Imps output pin to control a relay or a MOSFET (a power transistor) which in turn will control the actual high-current load. I decided to use relays over MOSFETs as they are cheaper.


Imp development board soldered on top or a PCB fitted with a relay, terminal blocks and the salvaged power supply (the vertical board).
The image above shows the assembled product. The power supply board is positioned vertically so that they will fit inside the convenience outlet backing box.

I used a relay driver chip to drive the relay. Unfortunately, I bought the chip in a wrong packaging. I got the very small surface-mount type which is very difficult to solder with a regular iron and this board. But I managed to do it by soldering the chip from the back of the board and simply separating the Vcc and Ground pins. Then I used the rest of the pins in parallel as one switching channel since I only needed one channel anyway.

The relay driver chip partially soldered.
After many year without practice, I think my soldering skills was not that bad. ;)


Testing



The very first test did not really work quite well. After few debugging, I figured out that I connected the relay's common pin wrongly. It turns out that I misunderstood the relay driver chips datasheet so I went back to it and reconnected the relay in the right way (positive-common, not negative-common). I was to excited to see it worked that I did not even ready the data sheet well.

Finally, using the same code I wrote for the RGB LED experiment, from a web service, I told the IMP to blink the LED and I hear the relay ticking. It means the electro-mechanical l contact is moving back and forth from ON to OFF position. This means that the board is ready to go inside the box.

Fitting Together

Because of earlier careful planning, fitting the board inside the box was easy. It's a tight fit but it works. I used a couple of terminal blocks where I can easily connect and disconnect the load and source sides of the electrical circuitry. This way I can take away the board and use it somewhere else whenever I need it.

 

In Production

I created a small mobile website using ASP.NET MVC4 and deployed it to my existing Windows Azure web space. After 4 straight hours of working on the electronics and the Squirrel (the imp's programming language) source code and the small mobile website. Time to package the product and use it in a the real world.

With a total cost of S$45 including the Imp card, I now can control any appliances plugged in to this socket/outlet from anywhere around the world. In a mass produced production version, this production cost can be reduced to less than $10 per unit and the size of the board of the final product can be reduced to up to only 10 % of the size of this prototype. If the product sells at 20$ each, that sound like business eh?

Checkout the demo I did at Hackware Singapore: https://engineers.sg/video/connecting-iot-things-with-electric-imp-hackware--1622




Comments

Popular

DIY Airsoft Chrono [PC-based]

Chrono or Chronograph, the term used by Airsofter and Paintball players to refer to the device that measures the muzzle velocity of firearms. This is also called MVMD, short for Muzzle Velocity Measuring Device by the British Army. Muzzle Velocity is the velocity of the bullet as it exits the barrel of the firearm.

A year ago I was an active Airsofter in Iligan who's more interested in modifying and improvising AEGs (Automatic Electric Gun) rather than playing airsoft. I have made my AEG susceptible to high current burns by using locally available MOSFETs. I have improved velocity by replacing cylinder gaskets and spring. I have increased the rounds per minute by altering the armature windings of the drive motor. And most of all, I have made my own cheap alternative PC-based Chrono.

I have posted an artivle before that details the development of my chrono but unfortunately the online forum was hacked/deleted by webmaster of proboards.com due to some violation in the contents. So, …

Disable PrintScreen on C# without Keyboard Hooks

Yes, there is a simple solution to prevent grabbing information on your C# application screen with the keyboard's printscreen key without using keyboard hooks or calling COM interops. The solution makes use of Windows Forms Message Filter to trap keyboard events on your application window.

To trap keyboard events with Windows Message Filter, you need to implement the IMessageFilter interface and override the member PreFilterMessage(ref Message WM) method. This is the method called whenever a Form receives a keyboard or mouse event. You may want to read more about IMessageFilter.

The problem is that even though you have trapped the PrintScreen keypress event, the captured image will still persist to the clipboard. Therefore the simplest solution is to clear up the clipboard right after the PrintScreen is pressed on the keyboard.

This is how the overridden method will look like this:

publicbool PreFilterMessage(refMessage WM)
{
Keys kCode = (Keys)…

DIY Mic Shock Mount

For the past couple of weeks I was looking for a cheap microphone shock mount and the cheapest I saw that was available in my country was around US$160 so I decided to build a cheap one. I only spent less than $6 and a 2 hours of my not very precious time.Before I left office today, bought materials and tools to for my DIY shock mount which are a piece of 4”-diameter PVC pipe coupling ($0.50), a set of hair ties($0.40), set of stove bolts ($0.50), a set of coping saw frame and blades ($2.5).First, I decided to cut the PVC coupling so it would look like Rode SM3 shock mount’s frame.Then I used the section of the PVC coupling that was removed to be a attachment brace to the original mic holders base and bolted it to the base of the frame. I had to heat that part so could bend it to a desired angle.And then cut slots on the edges for the rubber suspensions (hair ties). Right after positioning the suspensions, i found a problem. The rubber bands slip every time i attempted to position the…