Controlling an AC Bulb with an Arduino AC Dimmer
This video shows how to use an AC light dimmer to control an AC bulb using an AC dimmer and an Arduino.
I opened the sketch File>Examples>RBDdimmer>SerialMonitorDim, where you can control the light from the command line of the Serial Monitor. But, due to an issue explained in the video, it does not work properly, and the code needed to be modified. It might work in regions with 50Hz, which I have not tested.
Resources for this sketch
256-Resources for this sketch
语言: C++
/**************
* RobotDyn AC Light Dimmer
*
* Control AC bulb using Arduino and AC Light dimmer module with Triac BTA16 600B
*
* Code modified by Ahmad Shamshiri on Friday, October 25, 2019, in Ajax, Ontario, Canada
*
* Watch video instruction for this code: https://youtu.be/zJQf6bNodhE
*
* Original code can be obtained from: https://github.com/RobotDynOfficial/RBDDimmer
*
*
*
* Get this code and other Arduino codes from Robojax.com.
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place. Purchase my course on Udemy.com: http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon: http://robojax.com/L/?id=63
or make a donation using PayPal: http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <RBDdimmer.h>//
//#define USE_SERIAL SerialUSB //Serial for boards with USB serial port
#define USE_SERIAL Serial
#define outputPin 12
#define zerocross 5 // for boards with CHANGEABLE input pins
#define potPin A0 // define the input pin for potentiometer
/// fix potentiometer issue
const int potMin = 70;// watch video (link above) for details
const int potMax = 804;// watch video (link above) for details
int potValue;// watch video (link above) for details
//dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
dimmerLamp dimmer(outputPin); //initialize port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero
int outVal = 0;
void setup() {
USE_SERIAL.begin(9600);
dimmer.begin(NORMAL_MODE, ON); //dimmer initialization: name.begin(MODE, STATE)
}
void loop()
{
potValue =analogRead(potPin);// read potentiometer
correctValue();
// watch video (link above) for details
outVal = map(potValue, 22, 1023, 100, 0); // analogRead(analog_pin), min_analog, max_analog, 100%, 0%);
USE_SERIAL.print("potValue:");
USE_SERIAL.print(potValue);
USE_SERIAL.print(" ");
USE_SERIAL.print(outVal);
USE_SERIAL.println("%");
dimmer.setPower(outVal); // name.setPower(0%-100%)
}
/*
* correctValue()
* Corrects the value for AC dimmer module
* Written by Ahmad Shamshiri on October 25, 2019
* watch my Robojax YouTube video for details
* www.Robojax.com
*/
void correctValue()
{
if(potValue <potMin)
{
potValue =potMin;
}
if(potValue >potMax)
{
potValue =potMax;
}
}//correctValue() end
资源与参考
-
外部4N26 光耦合器数据表vishay.com
-
外部MOC3021 光耦三端驱动器 (PDF)farnell.com
-
外部RobotDyn库(GitHub)github.com
文件📁
没有可用的文件。