Sonoff – $5 WiFi Wireless Smart Switch Introduction

In this post, you’re going to learn how to control an outlet from anywhere in the world using the Sonoff device. The Sonoff is a device that you put in series with your power lines allowing you to turn any device on and off.

First, watch the step by step video tutorial below

Here’s the basic Sonoff. You can get a Sonoff for approximatly $5 – visit Maker Advisor to find the best price.

sonoff_pic

It’s very simple, it has an input in one side and an output on the other side.

Then, you can simply send commands via wifi to turn on and off. That’s pretty much how it works.

Opening the Sonoff

Let’s take a look inside the sonoff device. These are the main sections:

  • There are the two powerlines and they are isolated from the rest of the circuit
  • The active line goes to the relay (that’s on the other side of the PCB)
  • The ESP8266, that is the processor that provides wifi and receives the control commands
  • The Sonoff is meant to be hacked and you can see clearly that those 4 connections were left out, so that you can solder some pins and upload a custom firmware

sonoff-highlighted

Learn Raspberry Pi, ESP8266, Arduino and Node-RED. This is a a step-by-step course to get you building a real world home automation system using open-source tools DOWNLOAD »

Learn Raspberry Pi, ESP8266, Arduino and Node-RED. This is a a step-by-step course to get you building a real world home automation system using open-source tools DOWNLOAD »

In this project, we’re going to use the standard firmware that came with the Sonoff. In future post I’m going to show how to flash a custom firmware into the Sonoff device.

Sonoff Example

Let’s take a look at how this would fit in a normal circuit. Basically you cut the wire that goes to the device, and you put the Sonoff in the middle, so that you can control any device that is connected on the other end.

Normally, what you have is a power source that has an active and neutral line that goes to a load, your load can be lamp for example. In the middle, you usually have a switch.

slide2

With the sonoff, you cut that connection…

slide3

And you place the sonoff in the middle. The sonoff acts as a switch that is controlled via Wifi. slide4

Note: if you have a earth line, it has to go outside the sonoff.

slide5

Safety warning

Before proceeding with this project, I want to let you know that you’re dealing with mains voltage. Please read the safety warning below carefully. 

warning-m

Download our Free eBooks and Resources

Sonoff usage

Let’s hook up the Sonoff. On the left side, you connect the active and neutral accordingly to the pinout. Active and neutral come out on the right.

sonoff_circuit

Installing the App

Now you have everything in place to install the app to control the light with your smartphone, follow these next instructions:

  1. Search for the app eWeLink app and install it
  2. Open the app and create an account
  3. Power up the Sonoff device and connect the appliance that you want to control (in my case, it’s a desktop lamp)
  4. Press and hold the Sonoff button for 5 seconds, so the LED green starts blinking
  5. Go to the app and press the next button
  6. Enter your network credentials and choose a name for your device
  7. Add it to your dashboard.

Refresh the dashboard and you should see your device. Press the on button to turn it on. Now the lamp is On. and if you turn off. The lamps goes off.

on-and-off

Watch the video to see a live demo of the Sonoff device.

Keep in mind that with this app you can control any device on and off from anywhere in the world, because it’s controlled through the eWeLink cloud servers.

The app also comes with a nice set of features, click the timer button. You can add a timer that can be activated on a certain date and time.

I’ve tested this feature and it has been working flawlessly.

timer

 

Sonoff tutorials list:

Wrapping up

That’s it for now, I hope you had fun learning about the Sonoff device. Make sure you subscribe to my blog, because I’ll be posting more tutorials about the Sonoff. I’ll be showing how to flash custom firmware.

Do you have any questions? Leave a comment down below!

Thanks for reading,

Rui


Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

39 thoughts on “Sonoff – $5 WiFi Wireless Smart Switch Introduction”

  1. Awesome product with great application!
    Could it be used to work in parallel with a switch, i.e., together? For example, turn on a device either through the swith or via Sonoff?
    Again, congrats!

  2. Hi Rui,
    Thanks. Interesting solution but it maybe safer to work with standard remote control sockets (for example Energenie in the UK and similar elsewhere). These plug-in sockets can be controlled with a very cheap 433MHz transmitter. I control my lamps with a WeMos D1 board (based on the famous ESP8266) that sends on/off codes to such a 433MHz transmitter. The codes can be picked up with a receiver+Arduino when using the remote control unit that comes with these sockets. I can send more info if you wish.

    • There’s also a version of the Sonoff that’s got RF functionality. They also make a newer version that includes connections for ground (earth).

  3. Thanks a lot for your interest and exposure, but I particularly think that what really matters is controlling this sonoff device not with its own app (ewlelink) but integrated with node-red turning on and off the light from the node-red dshboard

    • Hi Jose,
      I totally agree with you! The next post is about flashing a custom firmware in the Sonoff device.
      The post after that is about integrating the sonoff with Node-RED

      Thanks for reading,
      Rui

  4. Hi Ru, I dowloaded the app. And read some of the comments. Some are very negative and criticise the working of the device. I.E failing in many instances. What is your comment on that. I like to see that before i purchase the gadget. Thank you. Ben

  5. Why earthing is outside of this device? It makes connection very complicated as you have to strip out earthing cable which is then too short as this Sonoff device adds approx 5 cm to original cable.

  6. I have experienced several times that the Sonoff looses connection with the WLAN network. I find it blinking with double blinks.

    After a bit of investigation, it seems that if the WLAN is interrupted (turned off temporarily), the Sonoff does not manage to reconnect. Turning its power off and on fixes the problem.
    Clearly a SW design fault.

    For me, this makes the device unusable for a remote operation.
    Maybe there is a firmware update that can fix it?

    • I’ve never experienced that error and I had the Sonoff running for a while.
      It might be a good idea to flash a custom firmware that hopefully fix that problem.
      I’ll be showing more tutorials in the next couple of weeks

  7. These are great devices and my only concern has been that eWeLink required full access to everything on my phone. I have 7 of them running right now and a TH10 on order for temperature control. Hope to break away from eWeLink if possible.

  8. I want to use this inline with my current light switches. Is it possible to wire so the switch is still active, along with allowing Alexa to control?

Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.