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

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

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 build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

44 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!

    Reply
  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.

    Reply
    • 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).

      Reply
    • True but I use mine through Google Home Assistant via Voice Activation. It’s so nice to be able to just say “Good Night” and have Google turn off my TV, all of the lights in several rooms, turn on the Bathroom lights over the mirror in the Master Bath and finally start playing Cricket Sounds for 45 minutes to soothe me to sleep. Some lights come on at sunset. Others work via a simple “Hey, Google. Turn on the Table Lamp.” Home automation is great and with these switches, it;s inexpensive as well.

      Reply
  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

    Reply
    • 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

      Reply
  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

    Reply
  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.

    Reply
  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?

    Reply
    • 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

      Reply
    • I did experience similar problems but after much investigation it is all solved now by installing a new router and all is stable. means my NEST thermostat is now working all the time too.

      Reply
  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.

    Reply
  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?

    Reply
  9. This was a great introduction. I just have one question. Do you know how does pairing mode work? How do smart switch and your communicate that initial settings ie. wifi ssid and pass? Switch does not use bluetooth to communicate with the phone, and you cant be simultaneously connected to two wifi networks with your phone

    Reply
  10. Hello!
    I had 4 switches working perfectly well with ewelink app using mobile outside of my home. Recently, I my modem/ router was replaced due to some problems. As some of my Son off switches were giving problems, I replaced everything with new onesSonoff (Basic 2) . Now when you switch on for the first time, the LED flashes Twice every cycle. After pressing the front button and getting into pairing mode, (led flashing continuously) I am able to add devices and operate while my mobile is connected to the Home wifi. However, when I go out of my house or disconnect the mobile from home wifi, I am unable to operate any device. It says the device is offline. I see the LED flashing twice with a long gap, which as per manual is: device not connected to Router. All my laptops and mobiles work well with the same modem/ router. Further while setup I noticed that while connecting to ITEAD, it says no internet. I tried checking same setup keeping the Sonoff switch very close to the modem/ Router. Same situation. Please help

    Reply

Leave a Reply to Rui Santos Cancel reply

Download Our Free eBooks and Resources

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