Light Switch + Fan Dimmer in One Board With ESP8266

20,865

129

30

Introduction: Light Switch + Fan Dimmer in One Board With ESP8266

About: I'am an Electronics student that really enjoy making new things from garbage, and DIY projects. I am here to share my knowledge with you, and learn with you too.

In this tutorial you are going to learn how to build your own light switch and fan dimmer in just one board with the microcontroller and WiFi module ESP8266.

This is a great project for IoT.

Cautions:

This circuit handles AC main voltages, so be careful.

Extra: I posted here a video tutorial that shows you the whole process.

Step 1: Video Tutorial!

If you are a visual learner, here you have a complete tutorial of tu set up and build the device.

Step 2: Schematics, Materials and PCB:

Here you have an image of the schematics with the conections and the result of the PCB build by PCBGOGO.

Click HERE for the Gerber file of the PCB design so you can order yours on PCBGOGO.

Materials:

  • 1x ESP8266 (ESP-01)
  • ESP8266 Programmer
  • 7x 1k ohm Resistores 1/4W
  • 4x 470 ohm Resistores 1/2W
  • 2x Triacs BTA16 o BTA24
  • 2x MOC3010 (Opto Triacs)
  • 1x Hi-Link 3.3v power supply
  • 1x Optoacoplador H11AA
  • 2x 33 kohm Resistores 1W
  • 2x Terminal Blocks 2 pin
  • 1x 100 ohm Resistor
  • 3x 100nf 400v Capacitor
  • 2x Push Button

Step 3: Code and Programming:

It's time to program your ESP module and setup everything.

  1. Connect the ESP Programmer to your PC
  2. Connect your ESP8266 to theProgrammer.

Here you can Download the Code and Libraries.

  1. Select the board: Generic ESP8266 Module
  2. Select the right COM port.
  3. Fill the Blanks (Ubidots TOKEN, WiFi SSID, WiFI PASS).
  4. Click on Upload button.
  5. You should be ready to test.

Step 4: Ubidots Settings:

First of all we need an Ubidots account, Click Here to create yours for free.

  1. Create a Device called dimmer.
  2. Create two variables bombillo and ventilador.
  3. Click on Data and create a new Dashboard called as you want.
  4. Add two widgets a button and slider associated to the device and variable.
  5. Resize your widgets and that's it.

Step 5: IFTTT Setup

  1. Create an IFTTT.com account.
  2. Click on Get more and then click on +.
  3. Click on IF+ and search for Google Assistant.
  4. Click on Say a simple phrase / number.
  5. Define your phrase and response.
  6. Click on That+ and search for WebHooks.
  7. Fill the blanks:

URL: http://industrial.api.ubidots.com/api/v1.6/device...

Method: POST

Content Type: application/json

Body: {"ventilador":0} // Repeat for Off, and the Fan speed.

8. Finish

Step 6: Hardware Setup:

Define the Terminal block terminals, Line, Neutral, Bulb and Vent. (L,N,B,V)

  • Break out the current supply. (For security)
  • Connect every wire on it place.
  • Put everything into the metal box.
  • The Blue button is the Light on and off button.
  • The Red button is Reset.

Step 7: Testing It.

After everything is in place correctly, turn on the supply of your house and test.

Just need to say "Ok, Google" and the statements you had stablished and ready, or just go to Ubidots App on your phone or PC and swipe the slider and push the button.

Be the First to Share

    Recommendations

    • Make it Glow Contest

      Make it Glow Contest
    • First Time Author Contest

      First Time Author Contest
    • PCB Challenge

      PCB Challenge

    30 Discussions

    0
    rashed3e47
    rashed3e47

    Question 4 weeks ago

    Hi there. Is it possible to write code for making1 Light Switch and fan dimmer by both 3 Manual push buttons (one button is for light ON/OFF and another two buttons are for Fan speed controlling (increasing and decreasing)) and also Blunk app on/off button for light and slider button for fan speed controlling . Board is NodeMCU. If so please write and share the code or give suggestion/guidance how to writing the code for that two push buttons for fan speed controlling and relate with zero cross detection function along with blynk app'a slider

    0
    rashed3e47
    rashed3e47

    5 weeks ago

    Thanks for your exceptional Project , patience and the hard working behind all of these. Is it possible to make the AC Dimmer which runs both Blynk app by using slider button (or "+ve" & "-VE" buttons) and two physical touch sensor switches (say 4 pcs TTP223 or 1 PCS TTP 224 for controlling 4 steps ...etc. ) for manual Control (Increasing or decreasing the bulb intensity or fan speed ) , If so please make a video particularly in coding part, It is difficult to relating the physical two buttons with Blink slider in coding part.
    Show less

    0
    Melandr_a
    Melandr_a

    2 months ago

    Good afternoon! I am trying to repeat your scheme with minor changes. And there was a problem at the stage of switching on the ESP-01. This problem is due to the fact that the GPIO0 pin is connected to a "0" crossover detector, which pulls up to 3.3V when crossing a "0". The rest of the time, the GPIO0 pin will be low. And for the normal start of ESP-01, it is necessary to provide a high voltage level at the GPIO0 pin.

    0
    mcmchris
    mcmchris

    Reply 2 months ago

    Hi! As you can see in the diagram, both dim and cero pins are pulled up to vcc so GPIO should be in the right state while booting, I needed to reset the board some times until it boot correctly because the LED of the optocoupler on those pins are giving a sense of 0 on those pins.

    0
    Melandr_a
    Melandr_a

    Reply 2 months ago

    Good evening! Indeed, GPIO0 and GPIO2 are pulled to + 3.3V through 1k resistors. But detector 0 will hold a high level on the GPIO0 pin only at the moment the sinusoid passes through 0, and the rest of the time on the pin will be low. Or I'm wrong?

    0
    SUDHIRHINGE
    SUDHIRHINGE

    Question 8 months ago

    getting corrupt file when try to open / unzip.

    0
    mcmchris
    mcmchris

    Answer 8 months ago

    Try using WinRar to unzip.

    0
    discostu956
    discostu956

    1 year ago

    Do you mind explaining what the ubidots and iftt sections are actually for? I'm assuming it's to control the device, but I'm not familiar with these types of things and only guessing

    0
    mcmchris
    mcmchris

    Reply 1 year ago

    Ubidots is the IoT platform that let you control your project by internet wherever you are, and IFTTT is an interface beetwen Google Assistant and the project.

    0
    discostu956
    discostu956

    Reply 1 year ago

    Cheers

    0
    mcmchris
    mcmchris

    Reply 1 year ago

    Yes, Ubidots it's the IoT platform to control your switch and dimmer through the internet. And the ifttt is to pair the Google Assistant with the device.

    0
    discostu956
    discostu956

    Reply 1 year ago

    Thanks

    0
    acmenw
    acmenw

    Question 1 year ago

    What is the value of R8?

    0
    mcmchris
    mcmchris

    Reply 1 year ago

    R8 is not needed for this design.

    0
    mcmchris
    mcmchris

    Answer 1 year ago

    Do not use R8. Let this place empty in the circuit because this resistor is duplicated by mistake.

    1
    AnkurP12
    AnkurP12

    Question 1 year ago on Introduction

    Does the fan make a humming sound at low speeds, normally observed while using triacs

    0
    mcmchris
    mcmchris

    Answer 1 year ago

    Yes, it does. Do you know how to reduce it or fix it?

    1
    ShashwatN
    ShashwatN

    Reply 1 year ago

    You will have to implement a snubber circuit to take care of the humming.

    0
    mcmchris
    mcmchris

    Reply 1 year ago

    It has it Snubber Circuit, check out the Schematic.

    0
    mcmchris
    mcmchris

    Reply 1 year ago

    Yes, the diagram has it snubber circuit!