Introduction: Ozone PDM Timer With Sonoff: Coronavirus Defense

The ozone is great in domestic sanitation, but you must use it with care (see domestic ozone overview). I started some DIY projects about ozone use, this one is about a timer for ozone generators.

Many ozone generators are without PDM (Pulse Duration Modulation) and therefore cannot regu­late the ozone produced in the unit of time. Some inexpensive generators are even without timer. But both PDM and the timer are practically indispensable for the correct use of ozone in domestic sanitation (see ozone diffusion simulation).

Ozone in air purify applications

The timerPDM allows a first control of the ozone produced by PDM (2% .. 100%). Furthermore, in LOOP mode, it allows you to adjust the ON (1min..3h) and the OFF (1min..24h) times separately in 1 minute intervals.

Ozone in chock applications

In AUTO mode, in addition to the PDM control and the setting of the switch-on duration, it is possible to program the start of the ozone generator (hh:mm). In addition, the button on the timerPDM allows the manual start of AUTO mode with an initial delay of 1 minute to move away.

This timerPDM is autonomous, but at the same time compatible with any external standard MQTT clients and brokers: therefore it can be used standalone or remotely con­trolled or even integrated into more complex projects IOT, like smart homes.

All required files and the last complete version of this project can be found here: github-timerPDM


  1. Itead Sonoff S20, Smart Socket Plug Wifi
    (You can also use Sonoff S26 or Sonoff-basic for this project)
  2. FTDI USB to TTL Serial Converter Adapter 3.3V
  3. 4/5 pins for p.c.
  4. Female To Female Jumper Cable Dupont

Step 1: Preparation of Sonoff Switch S20

Remove the S20 card from the container.

Solder a 4/5 pin connector into the Sonoff-S20 pitches

Prepare the 4-wire connection FTDI ↔ Sonoff:

  • FTDIS20
  • VCC → 3.3
  • RX → TX
  • TX → RX
  • GND → GND


  • esptool (,
  • esp_MQTT (

Clean Sonoff flash memory using esptool/write-erase-flash.bat

White Sonoff using esptool/write-esp-Sonoff.bat

Now Sonoff switch can be closed.

You use a laptop with WiFi, and connect the timer: AP "MyAP" (initial default) or "timerPDM" (after configura­tion).

Now use PuTTY, previously installed on the laptop, to connect Sonoff (Telnet, IP:, port: 7777) and give it the commands:

     CMD>set system_output        
     CMD>set speed      
     CMD>set ssid -router_ssid-
     CMD>set password -router_password-
     CMD>set ap_ssid timerPDM
     CMD>set mqtt_host ozonetimer       

You can also use an Android smartphone and the TCP Telnet Terminal app (or other telnet clients):

The "timerPDM02.cde" file is the script used by the timerPDM.

The easiest way to load a script into timerPDM in OTA mode is to use a WEB server.

Using the remote console (telnet: Putty or TCP Telnet Terminal) give the command :

		CMD>script -url_to_script-

After a reset the timerPDM is ready

Step 2: TimerPDM-red: Node-red Client

This app is the most complete, suitable for fixed applications, or for use with portable PCs. Since node-red acts like a WEB server, all devices connected to the network, including smartphones, can use it.

Node-red can be installed on any PC (Win / Linux) and also on Raspberry pi 3 if you want a dedicated low-cost computer (for node-red installation, see

  1. Copy the contents of the node-red/ timerPDM.json file to the clipboard and import it into a new flow in node-red.
  2. Configure access to the timer MQTT broker: -timer_IP-:1883

Step 3: PDM Timer: Android Client

This simple client allows you to control the timer using a WiFi connected Android smartphone. Convenient and above all portable solution, it acts as a remote control, allowing you to activate the ozone generator from a safe area.

For this client, I chose the free IoT MQTT Dashboard because it is rich in inputs and aesthetically pleasing, but there are also other alternatives. You can search Google Play. The important thing is that the application you choose manages JSON payload.

Unfortunately, it is not possible to import a dashboard into IoT MQTT Dashboard from a file: the PDM timer dashboard must be created interactively, following figures. Long but simple, see the app help.