Hi all,
I am a complete newbie to Arduino (and in fact to coding of any sort), so please be gentle. ![]()
I have an 8A RobotDyn RBDimmer (link) that I'm using with an Arduino Nano clone board (ATMega328p with a CH340g USB-serial chip; link). I have a sketch running to gradually brighten a tungsten/incandescent bulb (not an LED, which I know can cause problems), and it is exhibiting weird behavior:
From 1% to 13% power, the bulb is lit at a constant brightness of about 60% (the brightness does not change between 1% and 14% power).
Then from 14% to 16% power, the bulb flickers at a high frequency (maybe 50 Hz or so).
Then from 16% to 17% power, the bulb turns on and off at a much lower frequency (maybe 5 Hz).
Again, this is a tungsten/incandescent bulb I'm using, not an LED.
It is also behaving weirdly above that (at 100% power it is not lighting LED bulbs at all), but I have a harder time deciphering that behavior.
The code I am running is pasted below (it was generated by ChatGPT... sorry
. I'm just starting to learn to code).
I know the sketch involves the RBDimmer.h library, which I installed into the IDE (I'm using the v2 IDE).
Can anyone possibly explain (and/or provide a fix for) the weird behavior I'm seeing?
Thank you.
Here's the code:
[#include <RBDdimmer.h> // RobotDyn AC Dimmer library
#define AC_LOAD 3 // DIM/PWM pin connected to the RobotDyn module
#define ZC_PIN 2 // Zero-cross pin from the RobotDyn module (wired to D2, but handled internally)
// Create dimmer object (older library: only takes 1 argument)
dimmerLamp dimmer(AC_LOAD);
void setup() {
Serial.begin(9600);
// Initialize dimmer (older library handles ZC internally)
dimmer.begin(NORMAL_MODE, OFF);
dimmer.setPower(0);
Serial.println("Starting 30-minute gradual brightening...");
}
void loop() {
const int startBrightness = 0; // Start at 0%
const int endBrightness = 100; // End at 100%
const unsigned long totalTime = 30UL * 60UL * 1000UL; // calculating total time in milliseconds of fadeup; minutes, seconds per minute, milliseconds per second
const int steps = 100; // 1% increments
unsigned long delayPerStep = totalTime / steps; // calculating milliseconds per step
// Gradually brighten
for (int brightness = startBrightness; brightness <= endBrightness; brightness++) {
dimmer.setState(ON);
dimmer.setPower(brightness); // Set brightness (0β100%)
Serial.print("Brightness: ");
Serial.print(brightness);
Serial.println("%");
delay(delayPerStep);
}
// Hold full brightness indefinitely
Serial.println("Reached full brightness. Holding...");
dimmer.setPower(100);
dimmer.setState(ON);
while (true) {
delay(1000); // keep AC dimmer timing active
}
}](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966)

