Advertisement
microrobotics

Robotdyn 4-Channel AC Dimmer

Apr 4th, 2023
1,519
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 4-Channel AC Dimmer with an Arduino using the RBDdimmer.h library. This code will allow you to control the brightness of four AC light bulbs independently using the AC dimmer module.
  3.  
  4. This code initializes four Robotdyn AC Dimmers on digital pins 3, 4, 5, and 6 (PWM) using the RBDdimmer library. All four dimmers share a common zero-cross pin (ZC) connected to digital pin 2. It also connects four potentiometers to analog pins A0, A1, A2, and A3 to control the dimming levels of the four 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. Remember to install the RBDdimmer library if you haven't done so. You can download the library from this GitHub repository: https://github.com/RobotDynOfficial/RBDDimmer. Extract the downloaded ZIP file and copy the "RBDDimmer" folder to your Arduino's "libraries" folder.
  9. */
  10.  
  11. #include <Arduino.h>
  12. #include <RBDdimmer.h>
  13.  
  14. // Common zero-cross pin for all dimmers
  15. const int dimmerZCPin = 2;
  16.  
  17. // Pins for the individual dimmers
  18. const int pwm1Pin = 3; // Digital pin connected to the first AC Dimmer's PWM pin
  19. const int pwm2Pin = 4; // Digital pin connected to the second AC Dimmer's PWM pin
  20. const int pwm3Pin = 5; // Digital pin connected to the third AC Dimmer's PWM pin
  21. const int pwm4Pin = 6; // Digital pin connected to the fourth AC Dimmer's PWM pin
  22.  
  23. // Analog pins for potentiometers
  24. const int pot1Pin = A0;
  25. const int pot2Pin = A1;
  26. const int pot3Pin = A2;
  27. const int pot4Pin = A3;
  28.  
  29. // Initialize the dimmers
  30. dimmerLamp dimmer1(pwm1Pin, dimmerZCPin);
  31. dimmerLamp dimmer2(pwm2Pin, dimmerZCPin);
  32. dimmerLamp dimmer3(pwm3Pin, dimmerZCPin);
  33. dimmerLamp dimmer4(pwm4Pin, dimmerZCPin);
  34.  
  35. void setup() {
  36.   pinMode(pot1Pin, INPUT);
  37.   pinMode(pot2Pin, INPUT);
  38.   pinMode(pot3Pin, INPUT);
  39.   pinMode(pot4Pin, INPUT);
  40.  
  41.   dimmer1.begin(NORMAL_MODE, ON); // Start the first dimmer in NORMAL_MODE and turn it ON
  42.   dimmer2.begin(NORMAL_MODE, ON); // Start the second dimmer in NORMAL_MODE and turn it ON
  43.   dimmer3.begin(NORMAL_MODE, ON); // Start the third dimmer in NORMAL_MODE and turn it ON
  44.   dimmer4.begin(NORMAL_MODE, ON); // Start the fourth dimmer in NORMAL_MODE and turn it ON
  45. }
  46.  
  47. void loop() {
  48.   int pot1Value = analogRead(pot1Pin);
  49.   int dimmingValue1 = map(pot1Value, 0, 1023, 0, 100);
  50.   dimmer1.setPower(dimmingValue1);
  51.  
  52.   int pot2Value = analogRead(pot2Pin);
  53.   int dimmingValue2 = map(pot2Value, 0, 1023, 0, 100);
  54.   dimmer2.setPower(dimmingValue2);
  55.  
  56.   int pot3Value = analogRead(pot3Pin);
  57.   int dimmingValue3 = map(pot3Value, 0, 1023, 0, 100);
  58.   dimmer3.setPower(dimmingValue3);
  59.  
  60.   int pot4Value = analogRead(pot4Pin);
  61.   int dimmingValue4 = map(pot4Value, 0, 1023, 0, 100);
  62.   dimmer4.setPower(dimmingValue4);
  63.  
  64.   delay(10);
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement