It’s surprisingly easy to make your own simple air quality sensor. All you need is a cheap laser-scattering particulate matter sensor, a Wemos D1 Mini, a soldering iron, and Tasmota.
Part 1 shows how to make the simplest possible version of the SuperHouse Air Quality Sensor, the “Basic” version.
Part 2 will show how to improve it to make a more advanced “Display” version, and Part 3 will step it right up with the “Pro” version.
- Plantower PMS5003 particular matter sensor
- Wemos D1 Mini with ESP8266
- 3D-printed enclosure (download STLs or buy pre-printed)
- Explanatory paper: “Introduction to Laser Scattering” (PDF)
Here in Australia we’ve recently had a terrible bushfire season, and there’s been a lot of concern about the effects of smoke on air quality. Smoke particles, pollen, and many other forms of air pollution are tiny. Really tiny. Many people have been wearing “PM2.5” face masks, which means they are designed to filter out particles as small as 2.5 microns in size, but pollen and smoke can be even smaller than that.
Detecting tiny particles down in the 0.1 to 10 micron range is hard. Normally you’d need an electron microscope to detect something this small. In fact these particles are so small that they are often smaller than the wavelength of light, which is in the region of 0.5 microns. This means light doesn’t interact with them in the usual way: instead of bouncing off them like a particle, it can bend around them like a wave, and it can also refract inside them like tiny lenses.
Laser-scattering particle detectors pass a laser through a test chamber, with a deflection sensor on the other side. Particles in the test chamber cause the beam to be scattered in different ways, and the deflection sensor can use this scattering to determine the number and size of particles in the chamber.
This process creates a series of concentric rings on the deflection sensor, which can use the spacing of the rings to determine the characteristics of the particles.
The particles that are detected are then categorised, or “binned”, into different size ranges for reporting.
All of this functionality is wrapped up in the tiny Plantower PMS5003 sensor, which provides a serial interface to report the statistics for the particles that it detects.
Reporting is normally provided in a couple of forms.
The simplest number is the PPD value, which stands for “particles per deciliter”. The higher the number, the more particles there are in the air sample.
The most commonly used number is the “ug/m^3” value, which is micrograms per cubic meter. This is the total mass of particles in that size range in a cubic meter of air, so smaller particles will require a higher raw count to add up to the same mass as larger particles.
The “Basic” version of the SuperHouse Air Quality Sensor only requires a a Plantower PMS5003, the connection cable that comes with it, and a Wemos D1 Mini. See the links above for sources to buy them.
You can also print your own 3D-printed enclosure, or buy one from me if you don’t have easy access to a printer.
Connect PMS5003 to D1 Mini
The PMS5003 requires a 5V supply because it has an internal fan to keep air flowing through the test chamber, but all its I/O connections are 3.3V.
This is perfect for a D1 Mini, because we can connect the power pins to 5V on the D1 Mini and connect the sensor “TX” pin to an I/O header on the Mini.
Cut the supplied cable off at about 2/3rds of its length. Plug it into the PMS5003 to check the orientation, and then strip and tin the ends of the wires connected to pins 1, 2, and 5.
Connect VCC and GND from the PMS5003 to the 5V and GND headers on the D1 Mini.
Connect TX from the PMS5003 to the D4 header on the D1 Mini, which is GPIO2 for the ESP8266 MCU.
3D printed case
I’ve designed a case that slips over the PMS5003 and provides a space for the D1 Mini and wires. You can download the STLs and print it yourself, or if you don’t have access to a 3D printer you can buy it from me in a variety of colour options.
The case comes in two halves. Insert the PMS5003 into the case first, and then slip the D1 Mini into the space at the bottom. The case is oriented so that if the USB socket is on the side towards the PMS5003 it will be accessible through a slot.
Push the wires down into the case so everything is neat, and then slide the other half of the case over the top. It may take some jiggling to get the wires out of the way and the D1 Mini properly inserted into the slot.
There are many ways to install Tasmota on the D1 Mini, but my new favorite is to use Tasmotizer. I did a whole video about how to install and use Tasmotizer, so follow the instructions here if you need to install it:
Once you have Tasmotizer running, connect the D1 Mini using a USB cable and select the port.
Note: As of Tasmota v8.2, support for the PMS5003 has been removed from the normal “tasmota.bin” release binary. Instead, you must select “tasmota-sensors.bin”.
- Click the button next to “Release“.
- From the drop-down, select “tasmota-sensors.bin” (not the regular “tasmota.bin” as shown above)
- Click “Tasmotize!” and wait about a minute for the D1 Mini to be flashed and reboot.
Configure WiFi and apply the “SuperHouse AQS” template
After the D1 Mini has been flashed, click “Send config” in Tasmotizer to open the configuration screen.
- Click the checkbox to enable the WiFi section, and put in the details for your WiFi network.
- If you use MQTT, click the checkbox to enable the WiFi section and put in the address for your broker. My personal preference is to change the “Topic” entry to “tasmota-%06X” so that the MQTT topics will be dynamically generated using the unique ID of each D1 Mini.
- Click the button next to “Template”.
- Copy the template below, and paste it into the text box at the bottom of the config screen:
Click “Save” to send the new configuration to the D1 Mini.
It will then restart, and will connect to your WiFi network using the values you just provided.
Connect to Tasmota web interface
You can use a serial console connected at 115200bps to get the IP address directly from the D1 Mini, or look in the management interface for your DHCP server to find the recently added device.
Once you’ve found the IP address, put it into a web browser to load up Tasmota’s web interface.
The module will report its latest readings, updating as fast as the sensor is sending them.
You can also configure the D1 Mini manually if you didn’t use the template above. Starting from a default Tasmota installation, log into the web interface and set up the module as shown below.
Access data via MQTT
Tasmota periodically publishes all the PMS5003 readings aggregated into a single JSON string, in the “../SENSOR” topic.
The topic will depend on the settings you applied for MQTT. In my case, with the “Topic” modified as explained above, the readings are published to a topic that looks similar to “tele/tasmota-5F596F/SENSOR” with the unique ID of this particular device substituted.
The published value will look something like this:
You can parse the JSON using your favorite method, such as with Node-RED. I’ll go over this in more detail in Part 2 when we look at more advanced software options.
The “PMx” values are micrograms per cubic meter. The “PBx” values are particles per deciliter.
This “Basic” version of the SuperHouse Air Quality Sensor is very simple to make, but it has a couple of limitations.
The laser and the deflection sensor in the PMS5003 can degrade over time. After about 6000 hours of continuous use it may begin to decrease in sensitivity. The life of the sensor can be dramatically extended by shutting it down for a couple of minutes, then waking it up, giving it time to stabilise, taking a reading, and shutting it down again. With this change the sensor can last for many years.
There is also no way to interact with the device directly. You have to access it over the network, either by loading the Tasmota web interface or by using the data published to MQTT. Adding a screen and a mode button can make it easy to read particulate levels directly on the device.
Both of these limitations are fixed in the “Display” version of the SuperHouse Air Quality Sensor in the next episode. Stay tuned!
Installing Tasmota onto a device such as a Sonoff is usually done using esptool.py, which is a powerful command line utility but it can be a bit confusing if you’re not used to it. Now it’s been paired with an amazing graphical interface called Tasmotizer that gives you point-and-click convenience, and adds some handy features for configuring your devices:
The Tasmotizer page has good installation instructions, with three options given.
- If you use Windows, download the executible and run it.
- On Linux or MacOS, you can install using Pip.
- If you want the absolute latest development version you can clone the Git repo and install manually.
Use whichever method suits you best. I used Pip to install it on my iMac, my Macbook Pro, and my Ubuntu desktop, and the process went smoothly on all of them. Make sure you have the latest version of Pip, and then use it to install Tasmotizer:
pip3 install --upgrade pip
pip3 install tasmotizer
If your Python installation is set up so that new programs are automatically available, it should be possible to simply type in the name and press “Enter”:
However, you may not be so lucky. You may have to find where Pip installed it. Pip can tell you where the files are for a specific package, but its output has horrible formatting that’s hard to interpret. Run this command to see a list of all the files in the Tasmotizer package:
pip3 show -f tasmotizer
The output will include a line called “Location” which shows the directory where the program is located. On my iMac, Pip installed Tasmotizer at:
But on my Macbook, it was installed at:
And on my Ubuntu desktop, it was installed at:
It’s a pity that Python’s installation management is such a mess, and produces unpredictable results. Hopefully you can find the location for your installation without too many problems.
Once you’ve discovered its location, paste in the appropriate command and press “Enter” to launch Tasmotizer.
Connect the device to your computer
Your target device needs to be connected to your computer using USB, either by directly plugging in a cable or by using a USB-to-Serial adapter. Some devices such as Wemos D1 Mini boards have built-in USB. Sonoff boards don’t have USB so you’ll need to make up an adapter to suit the programming header for your specific board. I’ve done many videos and guides for reflashing various Sonoff models, and the Tasmota site has excellent documentation so follow the appropriate guide to make the connections.
Most Sonoff models use a simple 4-pin header, so I designed the Sonoff Programming Adapter to make it easy to plug in a 3.3V USB-to-Serial adapter with a standard 6-pin header.
Place device into bootloader mode
The ESP8266 / ESP8285 processor needs to be placed into a special bootloader mode before it can have Tasmota installed. This is done by powering it up while the GPIO0 pin is held at 0V, which is usually done using the control button. The sequence is:
- Press and hold the button.
- Connect power.
- Wait a couple of seconds, then release the button.
The device then stays in bootloader mode, waiting for new software to be loaded.
Select device in Tasmotizer
Click the “Refresh” button so Tasmotizer will scan for connected devices and update its list. Use the drop-down to find your target device.
Select the firmware image
Tasmotizer gives you three options for selecting a firmware image.
If you have your own binary, such as a version of Tasmota or some other firmware that you’ve compiled or downloaded, click the “BIN file” radio button and select the file from your local disk.
If you want to install the current release version of Tasmota, click the “Release” radio button and then use the drop-down menu to select the specific flavour of Tasmota for your device.
If you like to live on the edge, you can click the “Development” radio button and use the latest development code that hasn’t been released yet.
Set flashing options
If you want Tasmotizer to make a backup of the existing software on your device, click the “Backup original firmware” option. This will allow you to put it back onto the device later if you change your mind.
If you want to make sure the entire memory of the device is cleared, click the “Erase before flashing” option. This makes sure there is nothing remaining from the previous firmware still left on the device, such as saved configuration options. This is a good idea to make sure you have a fresh start and Tasmota won’t read data from a previous installation.
Flash the firmware
With the correct firmware image selected, click the blue “Tasmotize!” button. Tasmotizer will download the selected image (if required) and install it onto your device.
You’ll see a progress bar as the image is installed. Once it’s done, you’ll be prompted to restart it.
Congratulations! Tasmota is installed.
If you want to configure it manually you can do that by following the usual Tasmota instructions. However, Tasmotizer can save you a lot of time by allowing you to do some basic configuration via USB while it’s still connected to your computer.
Select config options
Click the “Send config” button to open a configuration window.
Click the check-box to enable the WiFi section, and enter your WiFi network name and password.
Click the check-box to enable module/template setup, which gives you options to either select a pre-defined module or apply a template. Applying a module profile or a template allows your device to be configured entirely from Tasmotizer.
If you have a common device, select “Module” and find the device in the drop-down list.
If you have a device that has a template provided for it, select “Template” and then paste the template into the text box. There are more than 1000 templates provided at the Tasmota Device Templates Repository.
If you use MQTT in your home automation system, click the check-box to enable MQTT setup and put in the address of your MQTT broker.
You can manually define the topic for this device (such as “bedroom1”) but my personal preference is to allow the device to generate the topic based on its own internal ID. That way all devices come up with their own unique topics, which can then be referenced in the home automation system.
To do that, change the “Topic” setting to add the extension “-%06X”, like this:
What this will do is take the last 6 hexadecimal digits of the device ID and append them, so the topic will be something like “tasmota-6A0B15”. This value is then used to generate the FullTopic value below it automatically, by replacing the “%topic%” placeholder. The result will be full topics that look similar to:
cmnd/tasmota-6A0B15/POWER tele/tasmota-6A0B15/TEMPERATURE ...etc
I like this approach because it means that all my Tasmota devices can have the same configuration, but they still end up with unique MQTT topics.
Send config to device
With all your preferred options set, click the “Save” button. Tasmotizer will send your configuration to the device, and you’re all done. This step is a bit strange, because it happens so fast that it seems like it couldn’t possibly have done anything, but if you get a confirmation dialog then you’re all set.
Finished! Your Tasmota device will now reboot and apply the settings that you configured, so after a few seconds it will be on your network. Just follow the Tasmota documentation to learn how to link it to your home automation system.
I’m sure you’ve heard of the crazy coronavirus epidemic that’s rapidly spreading around the world, and has now been declared a global health emergency by the World Health Organization.
One of the areas that has been hardest hit by the virus is the city of Wuhan, on the Yangtze River in east-central China. Wuhan went into a state of lockdown on January 23rd, with businesses closed and everyone told to stay home and avoid contact with other people.
China is taking this threat extremely seriously, responding on a scale that I don’t think would be possible in any other country. I don’t know of anywhere else in the world that could build entire 1000-bed hospitals from the ground up in 6 days, just to respond to a sudden medical need. If anyone can face a challenge like this, it’s the Chinese.
The primary focus has to be on the health of those in the affected areas, of course. So far I haven’t heard of any of my Chinese colleagues being infected, and I hope it stays that way.
Bare PCBs for both Freetronics and SuperHouse products are mostly produced by Gold Phoenix, which is located in Wuhan, right in the bullseye of the epidemic. Like almost all businesses in Wuhan, Gold Phoenix has told workers to stay home and stay safe.
Some of our prototype PCBs are produced in factories around the city of Shenzhen, in southern China just over the border from Hong Kong. Those factories are currently closed too.
Our PCBA (PCB Assembly, which includes pick-and-place installation of parts on the boards) and final testing and packaging is done in Beijing, which has now also gone into lockdown. Not only are factories closed, but roads out of the cities have been closed to prevent the spread of infection so any boards that have aleady been produced are stuck in warehouses.
There are currently batches of EtherMega and EtherTen boards that were scheduled to ship a few days ago, but they are now caught up in the lockdown and can’t leave Beijing.
So over the next little while there will probably be stock problems for both Freetronics and SuperHouse. Please be patient while I do my best to assemble what I can using local stock of bare PCBs and parts, and keep in mind the millions of people who are now stuck at home with dwindling food supplies. It may be frustrating that products are out of stock, but that’s really not important when the health of so many people is at stake.
I’m taking a big leap and paying to have SuperHouse boards produced in a factory, which costs a lot of money up front but hopefully will give me more time to work on videos. It also means that some products will now have awesome retail packaging.
I’m also clearing space in my lab by giving my Patreon supporters access to a special secret section of my online store, where they can buy clearance items for not much more than the cost of postage. To make this happen, the online store now has a password-protected category called “Members Only”. Patreon supporters will receive passwords from time to time, giving access to special discounted products that only they can see.
Still plenty of work to do, and the controls are too twitchy, but it works!
This is a combination of the Chair Breakout Mini (to read the joystick position and transmitting it on CAN bus) and the Wheelchair Motor Controller, which receives the messages and drives the motors and brakes.
We’re making rapid progress on a number of Assistive Technology projects, so if you want to join in the discussion please join the SuperHouse Discord server and use the #assistive-tech channel.
This was a surprisingly fun and useful project!
Connecting test probes to PCBs can be difficult when the contact points are very small, or when you need to keep the probes in place while using your hands to run tests or use a computer. Normal test probes for multimeters, oscilloscopes, and other equipment have to be held in place.
This amazing 3D-printed PCB workstation uses acupuncture needles as test probes. The test probes are attached to adjustable arms that can hold them in position on the device under test.
Print the parts and make one for your own lab:
- View directly on YouTube
- Discuss on the SuperHouse forum
- Discuss on the SuperHouse Discord
- PCB Workstation with Nano-Probes project on Thingiverse
- Probe Base variation (including Fusion360 file)
You can print the plastic parts yourself using the files provided on Thingiverse, or you can buy a kit from the designer. I printed the parts over the space of a few days while I was working on other things. The base takes a few hours to print and there are many other parts, so don’t try to rush through it. Collect everything you need and lay it out to make sure you have it all.
- Probe arms: 3D-printed parts, M4 bolt with hex head, washer, and M4 wing nut
- Pack of acupuncture needles (I used these ones in 0.35x40mm size)
- 3D-printed base plate
- PCB mounts: 3D-printed bracket, M5 bolt with hex head, washer, and M5 wing nut
- light-weight, flexible hook-up wire
- Pin headers
- Heat-shrink tubing (I used 3mm on the pin headers, and 1.5mm on the needles)
- Self-adhesive rubber feet
- Ferrules and crimper: useful if acupuncture needs have stainless steel ends
Assemble base and pcb holders
The Thingiverse project includes both large and small PCB holders. I’ve only printed the small ones so far. Thread an M5 bolt up through the base and a bracket, and put an M5 washer and wing-nut on top. Make sure the bracket can slide along the slot.
Stick a rubber foot under each corner of the base, to help it sit securely on your bench and give the bolt heads enough clearance to slide without sticking.
Assemble probe brackets
Insert the vertical bracket into the mounting base. I used a drop of superglue to lock it in place.
Danger! If you put superglue into the mounting base and then squeeze in the vertical bracket, the superglue can squirt out under high pressure. Be very careful that you don’t squirt it into your eyes!
The handles of the acupuncture probes that I bought are about 1.3mm in diameter, and didn’t fit into the mounting clips. I drilled out the clips with a 1.5mm drill, and used super-glue to attach them in place with most of the handle sticking out the top.
The mounting clips are a press-fit into the horizontal arm. Use super-glue to fix them permanently.
Pass an M4 bolt through the vertical mount and horizontal arm, then put an M4 washer and wing-nut on it.
If the end of the acupuncture needle is plain steel, you can solder the wire directly onto it. My acupuncture needles are all stainless steel so I used a ferrule with the plastic cover removed, and crimped the wire onto the end of the needle.
I put 1.5mm heat-shrink tubing over the needle, with just the end exposed. This is optional but it may help prevent the probes from short-circuiting against each other.
Thread the wire along the horizontal arm. What you put on the other end of the wire is up to you: I soldered on a pin header and then put heat-shrink tubing over the joint. Alternatively, you could put on an alligator clip, a banana plug, a spring clip, or whatever suits you.
With the device under test mounted on the base, press-fit test probes into the base. Use the handles on the test probes to rotate them, and tighten the wing nut when the needle is in position.
The needles are quite springy, so it’s easy to adjust their position with a pair of tweezers after they are approximately right. The heat-shrink on the needle helps with this, because it’s easy to grip with the tweezers.
Every single Sonoff model has used the Espressif ESP8266 / ESP8285 processor – until now.
But now ITEAD has gone in a different direction, and released the Sonoff BasicZBR3 which drops WiFi entirely in favour of Zigbee. It doesn’t even use an Espressif processor: instead it uses a Texas Instruments CC2530, which is based on the 40-year-old Intel 8051 processor architecture.
What is Zigbee, and how does it compare to WiFi? Is the Sonoff BasicZBR3 any good?
Let’s find out!
- View directly on YouTube
- Discuss on the SuperHouse forum
- Discuss on the SuperHouse Discord
- Sonoff BasicZBR3: product page | buy online
Zigbee is a wireless communications system that’s similar to WiFi in some ways, but they are optimised for very different purposes. They both use the 2.4GHz unlicensed ISM band, and they’re both based on standards managed by the IEEE: 802.11 for WiFi, 802.15.4 for Zigbee.
WiFi is optimised for devices with plenty of power available, and that also require very high throughput. It provides bandwidth in the region of hundreds of Mbps. Perfect for laptops, smartphones, tablets, and security cameras.
Zigbee is optimised for devices that need to run at extremely low power for a long time, and that don’t need to transfer much data. It provides bandwidth of 250kbps, so only about 1/1000th as much as WiFi. It’s suited to tiny devices that need to run on a coin cell for several years, and only pass small amounts of data. Great for temperature sensors and similar IoT devices that only need to send tiny amounts of data every few minutes.
Star topology vs mesh topology
WiFi uses a star topology, with each client device connecting directly to an access point. All communication is arbitrated through the access points, and end devices don’t talk to each other directly. The access points are linked together using some sort of backhaul, usually wired Ethernet. With this topology, you need enough access points to provide coverage of the entire area where you will be deploying devices:
Zigbee is much more flexible in its topology. It can be operated as a simple star just like WiFi, but it can also operate as a mesh because some Zigbee devices can act as relays to extend the coverage of the network:
There are three types of Zigbee device.
Zigbee End Devices (ZED) are nodes that only connect to one other device. They can enter a deep sleep mode to go offline when they aren’t sending data, so they can typically operate for 2 years or more from a tiny coin cell. Typical ZEDs include temperature sensors, light switches, and motion detectors. There can be many ZEDs in a typical Zigbee network.
Zigbee Routers (ZR) are nodes that don’t go into sleep mode. They stay awake continually, ready to pass on messages between other Zigbee devices. They are also functional devices in their own right: they include smart power plugs and light globes, because these typically have mains power available and can remain operating indefinitely. They don’t need to go into sleep mode to conserve a battery. With a few ZRs spread across your coverage area, your network can provide connections for many ZEDs.
Zigbee Coordinators (ZC) are the most important type of node. There can only ever be one ZC in each network. It always takes the first network address, and then it assigns addresses to all the other devices in the network as they join. You can think of it as being like the DHCP server in a typical LAN. Usually the ZC will also act as a gateway to other types of network, such as connecting your Zigbee network onto your WiFi network or wired LAN. Many home automation hubs can act as a ZC.
Pairing with Alexa
The Sonoff BasicZBR3 is wired up the same way as other Sonoff models, with active and neutral coming in on the input side on the left, and then going out to the load (such as a lamp) on the right. Follow the instructions provided by ITEAD and the guides in my previous videos to make the connections.
Once the BasicZBR3 is installed, turn on the power. It will begin in pairing mode, ready to join an existing Zigbee network. Startup is very fast, and it will be ready within a second or so.
You will need a home automation hub that can operate as a Zigbee Coordinator, such as an Amazon Echo Plus.
With the BasicZBR3 turned on and in pairing mode, and within range of your Echo, say “Alexa, discover devices.”
Your Echo will tell you that it is looking for new devices, and the BasicZBR3 will flash its output when it is discovered. The Echo will wait for some time in case there are devices that are slow to respond, so you will have to wait a minute before it will report back that it has found your new device.
That’s it, you’re done! You can now control the BasicZBR3 using commands such as “Alexa, turn on the first plug.”
Customisation of the node names can be done through the Alexa app.
CC2530 processor connections
Programming the CC2530 requires power to the device, plus DD (Debug Data), DC (Debug Clock), and Reset.
In the BasicZBR3, the output relay is controlled by I/O pin P0_7, and it reads the tactile switch using pin P1_3:
The BasicZBR3 provides the debug connections for the CC2530 in a handy 5-pin header, so if you want to mess around with the firmware and load your own code into it, these are the connections on the PCB:
If you write any custom firmware for the Sonoff BasicZBR3, please join the forum or Discord server and share your results.
If you don’t put USB on your project, you have to decide on a programming header to use. But everyone does it their own way: Sonoff has theirs, wESP32 has another, many projects have them and they’re all different!
That sucks, so let’s fix it by deciding what we think should be the conventional programming header format for our projects.
My goals are:
- Define a convention for programming headers on ESP8285, ESP8266, and ESP32 boards.
- Use that header in our own projects, so that it becomes common and interchangeable.
- Lobby ITEAD to use the same header in future Sonoff models.
And the stretch goal: Convince Espressif to document it as a recommended header format for new ESPxx projects.
If we’re super-lucky, maybe we can convince ITEAD to fix the incomplete Sonoff programming header by adding RESET and GPIO0, and make all our lives easier in future.
Places to discuss this
- Sonoff programming header usage guide
- wESP32-Prog by Patrick Van Oosterwijck
- ESProg by iohippo
- ESProg by me
- ESP32 Programmer by Mike Rankin
- A different ESP32 / ESP8266 Programmer by Mike Rankin
- ESP Prog by Espressif
We need to decide on a physical format, and also whether to supply 3.3V or 5V to the target board from the programmer. The pins we need are:
Physical format options include:
- 1×6 0.1″ header
- 2×3 0.1″ header
- 1×6 2mm header
- 2×3 2mm header
- Something else? Ideas please!
The design considerations for the physical format include:
- Similarity to existing designs including Sonoff, wESP32, ESProg, and ESP32 Programmer
- Cheap and easy to use, with easy to source connectors
- Small footprint on the target device
- Perhaps leverage some existing standard such as P-MOD
- Ability to mount permanently as a sub-board in the project if required
Considerations for the choice of 3.3V or 5V include:
- Sonoff already requires 3.3V on the header
- 5V can be useful in some cases
- Switchable voltage would be possible, but could be dangerous and would lead to fragmentation of the convention
- Connection of programmer directly to VCC on target, compared to input of onboard 3.3V VREG
This has the advantage that it’s well documented, and many people have made adapters for it.
Already implemented on the wEPS32. 5V supply means the input can be diode-isolated from other supply sources on the board. 4 of the pins match the Sonoff header, except that Sonoff requires 3.3V so it’s not a perfect match.
wESP32-Prog header, but with 3.3V
This is the closest we could have to matching the Sonoff header while extending it to add the GPIO0 and RESET lines.
Documented by Espressif. Uses a 2×3 header, which is nice in terms of compact size. Unfortunately there’s no useful overlap with the ESP-01 header.
Doesn’t seem to match up with anything else in terms of pin order, but is perhaps the closest match electrically in a 1×6 format: all the necessary pins, with 3.3V supplied.
ESP32 Programmer by Mike Rankin
Nice 2×3 format header. If power was added this would be a nice format, but it doesn’t have anything to differentiate it from the ESP-Prog format from Espressif.
Other ESP32 Programmer by Mike Rankin
This one has a 1×5 header, which has all the pins we want except power.
The new Sonoff T4EU1C no-neutral touch switch seems to defy the laws of physics. It works with just a live wire, and doesn’t need a neutral wire.
How can that possibly work? And can we install Tasmota on it?
Let’s find out.
- View directly on YouTube
- Discuss on the SuperHouse forum
- Discuss on the SuperHouse Discord
- Sonoff T4EU1C: product page | buy online
- Tasmota firmware
- CoolTerm serial terminal for Mac, Linux, and Windows
- Sonoff Programming Adapter
- USB-to-Serial adapter with true 3.3V mode and built-in voltage regulator
No-neutral power connections
Traditional house wiring has an active and a neutral that meander around the ceiling to each light location, with the neutral connected directly to the light. The active comes down through the wall to the light switch, and then the output from the switch goes back up the wall to the active side of the light fitting.
This works well with passive switches, but most smart light switches need a neutral connection to power their own electronics. With only the active wiring going to the light switch, it can be very difficult to replace existing switches with smart switches.
Building codes in many countries now require that all light switches must have a neutral connection, but this is a recent change so most existing houses don’t have a neutral wire at the switches.
Smart light switches that are designed to be installed in place of existing switches and don’t require a neutral connection are generally called “no-neutral” switches.
The Sonoff T4EU1C is a no-neutral smart light switch with WiFi, so it only needs the active-in and active-out connections that are already found at most light switch locations. It operates by drawing a small amount of power through the light even when the light is turned off, so that it can run its own electronics.
The T4EU1C consists of two PCBs joined together by an 8-way header. The top PCB is the low-voltage logic board, which includes the processor, WiFi antenna, 3.3V voltage regulator, touch sensor pad and driver IC, and the programming header:
The bottom PCB is the high-voltage mains board, which includes a 12V-output mains power supply, and a relay and Triac for controlling the active output to the load:
Re-flashing the firmware with Tasmota
WARNING: There are problems running Tasmota on this particular model. It worked for me, but many other people have problems with the touch switch even when Tasmota is installed correctly. The rest of the Sonoff operates properly and it can be controlled by WiFi, but the touch sensor doesn’t work. There are a few people collaborating right now to figure out why this happens. If you’re feeling lucky, you can give it a try. However, it’s possible that you won’t be able to use the touch sensor until this problem is solved. There is ongoing discussion about it on the SuperHouse Discord server so please join in.
Just like all other Sonoff models so far, the firmware on the T4EU1C can be replaced with alternative open-source firmware to add new features such as local-network operation, MQTT, etc.
However, out of all the Sonoff models that have been released this is perhaps the most difficult one to re-flash. It can be done if you have the equipment and ability to make soldered connections to very tiny parts on the PCB, and this particular board also seems to have some strange requirements to force it into bootloader mode.
The common process for putting a Sonoff into bootloader mode is to hold the GPIO0 pin low (ie: to GND) while powering-up the board. In my testing, I found that this would result in the Sonoff appearing to accept the upload of the new firmware, but a strange checksum error would occur in the flash memory and it wouldn’t boot properly afterwards.
The process that I’ve found to work requires making a connection to the RESET pin as well as GPIO0, so that it can be put into bootloader mode after it has already been powered-up and connected to the programming adapter.
Re-flashing the firmware on the T4EU1C requires the usual connections to the programming header found on the logic board as shown in the picture above, plus connections to GPIO0 and RESET to force it into bootloader mode. Connection to the programming header is easy, because it’s exposed on the logic board in the same format as almost all other Sonoff models.
The difficulty is gaining access to GPIO0 and RESET, because neither of these lines are brought out onto pads for easy connections.
The most convenient place to make a connection to GPIO0 is the very thin track that runs diagonally on the top side of the logic board. Use a scalpel to carefully scrape away some of the green solder mask along the track. Be very careful that you don’t cut the track, and don’t scrape away the solder mask from the surrounding copper areas. If you do, it will be much harder to connect a wire to the track without causing a short circuit to the surrounding copper.
RESET is even harder. The only place it is exposed is on the end of a tiny resistor labelled “R3”, with a very small gap to an adjacent resistor. The connection must be made very carefully and quickly. If the resistor is allowed to heat up for more than about one second, the solder on the other end will also melt, and the resistor will move.
To control the GPIO0 and RESET pins, I soldered a pair of momentary buttons together and connected 3 lengths of very thin wire-wrap wire to them:
- The common (blue) wire is soldered to GND on the logic board.
- One switched wire (yellow, in my example) is soldered to the GPIO0 track after scraping off the soldermask.
- One switched wire (red, in my example) is soldered to the RESET line by attaching it to the bottom end of the resistor marked R3.
Be extremely careful when making these connections to the PCB. It’s very easy to damage the tracks or the parts, and if you don’t have the necessary equipment and skill to rework the board you may destroy your Sonoff.
Programming header connections
Use a USB-to-Serial adapter and jumper wires to connect the Sonoff to your computer. Make sure the USB-to-Serial adapter supports 3.3V mode, because the ESP8285 can be damaged if you connect 5V to it. The connections are the same as explained in previous videos:
In this case the power switch doesn’t matter, because we will use GPIO0 and the RESET line to force the Sonoff into bootloader mode.
The connections can be made with loose jumper wire, or you can use my Sonoff Programming Adapter which does the same thing.
The T4EU1C has the same pin assignments as a Sonoff Basic, so download the generic pre-compiled Tasmota binary.
Install the “Esptool” program, and open a terminal in the same directory as the Tasmota binary.
With the Sonoff connected to your computer as described above, and the buttons ready to assert GPIO0 and RESET, run Esptool as below:
esptool.py -p /dev/tty.SLAB_USBtoUART write_flash -fm dout 0x0 sonoff.bin
You may need to adjust the serial port address to match your computer.
Immediately after you press “enter”, follow this sequence:
- Press and hold both buttons that you have attached to the Sonoff.
- Wait about 2 seconds.
- Release the RESET button.
- Wait about 2 seconds.
- Release the GPIO0 button.
You should see Esptool immediately identify the processor on the Sonoff and begin uploading Tasmota. This entire process will take about 30 seconds. You should see output similar to this:
esptool.py v2.6 Serial port /dev/tty.SLAB_USBtoUART Connecting…….._ Detecting chip type… ESP8266 Chip is ESP8285 Features: WiFi, Embedded Flash MAC: 2c:f4:32:a8:18:8b Uploading stub… Running stub… Stub running… Configuring flash size… Auto-detected Flash size: 1MB Compressed 515872 bytes to 355877… Wrote 515872 bytes (355877 compressed) at 0x00000000 in 31.3 seconds (effective 131.7 kbit/s)… Hash of data verified. Leaving… Hard resetting via RTS pin…
At the end of the upload, Esptool will report 100% completion and say that it is resetting the board. However, it can’t actually reset the board because it doesn’t have any connection to the RESET line. You can press the reset button yourself, or disconnect the Sonoff from the programmer and re-connect it to cycle the power.
The Sonoff will then begin the normal Tasmota setup process, creating a WiFi network and opening a serial connection through the programming header. Follow the usual steps as shown in the Tasmota documentation to set it up, selecting “Sonoff Basic” as the module type.
The T4EU1C should then behave as expected, with control using the touch sensor on the front panel and also via WiFi.
ESP8266 / ESP8285 boot messages
If the ESP8285 didn’t enter bootloader mode properly, the Tasmota upload may have appeared to work in the previous step but the Sonoff still won’t boot. Esptool can show its normal upload progress, ending with the message saying it is 100% complete and resetting the board. But then when you power cycle or reset the board, it never comes online and you can’t tell why.
While booting, the ESP8285 outputs debug information to the programming header at the unusual baud rate of 74880bps. Most serial terminal programs can’t operate at that speed, because it’s not a standard baud rate.
The “CoolTerm” serial console is available for Mac, Linux, and Windows, and can be configured to support 74880bps.
Download and install CoolTerm following the instructions on its site.
After it has been installed, find where the binary is located on your computer. On a Mac, it’s typically inside the “/Applications” directory.
In that same directory, make a text file called “baudrates.ini” and put in the number “74880” without quotes or any other characters. Save the file, then start up CoolTerm.
You should now find 74880bps listed as a supported baud rate in the “Options” menu.
Select 74880 as the baud rate, select the serial port for your programming adapter, and click “OK”:
Click the “Connect” button to open the connection to your Sonoff, and then press the reset button on the Sonoff to force it to reboot.
If the ESP8285 has failed to boot, it will display an error similar to this:
ets Jan 8 2013,rst cause:1, boot mode:(3,0) load 0x40100000, len 27144, room 16 tail 8 chksum 0xef load 0x00000000, len 0, room 0 tail 0 chksum 0xef load 0x00000000, len 0, room 8 tail 0 chksum 0xef csum 0xef csum err ets_main.c
It will then hang, and won’t proceed any further.
If you see this message, there is an error with the program stored in flash memory and you should try following the steps above to flash the Sonoff again.
The new Sonoff Mini DIY and Sonoff S55 are (so far) the best Sonoff devices that ITEAD has made. Flash them with Tasmota, and they get even better.
- View directly on YouTube
- Discuss on the SuperHouse forum
- Discuss on the SuperHouse Discord
- Sonoff Mini: product page | buy online
- Sonoff S55: product page | buy online
- Tasmota firmware
- Tasmota templates site
- Sonoff Programming Adapter
- USB-to-Serial adapter with true 3.3V mode and built-in voltage regulator
- Sonoff Mini Programming Jig on Thingiverse
The original Sonoff Basic didn’t have any provision for an external button or switch. One of the most common hacks is to add a switch, so ITEAD decided to make it easy and put screw terminals right there on the Mini.
The Mini is also the smallest Sonoff model so far, which makes it ideal for retrofitting behind an existing switch. Combined with the screw terminals to connect the switch, the Mini is probably the best general-purpose Sonoff for anyone wanting to retrofit home automation to an existing home.
The S55 is an exterior-rated GPO (General Purpose Outlet) or power point. It allows you to have both local control of the power point using a button, and also control from your home automation system.
Both are nice devices, but they become even better when the amazing Open Source Tasmota firmware is installed on them.
Over the years there have been many methods developed to do OTA (Over The Air) replacement of the existing Sonoff firmware with an alternative such as Tasmota. However, I’ve found that these methods are either frustratingly complex or just stop working because ITEAD change things with new releases. I don’t even bother trying these methods anymore: I just go straight to connecting a USB-to-Serial adapter to the programming pins on the Sonoff’s processor. It can be tricky to get the connections sometimes, but it’s guaranteed to work every time single time.
Warning: Do not attempt to connect a programming adapter to any Sonoff model while mains power is connected. ALWAYS disconnect the Sonoff and power it ONLY through the 3.3V connection.
Install Tasmota on Sonoff Mini
The programming connections for the Sonoff Mini are provided on tiny flat pads on the bottom of the PCB:
The button on the top of the PCB is connected to GPIO0, so if you connect to GND, 3.3V, TX, and RX, you can put the Sonoff Mini into programming mode by holding down the button while connecting power from the programmer.
Unfortunately the pads on the PCB are very small, so soldering jumper wires onto them is tricky. If you have a small soldering iron and good eyesight (or magnification) you can solder wires directly onto the pads.
Just be careful you don’t apply too much heat, because the pads can come away from the PCB!
To get around that problem I used my 3D printer to make a programming jig using a design published on Thingiverse. This programming jig uses “pogo pins”, which are spring-loaded pins that can make temporary connections to a PCB. Pogo pins come in a variety of sizes and shapes. I used P75-B1 pins, which means they have a 0.75mm diameter pin with a simple conical point:
This design has 3 parts: a base that holds 4 pogo pins, a small spacer that slips over the pins to help keep them aligned, and a top that goes over the pins and then provides alignment guides for the Sonoff Mini.
I used super-glue to attach the top to the base, once I’d checked everything was aligned:
The Sonoff Mini can be attached using an elastic band:
The pogo pins push against the pads on the PCB:
Hold down the button on the PCB while plugging in the programming adapter to force the Sonoff to go into programming mode, then you can use Esptool or whatever other method you prefer to load the Tasmota binary. In my case I used Esptool, and the command looked like this:
esptool.py -p /dev/tty.usbmodem141101 write_flash -fm dout 0x0 sonoff-6_6_0.bin
However, this command is specific to the USB port that I used on my computer. You may need to adjust the command to suit your needs. This is all documented well on the Tasmota site.
Because the Sonoff Mini has different pin arrangements to a normal Sonoff Basic, and it’s designed to use a normal switch instead of a button, you need to load a special configuration for it.
After you’ve been through the normal Tasmota setup process and connected it to your WiFi as described in the Tasmota docs, go to the Tasmota templates site at blakadder.github.io/templates/ and search for “Mini”. You’ll find a template that looks like this:
In the Tasmota interface, go to Configuration -> Configure Other and paste the template into the “Template” field.
Make sure the “Activate” check-box is ON, then click “Save”.
Your Sonoff Mini will now operate as expected, with the external switch operating in the normal way.
Install Tasmota on Sonoff S55
The Sonoff S55 doesn’t have a “DIY mode” jumper, so that’s not an option. Luckily, the usual programming header is provided on the PCB ready for you to solder on wires, solder on a header, or just press connections against it. The button for external control is linked to GPIO0, so it’s very easy to put it into programming mode.
The header is in the normal 0.1″ pitch so it’s large enough to solder on a header directly. There’s no need to use a complex pogo pin programming jig.
Solder some hookup wires directly onto the pads, or solder on a header:
I soldered a 4-way 0.1″ header socket onto the pads, with the pins bent a little sideways to make the head sit almost horizontal with the PCB. This makes it easy to plug in a Sonoff Programming Adapter, or use jumper wires to your own USB-to-serial converter.
Hold down the GPIO0 button while you connect the programming header to put it into programming mode, then follow the normal instructions for installing Tasmota. This is very well documented on the Tasmota site.
There’s no specific device profile for the S55 in Tasmota, but it uses the same pinouts as the Sonoff S26 and other mains-plug adapters. Simply select “Sonoff S2x” as the module type in the configuration interface, and it will work as expected.