110-220V AC Digital Dimmer Module Microcontrollers 16 Levels 3V 5V opto-couplers ATMEL PIC
Please see below video
https://youtu.be/tjeGFqFtIyM
Main Features:High quality PCB FR4 Grade with FPT Certified.
Input for Dimmer module is of digital input of 4bit data.D0, D1, D2, D3 are the input pins of dimmer which can be connected to I/O pins microcontroller. 16 level of dimmer controlling input of 0 to 100% is shown below.
Digital Dimmer Module.
const int D3 = 5;
const int D2 = 4;
const int D1 = 3;
const int D0 = 2;
const int Pins[4]={D3, D2, D1, D0};
int n=2; //change delay value here
int count;
void setup()
{
Serial.begin(9600);
Serial.println("Initializing the state of Pins as Output");
for (int pin =0; pin < 4; pin++)
{
pinMode (Pins[pin], OUTPUT);
}
}
void loop()
{
for ( count = 0; count < 16; count++)
{
Dimming();
delay (n*1000); //To change the delay simply change the n value in the program(n x 1sec).
}
}
void Dimming()
{
digitalWrite (Pins[3], boolean ((count & 8)>>3));
digitalWrite (Pins[2], boolean ((count & 4)>>2));
digitalWrite (Pins[1], boolean ((count & 2)>>1));
digitalWrite (Pins[0], boolean (count & 1));
}