Advertisement
microrobotics

Robotdyn 2-Channel AC Dimmer

Apr 4th, 2023
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here's the example code for interfacing the Robotdyn 2-Channel AC Dimmer with an Arduino using the RBDdimmer.h library. This code will allow you to control the brightness of two AC light bulbs independently using the AC dimmer module.
  3.  
  4. This code initializes two Robotdyn AC Dimmers on digital pins 2 and 4 (ZC) and 3 and 5 (PWM) using the RBDdimmer library. It also connects two potentiometers to analog pins A0 and A1 to control the dimming levels of the two lights independently. The dimming level ranges from 0 to 100, with 0 being off and 100 being fully on.
  5.  
  6. Please note that working with high voltage can be dangerous. Take all necessary precautions and safety measures while working with AC voltage. Also, make sure to check the voltage levels and specifications of your specific board and dimmer before using this code.
  7. */
  8.  
  9. #include <Arduino.h>
  10. #include <RBDdimmer.h>
  11.  
  12. // Pins for the first dimmer
  13. const int dimmer1Pin = 2; // Digital pin connected to the first AC Dimmer's ZC (zero-cross) pin
  14. const int pwm1Pin = 3;    // Digital pin connected to the first AC Dimmer's PWM pin
  15. const int pot1Pin = A0;   // Analog pin connected to a potentiometer (to control the dimming level of the first light)
  16.  
  17. // Pins for the second dimmer
  18. const int dimmer2Pin = 4; // Digital pin connected to the second AC Dimmer's ZC (zero-cross) pin
  19. const int pwm2Pin = 5;    // Digital pin connected to the second AC Dimmer's PWM pin
  20. const int pot2Pin = A1;   // Analog pin connected to a potentiometer (to control the dimming level of the second light)
  21.  
  22. dimmerLamp dimmer1(pwm1Pin, dimmer1Pin); // Initialize the first dimmer
  23. dimmerLamp dimmer2(pwm2Pin, dimmer2Pin); // Initialize the second dimmer
  24.  
  25. void setup() {
  26.   pinMode(pot1Pin, INPUT);
  27.   pinMode(pot2Pin, INPUT);
  28.   dimmer1.begin(NORMAL_MODE, ON); // Start the first dimmer in NORMAL_MODE and turn it ON
  29.   dimmer2.begin(NORMAL_MODE, ON); // Start the second dimmer in NORMAL_MODE and turn it ON
  30. }
  31.  
  32. void loop() {
  33.   int pot1Value = analogRead(pot1Pin);
  34.   int dimmingValue1 = map(pot1Value, 0, 1023, 0, 100);
  35.   dimmer1.setPower(dimmingValue1);
  36.  
  37.   int pot2Value = analogRead(pot2Pin);
  38.   int dimmingValue2 = map(pot2Value, 0, 1023, 0, 100);
  39.   dimmer2.setPower(dimmingValue2);
  40.  
  41.   delay(10);
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement