Control AC bulb with Arduino AC Dimmer
Control AC bulb with Arduino AC Dimmer
This this video shows how to use AC Light dimmer to control AC bulb using AC dimmer and Arduino.
I opened the sketch File->Examples->RBDdimmer->SerialMonitorDim where you can control the light from command line of Serial Monitor but due to issue
explained in the video, it doesn't work properly and code needed to be modefied. It might work in region with 50Hz which I have not tesed.
Resources for this sketch
- RobotDyn Libarary (GitHub)
- RobotDyn Libarary (from Robojax.com if Above link is not working)
- 4N26 Optocoupler Datasheet
- MOC3021 Optoisolators Triac Driver(pdf)
- BTA16 600B Triac datasheet (pdf)
- Get Wiring Diagram for this from Robojax Arduino Course on Udemy
- Get Early Access to my videos via Patreon
/**************
* RobotDyn AC Light Dimmer
*
* Control AC bulb using Arduino and AC Light dimmer module with Triac BTA16 600B
*
* Code modefied by Ahmad Shamshiri on Friday Oct 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 structured course with all material, wiring diagram and library
all in once 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 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 download 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 whith USB serial port
#define USE_SERIAL Serial
#define outputPin 12
#define zerocross 5 // for boards with CHANGEBLE 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); //initialase 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 initialisation: 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 Oct 25, 2019
* watch my Robojax YouTube video vor details
* www.Robojax.com
*/
void correctValue()
{
if(potValue <potMin)
{
potValue =potMin;
}
if(potValue >potMax)
{
potValue =potMax;
}
}//correctValue() end