Introduction: Sonoff Basic Wifi Extender - MQTT Dry Contact Relay - 5v DC Low Voltage

Ok I had some first generation Sonoff basic devices and I don't want to use them with 220v as they weren't really safe yet in that release. They had been lying around for a while waiting to do something with them.

So I stumbled across the martin-ger project on GitHub ( and hacked the Sonoff.

First I adapted the Sonoff to work on 5vDC and disabled the rest of the circuit.


Sonoff Basic R1

5v DC power supply

Step 1: Sonoff on 5v DC

So this is pretty simple.

You'll see in the first image that the Sonoff uses an AMS1117 regulator to go from 5v to 3.3v. The pins on the regulator are from left to right: IN (GND), OUT, IN (+). By soldering a small wire to theIN(GND) and the IN(+) you can connect your 5v DC power source to power the rest of the board. As it can get a little fiddly there I used 2 other connection points. The empty soldering point just to the right of the AMS117 (square pcb marker) is GND. Just to the left there is a + connection. Have a look at the close-up picture.

Ok once this is done you can already test before making the other alterations.

Step 2: Installing New Firmware

On the Github in the folder firmware you will see the .bin files:

  • 0x00000.bin
  • 0x02000.bin

You need to download these.

Then you go to the ESP Expressif website and download the ESP download tool (PC only):

Start it up and you will first get a selection window - choose DEVELOPER and then ESP8266. The screen should look like the screenshot above.

Then click on the right hand side "..." to browse and select the 0x00000 file first. Add the memory location in the box next to it: 0x00000.

Do the same for the second file and set the memory location to: 0x02000.

Once that is done take your favourite USB-TTL and connect the Sonoff up (make sure you don't have any other power connected to the Sonoff board). Also double check the USB-TTL is set to 3.3v!

Press the button on the Sonoff while inserting the USB-TTL in your computer to activate flash mode.

Select the COM port in the ESP download tool and set the speed to 1152000. Click START.

It should only take 3 or 4 seconds. Sometimes my board didn't go in flash mode properly - just take USB-TTL out, press button and re-insert.

OK - with this done we have the new firmware on the Sonoff ESP8266.

Disconnect your USB-TTL and connect you 5v DC power source to the Sonoff.

Step 3: Configure Your Wifi

We're going to use Telnet to configure the device. I use Putty.

After connecting the power to the Sonoff, you should see a new Wifi SSID appear: MyAP.

Connect to it with your computer - initially there is no password.

Once connected open Putty and set it to: PORT 7777

When the connection is done you'll see: CMD>

By using basic commands you're going to configure the Wifi device. Bold is the command - the italic after it is your setting. The first command with me always gives an 'Invalid command' - so just repeat it.


set ssidyour_home_router's_SSID

set passwordyour_home_router's_password

set ap_ssidthe_ESP's_new_ssid

set ap_password ESP's_password

show // (to check the parameters)

set status_led13 // (LED is on GPIO 13 on the board)

save // (!!! don't forget)

reset // (=reboot)

Ok now you have a basic sub-network you can use to connect IoT devices separated from your main Wifi.

Or you can use this for guests, babysitters, kids accessing to the internet with a timer, ....

Next - Add MQTT, Dry contact relay and cleanup.

Step 4: Cleanup, Enhance With MQTT and Relay Dry Contact


First I cleaned-up the board and prepared it for the dry relay contact behaviour.

This means:

  1. connecting the 5v DC to the green terminal
  2. cutting the old routes on the PCB (cut top and bottom of board) so the terminal is actually isolated and connects directly to the 2 points we soldered earlier on the pcb. On the top you can cut it where the red lines are - you'll see I cut them a bit further initially. I use a Stanley knife and then a very sharp scraper. Instead usually a small flat screwdriver is also OK to scrape the copper of the PCB.
  3. cut the PCB near the relay (solder track) and install a bridge as you see in the picture. Basically the left 2 connections to the relay are still powered by 3.3v. The right 2 contacts will now form a closed loop with the green terminal at the top of the board. Thus creating a basic dry contact.


Once this is done I connect the 5v DC source to the green terminal so the board power up. You should see the green LED blink when the Wifi is in action.

For MQTT I use a node-red setup on a Raspberry Pi 3A+ with Aedes MQTT. Let me know if anybody is interested in expanding this instructable on how to set this up. But it will also work with any other MQTT broker.

Connect with Putty to the Sonoff. You can use the internal ( or the external IP (IP that it got from your Wifi router).


set mqtt_host IP_from_your_MQTT_server // (I left the rest default - the MQTT should be on the main network though - so on your main Wifi internally or on the internet public)

gpio 12 mode out // (the relay is on GPIO 12)



Make sure to save and reset. The MQTT settings are only changed at reboot.

Once that is done you can use an MQTT client tool to check the messages. I use MQTT Explorer.

Step 5: Test MQTT

After 15 seconds you should see the ESP pushing the messages.

To test the relay you publish a message:

topic: /WiFi/ESPRouter_xxxxxx/command //(the xxxxxx is your device HEX value)

message: gpio 12 set high for 4 //(set gpio 12, the relay, to high for 4 seconds)

You should hear the relay click and the ESP will send the command feedback to the topic ("response").

From now you can use either telnet or MQTT to configure and change settings. Any valid command can be published by MQTT.

That's it. You now should have a low voltage Sonoff, private Wifi SSID, with MQTT and a dry relay that can be controlled.

Let me now in the comments if you found this useful, any mistakes I made, errors you found or improvements!


Step 6: Improvements ...?

The range is so-so though.

I have some 2.4Ghz mini antenna from an old router.

I'm going to try to install that on the Sonoff and see if it improves the range a bit.

Access to the AP/ST - lock web page access

by default the webpage is 'open'. So ideally when everything works fine you, open Putty and send the 'lock' command and save it. By default it will use you ST password to protect the webpage.