How to Flash a Custom Firmware to Sonoff

In this post, you’re going to learn how to flash custom firmware to the Sonoff device. I recommend that you read my previous post to get familiar with the Sonoff.

If you don’t have a Sonoff yet, you can get one for approximately $5 – visit Maker Advisor to find the best price.

First, watch the step by step video tutorial below

The code mentioned in the video can be found here: “Reprogram Sonoff Smart Switch with Web Server“.

Safety warning

Make sure you disconnect your Sonoff from mains voltage. Then, open the box enclosure.

warning-m

Sonoff pinout

The Sonoff is meant to be hacked, and you can see clearly that these connections were left out, so that you can solder some pins and upload a custom firmware.

That’s the pinout.

sonoff_gpio-r

I’ve soldered 4 header pins, so that I can easily connect and disconnect wire cables to my Sonoff device.

pins-soldered

Preparing your 3.3V FTDI module

You need an FTDI module to upload a new firmware to your Sonoff. Use the schematics provided as a reference.

Warning: uploading a custom firmware is irreversible and you’ll no longer be able to use the app eWeLink.

I’ve added a toggle switch in the power line, so that I can easily turn the Sonoff on and off to flash a new firmware without having to unplug the FTDI module.

I used hot glue to glue the ends of the wires together. This prevents you to make wrong connections between the FTDI and the Sonoff in the future.

hot-glue-ftdi

Boot your Sonoff in Flashing Mode

To flash a new firmware to your Sonoff, you have to boot your Sonoff in flashing mode. Follow this 4 step process:

1) Connect your 3.3V FTDI programmer to your computer

2) Hold down the Sonoff button

hold-down-sonoff-button

3) Toggle the switch to apply power to the Sonoff circuit

apply-power-to-sonoff

4) Then, you can release the Sonoff button

Now, your Sonoff should be in flashing mode and you can upload a new firmware.

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.

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 »

Enjoyed this project? Stay updated by subscribing our newsletter!

15 thoughts on “How to Flash a Custom Firmware to Sonoff”

  1. When you burn the new firmware, you will loose the original, from manufacturer. Do you know if someone has the original firmware ?

    Reply
    • Hi Miguel,
      I have a quick note that states that in this guide. They don’t provided the original firmware and I couldn’t find anyone that was able to re-flash with the original firmware…
      Thanks!

      Reply
  2. hi, i have flashed nodeMcu firmware and init.lua on sonoff device. While it is connected via FTDI programmer it works, but when i plug it in electric socket it does not work at all. Do you know where could be the problem ?

    Reply
    • Hi.
      Yes. That FTDI module works, but you might have to install some drivers in your computer.
      Note that there’s a jumper wire to set the operating voltage to 3.3V. You need to place the jumper wire in 3.3V rails, otherwise you may fry your ESP.

      Reply
  3. hi,
    i just uploaded the led blink program but it does not work. it shows nothing on the serial monitor too. i also tried web server for the relay. same thing: the upload goes well, but after that nothing.
    serial monitor nothing, mains conected nothing.

    the module is sonoff basic with 5 pins on the board
    any help apreciated !

    Reply
  4. I’ve changed my router and now my sonoff switch won’t reprogram to my new router?

    Is there a way to reset the switch to factory defaults ?

    Reply
    • Hi Keith.
      Basically, after you flash the SONOFF with a custom firmware, (as described in the blog post) I don’t think you can reverse those changes.
      Unfortunately, SONOFF doesn’t provide the original firmware.
      If you need to change the SSID and password from one of our examples, you just need to modify the sketch and flash the SONOFF with that sketch.
      Regards,
      Sara

      Reply

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.