Wednesday, 30 May 2018

Using the CH340 USB dongle as ESP-01S Programmer

Note the add-on push-button switch

Some time ago I bought a cheap (RM6.50) CH340-based USB to serial 3V3 TTL dongle with a socket for the ESP-01S. It was described as a development board, and I assumed it will also program the ESP-01.

That assumption turned out to be quite unwise, as 'programming' was not mentioned:

It most certainly would not program an ESP-01S. What is needed was a switch to pull GPIO0 low when the ESP-01S is powered up or reset. AndyS19 has a nice writeup on this.

ESP-01S pinout

I happened to have a cheap (RM0.80) small push-button switch very popular here for use in car, autogate or garage remotes. The distance between the leads (ie pitch) almost exactly fits the pins GPIO0 and GND of the CH340 ESP-01S USB dongle, on the solder-side of the PCB.

Push-button switch for remotes

Solder-side of the CH340 ESP-01S adapter

I simply glued the switch to the PCB and soldered the leads onto the GND and GPIO0 header pins, and presto, I have an ESP-01S programmer.

To program, hold down the button as you insert the dongle in your laptop. Release the button and fire up your Arduino sketch. Use the 'ESP8266 Generic' setting. Some ESP-01S I bought would only work with 9600 baud, others are fine with 115200.

It will be especially handy to have an ESP8266 board to run my code on those train rides on my daily commute.

Life is good. Happy Trails.

Tuesday, 8 May 2018

IoT Porch Light using ESP8266 and Arduino Relay PCB

WiFi control of Porch :Light
Warning: this project contains live mains voltages that can be lethal. There can be a fire risk especially if you use generic no-name China parts like I have. Do not use generic parts unless you first test them under load and disassemble them. Some generic parts are under-specified and can be hazardous. Do not mount the lamp on flammable surfaces like wood or plastic.

Following related posts on ESP-01S, the ESP-12E Arduino sketch, this post shows the final assembly of the light panel and the 5V power supply.

The light panel is a generic "Surface LED Down Light Panel Lamp" from cpeelectrical which I bought for RM43, mainly because there is room inside the enclosure to mount the ESP-1S and relay PCB.

Top: ESP-01S with relay module. Middle: 230Vac to 5Vdc power supply. Bottom: 18W LED Driver

For the ESP-01S power supply I used an old smartphone charger. It was marked as 'output 5.7V 800mA' but when used I measured 5.05V which is just as well as the ESP-01S only takes 5V. It is too large to be mounted inside the lamp, so I removed the PCB and mounted it without its enclosure.

Old Android smartphone charger, disassembled. Note the lack of a controller IC
The power supply was extremely simple: all the components were discrete devices (ie no IC) and just an oscillator at the primary side, and a single rectifier diodes at the primary and secondary. Still, it had been used for some 3 years sealed in its plastic enclosure with no ventilation holes and should be reliable enough for this purpose.

5V Charger tested on ESP-01S
If you do not have an old charger, you can buy them here in Malaysia for RM6 or more. It is better to buy branded chargers like Samsung, as generic chargers have been known to catch fire.

The ESP-01S drew 170mA during WiFi access, and 60mA more when operating the relay. In practice it drew somewhat more than 230mA on power up so that 800mA at 5V came in handy. For easy installation I had the relay come on on power up. This also acts as a manual override 'ON' from the light AC mains power switch. 

The final part, the LED Driver came with the lamp. It took in 85-230Vac (any lower and it shuts down) and puts out a stonking 60Vdc at no load, but settled down to 50Vdc at 330mA when the lamp is turned on. 

LED driver 18W 230V

Now the relay can be wired up to switch the DC or AC side of the LED driver. I opted to switch the AC side- hopefully it saves a little power as the primary side will not be always on.

LED Driver. Note the IC controller on the primary side
For enclosures for the ESP-01S and the mains 5V power, I used the casings from 20W LED drivers. The entire LED driver costs only RM6 each and I had a couple of faulty ones left over from other LED lamps. You must enclose them: all 3 boards have 230V mains voltages that must be insulated. Here in Malaysia insects get into electrical fittings, especially light fittings including bulbs.

There you have it: an IoT lamp, switched from your smartphone or desktop browser. Happy Trails.