Posted on 163 Comments

#21: Six Sonoff Secrets

Customise your Sonoff home automation controllers with a memory upgrade, weatherproof housing, control switches, sensors, and custom firmware.

ITEAD keep releasing new Sonoff models so this isn’t a complete list, but some of the models mentioned in the video include:


winbond-25q32fvThe flash memory chip in Sonoffs is 8Mbit, which is only 1MByte. Then if you want to do OTA (Over The Air) updates you need to limit your program size to less than half the available memory so that a new program can be uploaded alongside the old one. And if you use a SPIFFS (SPI Flash File System) to store non-volatile data outside your program, you lose even more memory.

You can replace the flash memory chip with a Winbond 25Q32FV in SOP-8 package, which is a 32Mbit (4MByte) chip. You can buy them on eBay for about US$3 for a pack of 10.

The original flash memory on the Sonoff is a Winbond 25Q08FV, which is the 8MBit (1MByte) version of the same chip.

Thanks to Pete Scargill for this idea! You can see more on his original blog post: “32Mb ESP01 and Sonoff


Sure, you can just cut a power lead and screw it into a Sonoff, but it’s probably a bad idea. You need to consider how your Sonoff will be used, including physical protection (stop little fingers reaching the terminals!) and liquid protection from spills. You also need to make sure there is strain relief on the cables to prevent them being pulled out, and possibly exposing live mains connections. You can do it cheaply using a plastic project box, and with some cable ties around the cables just inside the box so they can’t be pulled out. The result can be a very neat setup that won’t look like a dodgy DIY cable, and should be safe for general use.


You can go even further and use an IP-rated (Ingress Protection) case and cable glands, to make your Sonoff waterproof and physically very strong.


In this video I gave a very simple explanation of the two-digit IP codes. There are also extensions to the code for other attributes. You can find more information and tables showing the specific meaning of the numbers at


Internet control is fun, but usually you also want some way to manually turn the output on or off without using your phone. You can modify a Sonoff to connect an external button across the pins of the built-in button, allowing you to toggle the output by pressing the button manually. The built-in button is connected to GPIO0, so when the button is pressed it pulls GPIO0 to GND. This is used during power-up to put the Sonoff into bootloader mode, and can also be used to toggle the output or do other actions.


Alternatively, you can connect an external button between GND and GPIO14 so that your software running on the Sonoff can detect when it has been pressed. Some firmware, including Theo Arends’s TASMOTA, supports this out of the box.

GPIO14 is exposed on the internal header used to upgrade the software on a standard Sonoff. There is already a pull-up resistor on GPIO14, so you don’t need any other parts. Just connect a button across the GPIO14 and GND pins, and you’re done!


Even better, TASMOTA has an option to support an external switch instead of an external button. The difference is that with a button, you want the output to change state each time you press and release the button. This means the firmware needs to treat both the button press and release (cycling from HIGH to LOW to HIGH) as a single event. But a switch just changes state (goes from HIGH to LOW, or goes from LOW to HIGH) and stays there because it latches in place. So your software needs to treat each level change as a separate event, and toggle the output. Once again, TASMOTA supports this out of the box.


As explained in the section about switches, the regular Sonoff exposes GPIO14 on the internal header that is used for flashing new firmware. The same header also provides GND and 3.3V connections, and the GPIO14 pin is provided with a pull-up resistor. This makes it super easy to connect anything that needs a single digital pin, such as an external switch / button or a one-wire sensor.

sonoff-th-sensor-pinoutTo make it even easier, the Sonoff TH10A and TH16A both feature a 2.5mm 4-way (TRRS) socket that is intended for connecting external sensors. The socket provides 3.3V, GND, and GPIO14: the same I/O pin exposed on the internal header of a normal Sonoff. That means you don’t even need to modify the board, you can simply plug in your sensor or switch externally.


The 2.5mm socket also has a 4th connection, but there are parts missing inside the Sonoff so it’s left unused. You can fix this easily by putting a solder blob across two pads on the Sonoff PCB, and optionally installing a pull-up resistor.

In the video I said that there is a 10k pull-up from GPIO14 to 3.3V. However, I didn’t notice that there are actually 2 pull-ups in parallel, so the effective pull-up on GPIO14 is 5k! You can still use a 10k pull-up on GPIO4 if you like, or you can use a 4.7k resistor if you want them to be about the same. 4.7k is common for I2C, but 10k is generally fine too.



There are many alternative firmware projects for the Sonoff. Personally I love Theo Arends’s firmware, but there are many others that may suit you better.

To learn about how to install new firmware, see SuperHouseTV Episode #17: Home automation control with Sonoff, Arduino, MQTT, and OpenHAB.

If you have any other suggestions please let me know in the comments below, and I’ll update this list.


Because the Sonoff uses an ESP8266 microcontroller, there are a huge number of sites with information that’s relevant to the Sonoff. These include:

163 thoughts on “#21: Six Sonoff Secrets

  1. Excellent Post and Website. i have a question, does you connect 3 DTH sensors at the same time? are cable lenght limit to do that?.


  2. Hi Jonathan, reading your section on “Sensors” I was wondering if a rain sensor like the FC37 can be connected to one of the sonoffs. Basically a rain sensor just provides a variable voltage output depending the amount of water on the detection plate between (0-5V or 0-12V depending on the models).Shouldn’t this work just like a temperature sensor?
    Thanks for your opinion

  3. Hi Jonathan, very good information. Can a switch be added, like a reed switch. If so, should it connected to GND and GPIO14?


  4. Thanks for the great work.
    See if you can help me, I need to use the external switch but my sonoff is 4CH how to do this with only 1 GPIO?

  5. Hi

    Can the sonoff dual work behind dual rocket switches?

    I read on the tasmota wiki that one of the switches needs to be attached to gpio0 which means of you use a rocker switch it can go into programming mode when power is reapplied. Although i imagine this is onli an issue in a powercut?

    1. The relays can be controlled by external push buttons or switches connected to the header at the designated positions. BUTTON 0 (= GPIO0) connected to GND controls relay 1 and BUTTON 1 (= GPIO9) connected to GND controls relay 2.

      See the image on the right how to configure this functionality in Tasmota as Switch1 and Switch2.

      NOTE Make sure not to use a switch that keeps the connection between GND and BUTTON 0 active while power is re-applied as the device will start in programming mode

    2. Rocker* switches. Sorry auto correct

  6. Help please
    Can you tell me what pins to connect to on the jack plug
    Thanks tony

  7. For the Sonoff dual- I’m looking for gpio’s for 2 external switches ( as GPIO14 in basic Sonoff).
    Can you please refer?

  8. Hi there.

    I would like the th16 to send a push message (error notification) to a switching contact – possibly to the sensor input.

    Can you solve it?

    Thanks to Roland

  9. Hi how can I connect a Ethernet module on a Sonoff? Thank you

  10. I’ve made a simple input for myself. I’ve detailed it here –

  11. hi there
    i did try to connect as shown GPIO14 with GND on my son off basic R2 but it’s not working. could you precise me if the welding should be on both side or only on track side ?
    tks for your answers.

    1. Did u solve this?

  12. Hello, I have a sonoff basic and I want to use GPIO14 for switch. Must I have another firmware or work with the original 2.6. Thanks

  13. Hey, I like the idea of replacing the memory chip, and I would like to do that on Sonoff T1 “3Gang” UK however I cant find the memory chip itself on the board. Do you have any experience with those ?

    1. The Sonoff Touch series don’t use the ESP8266 (which has an external memory chip) they use the ESP8285, which has the same processor core but has 512MBit of EPROM physically inside it. Unfortunately that means you can’t just swap a memory chip like you can with ESP8266 boards.

      1. That makes sense, thank you. Have great new year.

  14. Hello,
    Do you know if i found somewhere the relay from sonoff basic as spare part? on one of my sonoff basic the relay is broken.


  16. Hi,

    I damaged the GPOI0 button terminals while trying your video and need to see where else I can connect to it. Please, could you show me where else I can connect to?

    Please help 🙁

    1. What model of Sonoff do you have? GPIO0 always has a pull-up resistor on it, so you can use the end of the resistor as a place to solder on a connection. It’s just a matter of finding the resistor, which depends on the model.

  17. hello, I need to use sonoff th10 at low voltage (12v or 5v) may I ? were to connect low voltage?
    Do I need to change rele’?.
    thanks and best regards

    1. Do you have any progress on it? I would like to do the same (24v). Thanks

  18. There are only 8 loop/ countdown timers available with SONOFF switches. How to increase the number of timers.

  19. Have enjoyed this tutorial on Sonoff basic modification with tasmota and toggle switch.
    So bought a few sonoff to test out, keeping in mind i’m very new to electronics and learning as i go along with your tutorials.

    Well have received my 2 sonoff but found they look different. Some googling reveled that Sonoff has mad a hardware change to the Basisc “Sonoff RF R2 POWER V1.0”

    I was still able to follow the tutorial and flash the sonoff with tasmota but issue i’m come across is as there is no GPIO14 how do i introduce a Toggle switch as i’m intending to use with existing light switch.

    Can i use another pin like TX and Group as a toggle switch, as i found when changing the Module type to Generic (18) i had this option? but want to reach out and see if there was a better way to do this with new Sonoff Basics.

    Thanks inadvance


  20. Hi Jonathan Oxer,
    I am using Sonoff Basic+RF & Sonoff 4Ch switches.
    There are only 8 loop/ countdown timers available with 1Ch/ 2Ch/ 4Ch switches. 8 timers for a single ch. switch is enough, but for a 4ch. switch it is just 2 timers for switch. How to increase the no. of timers in the 4ch. switch.

    Please Share. Thanks.

  21. Hi, thank you for your great explanations and tricks!
    One question pleas: Is it possible to swap L (live) and N (neutral) input or will the Sonof TH16 be destroyed then? European jacks (Schuko) can be plugged in either direction to a 230V socket so that N-L-crossing ist likely. I have read in another blog (cannot remember the name) that the Sonoff Smart Switch (without temperature humidity sensor) will not tolerate swapping N and L.
    Thank you and best wisches!

    1. Looking at the circuit for the TH16, I *think* it should work either way around, but it would be a really bad idea because only one of the mains connections is switched. Power is tapped off the input to go into the power supply to run the electronics inside the Sonoff, but the power supply is taking an AC input so it’ll work either way. It won’t know the difference. The problem is that the neutral wire passes straight through from the input to the output, while the active wire is switched by the relay. If you swap the inputs, the active wire will pass straight through and the neutral will be switched. This will work, but it will leave active permanently connected to the device you’re controlling, which could be a safety hazard.

      1. AC is not polar. Live and Neutral are not “directions” like +ve and -ve. Its is totally OK to swap them electrically speaking, but as mentioned, for safety the Live side is always switched, but sometimes the neutral side is not.

        1. Yes, I know AC isn’t polarised if you take the average over time (although of course it is polarised at any specific moment in time other than at zero-crossing) but if you treat them interchangeably it can cause safety problems with ELCBs not being able to do their job properly. If you reverse them, it’s quite possible that you will totally undo any protection that you would otherwise get from an ELCB in your switchboard.

  22. Hello, what are your thoughts on the Sonoff 4CH Pro?

  23. the statement about requiring a solder blob to make the GPIO4 come out ton the 2.5mm socket of a TH10 might be out of date. i have a ver1.2 PCB and the board is populated with a 0ohm (yes!) resistor already.;postID=2786406463371932769
    Hope this is useful!

    1. Hello KDMcMullan, i trying to go to your blog (follow your link) and it was impossible. I have TH10 ver 2.1, and i wish to see how the resistors are connected. i tried to connect i2c LCD but it was impossible (i2c scanner didnt detect). Anybody have any idea how to make it? thanks in advance.

  24. I made a thing! Here’s a 3d printed case I made to make my Sonoff a little bit safer

    1. Great work! When I saw the first photo I thought it was an injection-moulded case that had been modified. I’m very impressed that you created that from scratch.

  25. Hi Jonathan,
    I have a standby generator with an auto transfer switch. I would like to get a push notification to my cell phone when the generator starts and shuts down. I have dry contacts to indicate if it is running and if its off. Is it possible to use a TH10 or TH16 to do this? Use the 2.5 mm socket to detect the contacts to send a push if contacts close or open? If so which pins would I need to use, 3.3/GND/GPI04/GPI014? Would it send a push for open and closed? I have uninterrupted 12VDC and would like to use that as the voltage source. Is there anyway to wire it that way? Could the sonoff be used without flashing, If not what would you recommend? My wifi has a ups.
    Thank You,

    1. Yes. Use Gnd and either GPIO4 or GPIO14. Yes a message is generated for each change of state of your relay.
      This is what you might call an extended feature. So, it can be done best by flashing with a more generic firmware, but that is not a complicated process. Consider TASMOTA. However, having flashed it, the default web app will no longer work. You need to have a PC or a Raspberry Pi continuously running a broker in order to accept the MQTT messages and send them out to your phone, or a web browser.
      The sonoffs are designed to run off mains. Yes, the PSU can be bypassed, but I wouldn’t recommend it.
      Ask more questions.

      1. Hi Ken,
        Thanks for the information. I was hoping to use it with the default app. I have been doing some research and found someone using a Rpi. They hooked the contacts up to the Rpi and wrote a program in Python to send the push with instapush. It is for a door sensor but I should be able to adapt or modify it. I’ve never done any programing other than make some batch files in DOS. I guess I’m looking for something somewhat simple and inexpensive to make it work. If you have any other ideas I would appreciate them.
        Thanks. John

    2. I used a sonoff mini for a similar project to monitor when my water softener went through a cycle. I put a micro switch on the control wheel and connected it to the switch contacts of the mini. It the logged the on/off times.

  26. Good day!
    I am hoping to use the network available in a large scale facility to activate an electric strike on one side of the building from a hardwired switch activated on the other side. Can I use Ewelink to create a scene that will toggle the state of the Sonoff connected to the strike when I activate GPIO14 on the Sonoff TH10 connected to the switch at the other end of the property? Both devices would be on the same network.
    Thank you for your support!
    Kind regards!

    1. Hi James Any progress on this? I’m looking to do similar.

      1. I found $15 wall switches that are dimmable did the trick for me

  27. I was wondering if you know with the basic sonic module you are able to select state of module on power applied either on or off or keep.
    Would it be possible to add a toggle on power on like that you could operate the regular light switch with the module installed at the light fixture in the ceiling , would make for installation a lot easier

  28. Hi Jon where is GPIO14 on the new sonoff basic R2? So I can add a switch with Tasmota out of the box

  29. Hello, Excelent explanation.

    I have a doubt: If I have the Sonoff TH16, and I want to connect my wired DS18B20 (Vcc, data, GND), how should I sold the plug 2,5 mm plug? Pin Data should go to GPIO4 or GPIO14? Should I put an external pull up resistor (or it is included inside the Sonoff TH16)?

    Thanks a lot!!!!!!

  30. This is an amazing post.

    Found it while trying to see if a MG 811 Co2 sensor would be compatible with the Sonoff th10 or th16

    Do you think this would work?

    1. Any luck integrating a CO2 sensor with the TH16?

  31. Did anyone try to set up TH16 together with manual (home original) thermostat? so, using TH16 or genuine thermostat indistinctly.

  32. Great post with plenty of details explaining the inner workings of the switch.

  33. Hi Jonathan,

    I just discover sonoff TH16 months ago, I want to switch on/off my air conditioner without to cut the main power, do you know a solution?

    Thank you.

  34. Hello friends, i am electronics engineer. i am basically freelancer. So now i am working on one project which uses sonoff basic as hardware. I am making product on it. So i have search about tasmota but there is binary file not source code so i can not modify and binary file can not use in product. So there is any solutio?
    And i also work on mongoose os. So i want to get review on mongoose os that should i use it or not?

    1. Tasmota is open source. All the source code is public at

  35. Excellent post, especially as I plan to extend my existing sonoff projects. I was looking for the software downloads and here they are 😉

  36. Very informative tutorial/ videos, thanks

  37. Could you cover adding RF to the boards?

  38. Love your video. I have had several different types of these unmodified and seems within a year with little use just plugged in they have become unresponsive and no lights as if they are burnt up. Anyone else have this problem and is there an easy fix or something to prevent this? The message about adding RF is for a different non cased model and it has been contrling my garage for years with no trouble except when the wifi acts up.

  39. Hi Jon. I have the Sonoff TH16 ver 2.1 2019-08-26 and when connecting with the 2.5 plug GND and GPIO14, to place a switch, the state does not change. Should I add something extra in this version ?

  40. Great job, I have learned a lot. I would like to use an ESP-01 with I2C, do you have any info on that.
    also which pins support an interrupt?
    Thank you in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *