AC Dimmer for Lighting and Motors W/ Raspberry Pi + Home Assistant + ESP8266

by mcmchris in Circuits > Raspberry Pi

1995 Views, 1 Favorites, 0 Comments

AC Dimmer for Lighting and Motors W/ Raspberry Pi + Home Assistant + ESP8266

IMG_20210619_113439.jpg

Hello to everyone, today I am here to show you a very interesting application of your Raspberry Pi for Home Automation, we could be used to bare metal coding for our IoT solutions in ESP8266 and ESP32 but today you are going to learn how to take your development to the next level with your own server, offline and online control capabilities and more with the use of Home Assistant Raspberry Pi OS and ESPHome.

We will be giving life to an old project, a AC Dimmer, lighting and motors controller. (8 Amps max, and 120vAC)

I've made a lot of projects with the ESP8266 and ESP32 programmed by the Arduino IDE, and all of this projects can be recreated with just few lines of "code" in the approached system.

Here I leave you a tutorial with all the information so you can make your own version. If you are a visual learner I know that a video worth more than 1000 words, so here is a Tutorial video. (I am a Spanish speaker, so please consider turning on English subtitles):

Skills Required

Captura de pantalla (573).png
Captura de pantalla (563).png

This project may seem difficult or very complex, but it is definitely not completely, since you will have all the guidance for the construction, it was difficult for me to design it to make life a little easier for you. Any conceptual doubt, you are free to ask it without problems.

  • Power electronics knowledge.
  • Programming (a bit).
  • Linux systems experience (a bit).

Components and Parts List

Captura de pantalla (549).png

The Electronics discrete components as resistors and transistors will be attached in a BOM file in the PCB Step.

  • Here is the list of what you will need for the whole process:
  • -10kohm Potentiometer.
  • -2 Double Terminal blocks.
  • -AC motor of your preference (single phase).
  • -Dimmable Lightbulb.
  • -Small 5 volts cellphone power supply.
  • -Measuring tools: multimeters, clamp meters (optional).
  • -Micro USB SMD connector.
  • -1.3 inch OLED Display.
  • Wire.
  • Housing STL.
  • Cover STL.
  • Button cap STL.

BOM list of PCB components attached.

Great, cheap and awesome Graphical Multimeter to watch the Sinusoidal AC wave form

Circuit Diagram

Schematic_AC-Driver_2021-06-25.png

Here is the Circuit Diagram of our project:

It has all the internal conections of the circuit that will us allow to create the PCB design later.

I also attached the PDF of the Schematics so you can see it better.

PCB Design and Ordering

F1R3UVUKM965UAP.png
FQUMEE5KM965UAN.png
FM95M2PKM965UD5.png

For the implementation of a good project we need a reliable assembly for the circuit that makes it up, and there is no better way to do it than with a good PCB.

Here you can download the Gerber, BOM and Pick & Place Files, the ones you need to order your PCB on your PCB manufacturing company.

I suggest JLCPCB:

$2 for 1-4 Layer PCBs⚡, Get SMT Coupons🎫

UnZip the .rar file with a software like WinRar or any other.

Setting Up Your Home Assistant

Captura de pantalla (552).png
Captura de pantalla (553).png
Captura de pantalla (554).png
Captura de pantalla (555).png
Captura de pantalla (556).png
Captura de pantalla (557).png
Captura de pantalla (558).png
Captura de pantalla (559).png
Captura de pantalla (560).png

As I explained in one of my previous Instructables, you need to download, flash and run your Raspberry Pi OS (Home Assistant): https://www.instructables.com/How-to-Start-on-Rasp...

Once you have done the initial setup, follow the instructions:

  1. Go to: homeassistant.local:8123 (you should be able to see your dashboard).
  2. Click on your EspHome tab.
  3. Click on the (+) button to create a new node.
  4. Name your node with a lowercase word. ("dimmer" in my case).
  5. Select your board (NodeMCU in my case).
  6. Add your WiFi credentials.
  7. Click on submit.

Once your node is done, click on edit and you should be able to see the initial configuration with all you've set before.

Dimmer Code

Captura de pantalla (561).png
Captura de pantalla (562).png
Captura de pantalla (564).png

Go to ESPhome AC dimmer exampleESPhome AC dimmer example and follow the steps:

  1. Copy the example entry code.
  2. Paste it bellow the Node code as shown.
  3. Looking the circuit diagram modify the Triac Pin and the Zero cross prin. (12,14).
  4. Modify the device name as you want. ("Luz Dimmeable" in my case).
  5. Click save.

Wiring Up

Captura de pantalla (571).png
Captura de pantalla (572).png
Captura de pantalla (565).png
Captura de pantalla (566).png

  1. Connect the lightbulb or load to the right connector.
  2. Connect the AC source cable to a 120v AC outlet.
  3. Connect the Raspberry to the project PCB through the USB cable.
  4. You are ready.

We are working with main voltages, please be carefull.

Uploading the Program and Flash

Captura de pantalla (567).png
Captura de pantalla (569).png
Captura de pantalla (570).png

Once you connect the board, it will show you a new serial port detected.

  1. Select it.
  2. Click on Upload button in your node.
  3. A kind of prompt will appear with the process of uploading, it can take several seconds, it will install the libraries and dependencies.
  4. Wait until you get the board log of WiFi scan, connection and stuffs like you see in the last picture.
  5. Once you have the code uploaded, you can close this window.

Integration Setup

Captura de pantalla (574).png
Captura de pantalla (575).png
Captura de pantalla (576).png
Captura de pantalla (577).png
Captura de pantalla (578).png
Captura de pantalla (579).png
Captura de pantalla (580).png
Captura de pantalla (581).png

  1. Once the color of your node turn to green it means that you can disconnect the dimmer project from the usb of the Rasp and power it up independently and it will be recognized.
  2. Go to Configuration (left bar).
  3. Go to Integrations and click in the new one that appears called "dimmer".
  4. Select the Area you have it installed it (bedroom in my case).
  5. Go to your dashboard and click on "control panel edit" then add widget. (añadir tarjeta).
  6. It should appear a dimmer widget with a lightbulb symbol and a dial, select it and place it in your dashboard.
  7. Try it.

Testing the Project (Enjoy)

Captura de pantalla (588).png
Captura de pantalla (587).png
Captura de pantalla (586).png
Captura de pantalla (585).png
Captura de pantalla (584).png
Captura de pantalla (589).png

As you can see, now you are able to control your dimmable light as you want from a local network or from anywhere if you enables the DNS of Home Assistant.

As you can see in the multimeter the waveform is trimmed accordingly to the dial position giving a brightness feedback and obviusly we can evidence it in the shine of the actual bulb.

This can be applied to control AC motors, heaters, lighting (could be LED dimmable lights also) and every load you understand can handle this kind of waveform.

Pd: I've tried this with ceiling fans and it works very well.