Advertisement
microrobotics

Robotdyn AC Dimmer_RBDdimmer.h

Apr 4th, 2023
2,555
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 AC Dimmer with an Arduino using the RBDdimmer.h library. This code will allow you to control the brightness of an AC light bulb using the AC dimmer.
  3.  
  4. First, you need 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.
  5.  
  6. This code initializes the Robotdyn AC Dimmer on digital pins 3 (PWM) and 9 (ZC) using the RBDdimmer library. It also connects a potentiometer to analog pin A0 to control the dimming level. The dimming level ranges from 0 to 100, with 0 being off and 100 being fully on.
  7.  
  8. 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.
  9. */
  10.  
  11.  
  12. #include <Arduino.h>
  13. #include <RBDdimmer.h>
  14.  
  15. const int dimmerPin = 9; // Digital pin connected to the AC Dimmer's ZC (zero-cross) pin
  16. const int pwmPin = 3;    // Digital pin connected to the AC Dimmer's PWM pin
  17. const int potPin = A0;   // Analog pin connected to a potentiometer (to control the dimming level)
  18.  
  19. dimmerLamp dimmer(pwmPin, dimmerPin); // Initialize the dimmer
  20. int dimmingValue = 0;
  21.  
  22. void setup() {
  23.   pinMode(potPin, INPUT);
  24.   dimmer.begin(NORMAL_MODE, ON); // Start the dimmer in NORMAL_MODE and turn it ON
  25. }
  26.  
  27. void loop() {
  28.   int potValue = analogRead(potPin);
  29.   dimmingValue = map(potValue, 0, 1023, 0, 100);
  30.   dimmer.setPower(dimmingValue);
  31.   delay(10);
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement