ESP8266 01 Light Dimmer

ESP8266 01 Light Dimmer

Note: Although I do have some useful things here, I never did get around to assembling a dimmer using the mini-version of this board. School came around and other hobbies took my interest away, but I plan to revisit this in the near future!
CAUTION! This project works with mains voltage! This can be lethal, so do not attempt unless you are familiar with the necessary safety precautions and understand the risk!

I purchased some of these little wifi enabled microcontrollers some time back, but until recently haven't known what to do with them. While working on my e-bike and spot welder, I had the thought of making the ebike controller wifi enabled. This got me started on making some test projects to learn with. The goal here is to use to cheapest variation of the esp8266 and still accomplish a reasonably complex task without needing to purchase I2C add on boards. Now, on to the details on how to do this project and what you'll need.

Parts for this project

  • A dimmable light and socket
  • Triac (I used a BTA08)
  • Driver IC (moc3023 or similar)
  • AC optocoupler or DC optocoupler with diodes (H11AA1 or generic)
  • (Optional) Breadboard and jumper wires
  • Appropriate tools (soldering iron, solder, wire cutter)
  • ESP8266 variant, we'll use the 8266 01 for its small size
  • FTDI serial adapter (if using the 8266 01 or an arduino pro mini)
  • AC-DC supply (may need a regulator depending on what you have available)
  • A variety of resistors

A neat trick for the tiny board

This little block of code here will be used to repurpose our TX and RX pins since GPIO 0 and 2 are required to stay high during boot. The problem with the pins being high at boot has to do with the fact that one is supposed to take an input from the zero cross detection circuit, and the other needs to use a high signal to trigger the lights, that way in case of an error with the board or the power supply, our lights or other load (like a motor) aren't stuck on.

//GPIO 1 (TX) swap the pin to a GPIO.
pinMode(1, FUNCTION_3); 
//GPIO 3 (RX) swap the pin to a GPIO.
pinMode(3, FUNCTION_3);

By doing this, we keep our design safer and only lose functionality which wouldn't be used here anyway. If your use case does require TX and RX functionality, it can be done, but may require additional boot attempts if it happen to boot at time of zero crossing, it will briefly pulse the output on at boot, and will be stuck on if it fails.