Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Here's an example code for interfacing the Robotdyn AC Dimmer with an Arduino. This code will allow you to control the brightness of an AC light bulb using the AC dimmer.
- This code initializes the Robotdyn AC Dimmer on digital pins 3 (PWM) and 9 (ZC). 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.
- 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.
- */
- #include <Arduino.h>
- const int dimmerPin = 9; // Digital pin connected to the AC Dimmer's ZC (zero-cross) pin
- const int pwmPin = 3; // Digital pin connected to the AC Dimmer's PWM pin
- const int potPin = A0; // Analog pin connected to a potentiometer (to control the dimming level)
- const int freqStep = 75; // Dimming control frequency step (75us = 50Hz, 100us = 60Hz)
- void setup() {
- pinMode(dimmerPin, INPUT);
- pinMode(pwmPin, OUTPUT);
- pinMode(potPin, INPUT);
- attachInterrupt(digitalPinToInterrupt(dimmerPin), zeroCrossing, RISING);
- }
- void loop() {
- int potValue = analogRead(potPin);
- int dimmingValue = map(potValue, 0, 1023, 0, 100);
- delay(10);
- }
- void zeroCrossing() {
- int dimmingDelay = (100 - dimmingValue) * freqStep;
- digitalWrite(pwmPin, HIGH);
- delayMicroseconds(dimmingDelay);
- digitalWrite(pwmPin, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement