RobotDyn AC Dimmer-4 channels not working

I am attempting to dim a 230V AC light using an Arduino UNO R4 WiFi and a RobotDyn AC dimmer. However, Arduino IDE version 2.3.4 displays the following error message: 'This library only supports boards with an AVR, ESP32, ESP8266, SAMD, SAM, or STM32F1/F4 processor.' Has anyone tested the RobotDyn AC dimmer with the Arduino UNO R4 WiFi? Alternatively, is there another method to dim the light using the UNO R4 WiFi?


The error message should be self-explanatory. The library you are using does NOT work with the board you are using. Pick a library that does.

  1. You can write the low level code for the UNO R4 which uses the zero cross interrupt and timer based triac turn on signal like used by the library.

  2. You can use a dimmer like those made by Krida which use a pwm input.
    https://www.tindie.com/products/bugrovs2012/pwm-8a-ac-light-dimmer-module-50hz-60hz-tasmota/

  3. You can use an dimmer which is controlled through i2c
    [https://www.tindie.com/products/bugrovs2012/i2c-4ch-ac-led-dimmer-module/]](https://www.tindie.com/products/bugrovs2012/i2c-4ch-ac-led-dimmer-module/])

Thanks for the reply. I write the code. But I am facing following issues.
1.I was unable to turn off the light.
2.The light is flickering at a low brightness level.
3.The light brightness is high at 0 and low at 255. However, I need the light brightness to be low at 0 and high at 255.

My application is simple. I need to dim a 230V light using an Arduino UNO R4 Wi-Fi, a CT3021 optocoupler, and a BTA16 TRIAC dimmer.

I have attached my code for your reference.

// Pin definitions
const int zeroCrossPin = 2; // Zero-cross detection input
const int triacPin = 3;     // TRIAC gate control output

// Variables
volatile boolean zeroCrossDetected = false;
int dimming = 128; // Dimming level (0-255). Lower = brighter, higher = dimmer.

// Interrupt service routine for zero-cross detection
void zeroCrossISR() {
  zeroCrossDetected = true;
}

void setup() {
  pinMode(zeroCrossPin, INPUT);
  pinMode(triacPin, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(zeroCrossPin), zeroCrossISR, RISING); // Trigger on zero cross
  digitalWrite(triacPin, LOW); // Ensure TRIAC is off at start
  Serial.begin(9600);
}

void loop() {
  if (zeroCrossDetected) {
    zeroCrossDetected = false;
    
    // Calculate delay based on dimming level
    int delayTime = (dimming * 75) / 255; // Delay in microseconds (adjust for 50Hz)
    
    delay(delayTime); // Wait for the correct phase angle
    digitalWrite(triacPin, HIGH); // Trigger TRIAC
    delay(10);        // Short pulse to trigger
    digitalWrite(triacPin, LOW);  // Turn off TRIAC gate
  }

  // Optional: adjust dimming via Serial input
  if (Serial.available()) {
    int newDimming = Serial.parseInt();
    if (newDimming >= 0 && newDimming <= 255) {
      dimming = newDimming;
      Serial.print("New dimming level: ");
      Serial.println(dimming);
    }
  }
}

Yo need more than that to make a dimmer.
Let's be clear about what you want to do and what you have.
In your original post you say you have a 4 channel AC dimmer by RobotDyn.
So which is it?
How may channels do you need?

Thanks for your reply. I have a RobotDyn 4 channel dimmer. The Arduino UNO R4 WIFI is not supporting RBDDimmer.h file. I need a solution to dim 230v light without this file. Thanks.

Hi, @hisjuma1
Welcome to the forum.

Do you need to use the UNO R4 WiFi ?
Can you use the AVR board UNO R3 or if need WiFi ESP32?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Hi @TomGeorge , I don't have UNO R3 board. I have only UNO R4 WIFI board. Is it possible to dim 230v light using UNO R4 WIFI board and RobotDYN 4 channel dimmer? Is there any way possible?

Try this code
Make sure you select no line ending on the serial monitor
Dimming goes from 0 to 100

// Pin definitions
const int zeroCrossPin = 2; // Zero-cross detection input
const int triacPin = 3;     // TRIAC gate control output

// Variables
volatile boolean zeroCrossDetected = false;
int dimming = 50; // Dimming level (0-100) Lower = brighter, higher = dimmer.
unsigned long delayTime = 0;

// Interrupt service routine for zero-cross detection
void zeroCrossISR() {
  zeroCrossDetected = true;
}

void setup() {
  pinMode(zeroCrossPin, INPUT);
  pinMode(triacPin, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(zeroCrossPin), zeroCrossISR, RISING); // Trigger on zero cross
  digitalWrite(triacPin, LOW); // Ensure TRIAC is off at start
  Serial.begin(9600);
}

void loop() {
  if (zeroCrossDetected) {
    zeroCrossDetected = false;

    if (dimming > 0)
    {
      // Calculate delay based on dimming level
      delayTime = dimming * 100L; // Delay in microseconds (adjust for 50Hz)

      delayMicroseconds(delayTime); // Wait for the correct phase angle
      digitalWrite(triacPin, HIGH); // Trigger TRIAC
      delayMicroseconds(100);       // Short pulse to trigger
      digitalWrite(triacPin, LOW);  // Turn off TRIAC gate
    }
    else
      digitalWrite(triacPin, LOW);
  }

  // Optional: adjust dimming via Serial input
  if (Serial.available()) {
    int newDimming = Serial.parseInt();
    if (newDimming >= 0 && newDimming <= 100) {
      dimming = newDimming;
      Serial.print("New dimming level: ");
      Serial.println(dimming);
    }
  }
}

I made one mistake
Change
unsigned long delayTime = 0;
to
unsigned int delayTime = 0;

and change

delayTime = dimming * 100L;
to
delayTime = dimming * 100;

Thanks @jim-p. It's working!! Only thing is the light brightness is high @10% and low @80%. But, we need light brightness high @80% and low @10%.

Thank you once again.


Easy fix

  if (zeroCrossDetected) {
    zeroCrossDetected = false;

    // add this line here
    dimming = 100 - dimming;  // Reverse the dimming level
    
    if (dimming > 0)
    {
 

Sorry, the light behaves erratically after adding the above line. I can no longer turn off the light, nor is it dimming. Additionally, the light is flickering.

Sorry, totally messed that up
New code

// Pin definitions
const int zeroCrossPin = 2; // Zero-cross detection input
const int triacPin = 3;     // TRIAC gate control output

// Variables
volatile boolean zeroCrossDetected = false;
int dimming = 50; // Dimming level (0-100) Lower = brighter, higher = dimmer.
unsigned int delayTime = 0;

// Interrupt service routine for zero-cross detection
void zeroCrossISR() {
  zeroCrossDetected = true;
}

void setup() {
  pinMode(zeroCrossPin, INPUT);
  pinMode(triacPin, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(zeroCrossPin), zeroCrossISR, RISING); // Trigger on zero cross
  digitalWrite(triacPin, LOW); // Ensure TRIAC is off at start
  Serial.begin(9600);
}

void loop() {
  if (zeroCrossDetected) {
    zeroCrossDetected = false;
    if (dimming > 0)
    {
      // Calculate delay based on dimming level
      delayTime = dimming * 100; // Delay in microseconds (adjust for 50Hz)

      delayMicroseconds(delayTime); // Wait for the correct phase angle
      digitalWrite(triacPin, HIGH); // Trigger TRIAC
      delayMicroseconds(100);       // Short pulse to trigger
      digitalWrite(triacPin, LOW);  // Turn off TRIAC gate
    }
    else
      digitalWrite(triacPin, LOW);
  }

  // Optional: adjust dimming via Serial input
  if (Serial.available()) {
    int newDimming = Serial.parseInt();
    if (newDimming >= 0 && newDimming <= 100) {
      Serial.print("New dimming level: ");
      Serial.println(newDimming);
      dimming = 100 - newDimming;  // Reverse the dimming level
    }
  }
}
1 Like

Thanks. It's working.

Great
Have a nice day!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.