AC Dimming and AC Motor Speed Control How To with Arduino/NodeMCU

Поділитися
Вставка
  • Опубліковано 27 чер 2024
  • Video sponsored by PCBWay. Visit PCBWay and get $5 off from your first order:
    www.pcbway.com/setinvite.aspx...
    Controlling AC appliances with Arduino always comes with a challenge and when tr requirement is to control the speed of an AC motor or dim an AC light, the challenge is even greater.
    In this video, I'm going through the basics of achieving such AC control with the help of a triac and connecting a dimming module to an Arduino or NodeMCU board.
    For written instructions, code, and more details be sure to check the Instructable article for the project:
    www.instructables.com/AC-Dimm...
    The Arduino library can be found here:
    github.com/RobotDynOfficial/R...
    Tools and materials used in the video:
    AC Dimmer Module - s.click.aliexpress.com/e/_A3CeHP
    NodeMCU - s.click.aliexpress.com/e/_9vHJU1
    Aligator clip cables - s.click.aliexpress.com/e/_9gDLId
    Dupont jumper wires - s.click.aliexpress.com/e/_AqmYwh
    Mini breadboard - s.click.aliexpress.com/e/_Adyhxn
    AC Fan - s.click.aliexpress.com/e/_AmI0P7
    Alternative links on Banggood:
    WiFI Triac Dimmer - www.banggood.com/custlink/3D3...
    NodeMCU - www.banggood.com/custlink/DGv...
    Aligator clip cables - www.banggood.com/custlink/m33...
    Dupont jumper wires - www.banggood.com/custlink/KG3...
    Mini breadboard - s.click.aliexpress.com/e/_ol4...
    AC Fan - www.banggood.com/custlink/DGG...
    Support my work on Patreon so I can continue producing free content and tutorials!
    / taste_the_code
    My recording gear:
    GT10 Pro 5G Android Phone - s.click.aliexpress.com/e/_oDn...
    Dragon Touch 4K Action Camera - s.click.aliexpress.com/e/_mrc...
    USB Condenser Microphone - s.click.aliexpress.com/e/_mq5...
    Tripod - s.click.aliexpress.com/e/_ooa...
    Phone tripod mount - s.click.aliexpress.com/e/_s9WaiJ
    AC Dimming and AC Motor Speed Control How To with Arduino/NodeMCU
    #ACdimming #triac #Arduino #NodeMCU #tastethecode
    Main Site and blog: www.tastethecode.com
    Facebook: / tastethecode
    Instagram: / taste_the_code
    Twitter: / taste_the_code
    Get exclusive Taste The Code t-shirts and merch at
    teespring.com/taste-the-code
    Click on the link below to get two months of free premium access to Skillshare and start learning today!
    skl.sh/37LnRua
    Get $50 off your order on hosting for all of your website needs and learning projects on Dreamhost!
    www.dreamhost.com/r.cgi?24057...
  • Наука та технологія

КОМЕНТАРІ • 110

  • @ffwATL
    @ffwATL Рік тому +1

    I was able to implement the same on nrf52832 based on this example. It wasn't as easy as I expected, but using pwm + ppi did the trick. Thank you!

  • @TakamiWoodshop
    @TakamiWoodshop 3 роки тому +1

    I like it Bill, I had no idea you could do that with arduino! Playing around with 240v would scare the crap out of me though.

  • @chimpofm
    @chimpofm 2 роки тому +1

    My dude!! This is what ive been looking for. Can you do a video on how to add pid temp control of the ac fan controler. Outputting the temp value via iot user interface like blynk.

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      Thanks! That's an interesting request. I'll add the idea to my list.

    • @chimpofm
      @chimpofm 2 роки тому

      @@TasteTheCode thanks buddy. The cheapest pid fan controller is the smscom at 50 bux. Thats without iot. I hope this makes it to a video. It would help me and my gardening budys out loads to be able to control fan speed based on temperature. Plus it would compliment our iot aquarium monitor we have just made. Coughs * hydroponics *

  • @ocean8649
    @ocean8649 2 роки тому +2

    Hi, I am currently working on a project similar to this, this video is very helpful. I do have a question, are the two loads connected in parallel?

    • @TasteTheCode
      @TasteTheCode  2 роки тому +1

      Yes, both the fan and the light bulb are connected in parallel.

    • @ocean8649
      @ocean8649 2 роки тому

      @@TasteTheCode thank you for the reply

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      @@ocean8649 You are welcomed!

  • @zyghom
    @zyghom 3 роки тому

    that is exactly the project I am working on now! Perfect. But how to do it with Raspberry?
    I think this should be fairly similar: zero detection: any pin with interrupts, then control over standard PWM, right?

    • @TasteTheCode
      @TasteTheCode  3 роки тому +1

      Yes you are.correct!

    • @zyghom
      @zyghom 3 роки тому

      @@TasteTheCode Thank you ;-) I am going to change 20 GBP fan for "200 GBP Wahoo fan" with 1 pico and 1 module from Ali (2 GBP) - lets see if it works ;-)

  • @zzzzzzz1729
    @zzzzzzz1729 2 роки тому

    Hi Bill, can we use arudino nano, if yes what is the interrupt pin we have to use?

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      Yes, you can. There are two interrupt pins on the Nano, pins 2 and 3.

  • @mrgcav
    @mrgcav 2 місяці тому

    In the USA we use 120VAC and I have a large 2.0HP (about 10amps) Inductive AC motor I need to control the the speed of on a table saw. I like you setup. Problem with Triacs is Idle current. So when your circuit is "OFF" how much power is it still drawing ?
    If I am Drawing 10 amps then would I not need a much bigger heatsink for the Triac ?
    Would you still use an Arduino node MCU if you did this again ?

    • @TasteTheCode
      @TasteTheCode  2 місяці тому

      You will need a dimmer that is rated for the load you are applying. However, large inductive loads are now a good thing to regulate with this method. In terms of the NodeMCU, sure, it does the job but you can also go with ESP32 nowadays.

  • @SJman-ch3dj
    @SJman-ch3dj Рік тому

    I'm curious where you got the schematic for the module?

    • @TasteTheCode
      @TasteTheCode  Рік тому

      To be honest, I don't really remember... Basically, it just follows the standard example circuit for an AC dimmer.

  • @Aisi555
    @Aisi555 7 місяців тому +1

    For you who have flickering problem, try to add snubber R-C 100ohm - 10nF across the triacs MT terminal. The triacs available on the market are cheap crap or fake one. BTA16 will couse headache. Try using triacs from old power electronics and its all smooth dimming. Chinese semiconductor sucks...

    • @TasteTheCode
      @TasteTheCode  7 місяців тому

      Hey, thanks for the added info. I did not had issues with mine but this is nice to know.

  • @MixwellSidechains
    @MixwellSidechains 6 місяців тому +1

    Can I connect more multiple module's zero-crossings pin to the same pin (e.g. pin 2) of the microcontroller or do I have to have a interrupt pin for each as I would the PWM signal pin?
    Isn't it the PWM signal pin that controls the triac? Why would I need an interrupt to do so?

    • @TasteTheCode
      @TasteTheCode  6 місяців тому +2

      No, you will need an interrupt for each. It is needed because we need to know when at the sine wave signal to turn on the triac. This is AC so it works much differently to PWM in DC. The interrupt is there for the precise timing as otherwise the microcontroller will miss the right moment to turn on the triac.

  • @BenBilesBB-box
    @BenBilesBB-box Рік тому

    going to try this with 2 modules and an esp32. hopefully the interrupts stay high long enough for that.

    • @TasteTheCode
      @TasteTheCode  Рік тому +1

      Yep, that should work just fine. I tried it once with an Attiny85 once and it was still working OK.

    • @BenBilesBB-box
      @BenBilesBB-box Рік тому

      @@TasteTheCode nice to know! I ordered 2 already. I'm making a 3d printer enclosure and I want to regulate the internal temp of the case with the 110v extractor fan and I'm thinking of powering the actual printer with another module so I can shut the printer off if the thermistors detect unusual high temps etc. maybe even hook up a smoke detector in there to

    • @TasteTheCode
      @TasteTheCode  Рік тому +1

      @@BenBilesBB-box Sounds like an interesting project 😀 If you need simple on/off, maybe a solid state relay is better for turning off the printer?

    • @BenBilesBB-box
      @BenBilesBB-box Рік тому +1

      @@TasteTheCode thanks, great idea. I just found the same company sell an SSR with opto isolation and 3.3v - 12v logic for a few bucks. I can have 2 variable speed fans and power shut down for the printer now with SSR.

  • @pwn20wnd56
    @pwn20wnd56 Рік тому

    Can we determine the output AC voltage as we want? For example I want the output to be 175V AC

    • @TasteTheCode
      @TasteTheCode  Рік тому

      There is no real feedback about what the output voltage is but you can I guess ise math ro calculate it or use voltage sensor to read it and feed it back to the Arduino.

  • @danieldbird
    @danieldbird Рік тому

    Great video. Will this work with ESP32?

    • @danieldbird
      @danieldbird Рік тому +1

      Also does this work the same as Shelly Dimmer 2?

    • @TasteTheCode
      @TasteTheCode  Рік тому +1

      @@danieldbird I'm not familiar with the Shelly dimmers but it should work exactly the same with ESP32

    • @danieldbird
      @danieldbird Рік тому +1

      Thanks!

  • @mareksendecki5695
    @mareksendecki5695 2 роки тому

    Im using this module and SUNON DP203A AC FAN and it's acting strange. Bulb works fine but the fan is just buzzing when at 50%. At 70% it works fine but slower than 70% and at 99% it's buzzing and moving at a speed of 1 maybe 2 RPM. Any idea why? I dont have an oscilope to monitor the output wich i suppose may be useful. Thanks for the video :)

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      I wonder if there's some noise on the zero crossing signal. I had some weird behavior as well but only on very low speeds where I guess the motor was not able to spin they slow. Try the motor and the bulb in parallel, maybe the motor inductance messes with the module in some way. Let me know the results, I'm interested in what's going on.

  • @Ram-bf7xq
    @Ram-bf7xq Рік тому

    Sir plz make it with EEPROM

    • @TasteTheCode
      @TasteTheCode  Рік тому

      You can check my other video on how to add EEPROM data retrieval and saving ua-cam.com/video/iE91SuZSsFQ/v-deo.html

  • @SurajKumar-xt4ur
    @SurajKumar-xt4ur Рік тому

    hi. is this circuit frequency control or voltage regulator?

    • @TasteTheCode
      @TasteTheCode  Рік тому

      Neither, this cuts the current flow at each zero crossing point in the input sinewave.

  • @TheEdevat
    @TheEdevat 5 місяців тому

    Your content is great! Inspired by this, I started creating a circuit that simulates sunrise and sunset for a chicken farm. I am trying to dim 15 different lamps with a single dimmer module. Everything is fine up to 2 lamps, when there are 3 or more lamps, I constantly get 220v output, dimming does not work. I couldn't understand what I did wrong, can you help me?

    • @TasteTheCode
      @TasteTheCode  5 місяців тому

      Thanks for the great words! For the dimmer, what is the actual rating of it? The dimmer must be rated to handle the attached load so I'm guessing that yours is not and it fails ro handle the dimming properly.

    • @TheEdevat
      @TheEdevat 5 місяців тому

      @@TasteTheCode First of all, thank you for your quick response. I'm not sure what actual rating means, I'm sorry, my electronic knowledge is limited. But I can give more information about my circuit. I am using Robotdyn AC dimmer module, this module has bta16-600 Triac on it. The bulbs I use are dimmable 9w LED bulbs, 15 in total. I measure 0.3 amps when all bulbs turn on at the same time. The mains voltage where I am is 230V 50 Hz. Finally, I use the module on a nodemcu and the library I use is dimmable_light.h

  • @peastfist1602
    @peastfist1602 Рік тому

    Do you know on how to control 5V fan speed using raspberry Pico ?

    • @TasteTheCode
      @TasteTheCode  Рік тому

      For DC loads like that fan, you new PWM signal from the Pico to turn on a MOSFET as the fan draws more current than what the Pico can provide.

  • @zipcee5715
    @zipcee5715 8 місяців тому

    sir what if i only connect live wire to dimmer and the gnd to the load
    does it will work fine or not

    • @TasteTheCode
      @TasteTheCode  8 місяців тому

      Any other connection except the one shown will not work. You need both wires in both places.

  • @user-vt9lm6fm3s
    @user-vt9lm6fm3s Рік тому

    Has anyone gotten this sample (SerialMonitorDim) to run on an Arduino Nano? If so what pins did you hook the dimmer module to, and what tweaks were needed to the code? I tried D2 for the Z-C interrupt and D5 (defined as pin 8) for PSM, but no joy. What am I doing wrong? Thanks!

    • @user-vt9lm6fm3s
      @user-vt9lm6fm3s Рік тому

      So to answer my own question, for Arduino Nano outputPin should be #defined as PD5.
      What threw me at first was that for some still unknown reason (at least with my dimmable LED bulbs) many power level settings (particularly but not solely those >=95 or

    • @TasteTheCode
      @TasteTheCode  Рік тому

      @@user-vt9lm6fm3s Some of the low power settings know to be unstable because things are happening too fast I guess so the circuit can't keep up. I've also seen flickering with values

  • @thewaveringwarrior
    @thewaveringwarrior Рік тому

    Could let us see the code which makes it work with a Potentiometer instead of using the keyboard. I guess you connect the pot to the ADC input pin?

    • @TasteTheCode
      @TasteTheCode  Рік тому

      Yes exactly. The read value needs to be mapped in a range of 0 to 100 and can be used to drive the dimmer.

  • @vincekeanneta-aca4340
    @vincekeanneta-aca4340 Рік тому

    It it possible to add dht11 sensor to makeit temperature base ?

    • @TasteTheCode
      @TasteTheCode  Рік тому

      You mean to measure the temperature of the lamp? Sure it can. Based on that you can then vary the duty cycle through the microcontroller.

    • @yolo9036
      @yolo9036 10 місяців тому

      Hello, we have same to add dht11, can i see your source code for this? Cuz i have to compile the value dont get it

  • @cicciosonyalfa
    @cicciosonyalfa Рік тому

    Hi, I have to control 4 lights at the same time with 4 different boards, did you use the command: dimmer.setPower(val) to control one output, to control multiple outputs which command should you use?

    • @TasteTheCode
      @TasteTheCode  Рік тому

      For multiple dimmers, you will need to define multiple dimmerLight objects like dimmer1, dimmer2, etc., and then set the brightness on each of them. If they are running from the same AC phase, I think you might get away with using just one zero-crossing signal, but otherwise, you will need a board with multiple interrupt pins like ESP32 in order to control all of them.

    • @cicciosonyalfa
      @cicciosonyalfa Рік тому

      @@TasteTheCode Use the same phase. Could you give me an example with the code, in the library examples I didn't find anything

    • @TasteTheCode
      @TasteTheCode  Рік тому

      @@cicciosonyalfa You need to create different objects for each of the dimmers like this dimmerLamp dimmer(outputPin);, dimmerLamp dimmer1(outputPin1);, dimmerLamp dimmer2(outputPin2); etc. where each dimmer has its own pin that it is connected to. Later you will need to set the values of all of them like this: dimmer.setPower(outVal);, dimmer1.setPower(outVal);, dimmer2.setPower(outVal);, etc. I have not tried this and it might have an issue with all of them using the same interrupt pin but you can give it a go. If this does not work, then all initialization will need to be done with the second constructor where a different interrupt pin is passed for each. dimmerLamp dimmer(outputPin, zerocross);

    • @cicciosonyalfa
      @cicciosonyalfa Рік тому

      @@TasteTheCode Thanks, as soon as I get the 4-light card I'll try and let you know

    • @cicciosonyalfa
      @cicciosonyalfa Рік тому

      @@TasteTheCode The boards arrived, I started programming a board and it works well, if I add the definitions of the other 3 dimmers, (dimmer 1, dimmer 2, dimmer3) the lamp flickers, goes off halfway through the cycle, then goes back on. If I remove the 3 definitions, the lamp, as if by magic, starts working well. Does that mean this library can only work with a lamp?

  • @manumohan1928
    @manumohan1928 2 роки тому

    can we use 2hp ac motor with this Dimmer Module. pls reply

    • @TasteTheCode
      @TasteTheCode  2 роки тому +1

      The 2hp is around 1.5kW? That is what Google told me so if that is true, the current draw of that motor on 220V will be about 13A. The module is only rated for 8A so the answer is no. The maximum I would use this for is around 600W. You need a module that can handle a lot more current but the setup will be the same.

    • @manumohan1928
      @manumohan1928 2 роки тому

      @@TasteTheCode thanks for your reply

  • @yogabharath1711
    @yogabharath1711 Рік тому

    why this lib not work in rp2040 any other alternative src here

    • @TasteTheCode
      @TasteTheCode  Рік тому +1

      Sorry but I haven't worked with RP2040 yet so I can't get this info for you.

  • @faturahmanf3024
    @faturahmanf3024 2 роки тому

    Hello , does an intterrupt pin affect the zerocross off the dimmer, i found trouble that when i use the dimmer and use any interrupt pin i found error in the compiler

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      Yes, an interrupt pin is required to get proper timing on the zero crossing signal. If you need multiple interrupts, then you must use a board that supports them and define different routines for each.

    • @faturahmanf3024
      @faturahmanf3024 2 роки тому

      @@TasteTheCode what board do you suggest?, Can it use arduino mega??

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      @@faturahmanf3024 each board has different specs, Mega has pins 2, 3, 18, 19, 20, 21 (pins 20 & 21 are not available to use for interrupts while they are used for I2C communication) defined as interrupts. On ESP32 all GPIOs can be configured as interrupts.

    • @faturahmanf3024
      @faturahmanf3024 2 роки тому

      @@TasteTheCode so in arduino mega i can use each of this pins to use interrupt pin for any different function including use it as zero cross for the dimmer, is that right?
      Currently in my board using arduino uno i cannot compile the program of rbd dimmer if i use one of the interrupts pin on it, so in my board i use pin 2 for zero cross and i use pin 3 for the interrupts pin for the encoder, but the arduino ide cannot compile it, a cannot use it at the same time. i have to use one of it so the compiler not error, so if i use dimmer i cannot use my encoder, then if i use my encoder i cannot use my dimmer, if you give me some help i will be very appreciate it, currently i working on my final project for my college

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      @@faturahmanf3024 hmmm I'm not sure what might be causing that. You should be able to use both interrupts at the same time as long as they have separate handling routines. Try searching for the exact error message you are getting and resolve it that way.

  • @jameswainaina4480
    @jameswainaina4480 2 роки тому

    I want to develop a similar project

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      Awesome! Feel free to use this one as a base.

  • @pritambakshi6936
    @pritambakshi6936 5 місяців тому

    Can you metion your Arduino IDE, Esp8266 board manager and RBDDimmer library version.?

    • @TasteTheCode
      @TasteTheCode  5 місяців тому

      I don't recall what versions I used exactly as I constantly update them to the latest ones.

    • @pritambakshi6936
      @pritambakshi6936 5 місяців тому

      @@TasteTheCode but now its works or not

    • @TasteTheCode
      @TasteTheCode  5 місяців тому

      No matter the library version it should still work.

    • @pritambakshi6936
      @pritambakshi6936 5 місяців тому

      @@TasteTheCode Can you explain me what problem i have faced.

    • @TasteTheCode
      @TasteTheCode  5 місяців тому

      I can try. What is the problem you are having?

  • @mrgcav
    @mrgcav 2 місяці тому

    Please updaten the Triac Module is no longer on Aliexpress

    • @TasteTheCode
      @TasteTheCode  2 місяці тому

      Hmm, I just checked the link and it works for me. Can you please double check it?

  • @anwarisholichul7686
    @anwarisholichul7686 Рік тому

    from this video can it be connected to nodered?

    • @TasteTheCode
      @TasteTheCode  Рік тому +1

      Yes it can but not with the current sketch. I haven't connected it myself so I would not know to tell you exactly how.

    • @anwarisholichul7686
      @anwarisholichul7686 Рік тому

      @@TasteTheCode are you still using the same module?

    • @TasteTheCode
      @TasteTheCode  Рік тому

      Yes, why?

    • @anwarisholichul7686
      @anwarisholichul7686 Рік тому

      @@TasteTheCodeCan you provide an overview for this project, can it be connected to node red

  • @carljay2177
    @carljay2177 Рік тому

    can it handle and control 1.5-2Hp 220 ac induction motor?

    • @TasteTheCode
      @TasteTheCode  Рік тому +1

      The module says it can handle 8A of continuous load but I'm guessing that is for a resistive load. A 2Hp motor will draw ~13A. And that is an inductive load which brings even more problems. The module is suitable for smaller motors, fans and heaters.

    • @carljay2177
      @carljay2177 Рік тому

      @@TasteTheCode how about a 1.5Hp gear motor?

    • @TasteTheCode
      @TasteTheCode  Рік тому +1

      That will be around 9-10A. Still too much. There are probably bigger modules that you can look at that should handle such loads.

    • @carljay2177
      @carljay2177 Рік тому

      @@TasteTheCode what modules should I use?

    • @TasteTheCode
      @TasteTheCode  Рік тому +1

      @@carljay2177 You can try this 24A module but I've never used such high power module, I'm not sure how it will go. www.aliexpress.com/item/1005001965951718.html?spm=a2g0o.detail.0.0.2b64657cSJgOQh&gps-id=pcDetailBottomMoreThisSeller&scm=1007.13339.291025.0&scm_id=1007.13339.291025.0&scm-url=1007.13339.291025.0&pvid=6c714dc3-2f23-475b-aa9e-f302b2334412&_t=gps-id:pcDetailBottomMoreThisSeller,scm-url:1007.13339.291025.0,pvid:6c714dc3-2f23-475b-aa9e-f302b2334412,tpp_buckets:668%232846%238111%231996&pdp_ext_f=%7B%22sku_id%22%3A%2212000018256785548%22%2C%22sceneId%22%3A%223339%22%7D&pdp_npi=3%40dis%21USD%217.99%217.83%21%21%21%21%21%402101d1b916787005781816918e5674%2112000018256785548%21rec%21MK%21164368730

  • @zyghom
    @zyghom 2 роки тому

    my fan went to trashbin ;-(
    unfortunately: not ALL AC fans are OK with speed control using this method
    just that you know ;-)

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      Sorry to hear that. Any specifics why? What makes some work and others not?

    • @zyghom
      @zyghom 2 роки тому

      @@TasteTheCode type of AC motor. I am not 100% sure about the names but there are few of them and .. the cheapest fans are... the cheapest, not subject to "triac things". They have wire split into 3 parts and there is a rotary switch giving possibility of speed 1,2 or 3. I wanted to be "better" and use speed 3 and then to regulate the speed by triac... I could have saved it but I turned it on and ... went for coffee. The fan was at zero rpm and got burned due to some lower current but without rotation there was no cooling so. Anyway, you cannot learn without mistakes ;-) I am back to business by making this rotary switch remotely on my turbo and relays inside the fan to switch the wires while and can do it remotely from the bike.

    • @TasteTheCode
      @TasteTheCode  2 роки тому

      @@zyghom yes, low RPM can be a problem. In my case, I found that 30% is the minimum at which the fan spins at all so I plan to limit the low end so it does not stop to provide some cooling.

  • @maestrospavlou
    @maestrospavlou 7 місяців тому

    Hi. what percentage should I send so that I get 220 volts at the output? with 60% the output is 116 volt and if i increase the percentage the output voltage decrease again. can you send your email to contact with you please? thank a lot.

    • @TasteTheCode
      @TasteTheCode  7 місяців тому

      Make sure that the zero crossing code is set through the interupt and that there is no delay in the code there as with higher duty cycle, the code needs to run faster. For a full output the percentage should be 100%.