* 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 :


* Original code can be obtained from:




* Get this code and other Arduino codes from

Learn Arduino step by step in structured course with all material, wiring diagram and library

all in once place. Purchase My course on

If you found this tutorial helpful, please support me so I can continue creating

content like this. You can support me on Patreon

or make donation using PayPal

* * 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

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


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 <>.


#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() {


dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE)


void loop()


potValue =analogRead(potPin);// read potentiometer


// 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(" ");



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



void correctValue()


if(potValue <potMin)


potValue =potMin;


if(potValue >potMax)


potValue =potMax;


}//correctValue() end