We are first time arduino users trying to use an Arduino Uno into shift registers into relays to power 16 Christmas lights. We are so close to having everything working but are getting flickering as the relays switch and trying to troubleshoot this piece. We believe the problem is with the relay or could be needing something to help with signal noise, but have gotten to the point where we are stuck.
Video of problem flickering
Flickering video
HARDWARE
Ardiuno Uno
2x Shift Register74HC595 Amazon Link
2x 8 Solid State Relay Amazon Link
8x outlets from home depot
Code
Works on our LED test system and the LEDs on the relays are working as intended, but have extra blinks on the actual lights.
//---------------------------------------
// CONSTANTS
//---------------------------------------
// name of SR pin -> Arduino pin # connected to SR pin
#define SER 4 // data in
#define SRCLK 6 // shift register clock
#define SRCLR 3 // clear shift register
#define RCLK 5 // storage register (sometimes called the latch pin)
#define OE 2 // enable output
#define TOTAL_SHIFT_PINS 16
void setup() {
// put your setup code here, to run once:
pinMode(SER, OUTPUT);
pinMode(SRCLK, OUTPUT);
pinMode(SRCLR, OUTPUT);
pinMode(RCLK, OUTPUT);
pinMode(OE, OUTPUT);
clearShiftRegisters();
turnOutputsOn();
}
void loop() {
// put your main code here, to run repeatedly:
shiftDataIn(HIGH);
copyShiftToStorage();
delay(2000);
shiftDataIn(LOW);
copyShiftToStorage();
delay(2000);
}
// This doesn't change the value stored in the storage registers.
void turnOutputsOn() {
digitalWrite(OE, LOW);
}
// clear the shift registers without affecting the storage registers.
void clearShiftRegisters() {
digitalWrite(SRCLR, LOW);
digitalWrite(SRCLR, HIGH);
}
// All the data in the shift registers moves over 1 unit and the new data goes in at shift register 0.
// The data that was in the shift register 7 goes to the next register (if any).
void shiftDataIn(int data) {
digitalWrite(SER, data);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
}
// copy the 8 shift registers into the shift registers,
// which changes the output voltage of the pins.
void copyShiftToStorage() {
digitalWrite(RCLK, HIGH);
digitalWrite(RCLK, LOW);
}
Schematic / circuit diagram
Basic
Prototype board
Relays to outlets
Pictures of actual system (It didn't like me uploading so many pictures so these will follow)
Arduino to proto board
IMG_5585
Protoboard to relays and relays to outlets
IMG_5586
IMG_5587
IMG_5588
Note we did ground the relays to the ardiuno ground as we weren't getting all 8 on a board to turn on without it.
Outlets and power
IMG_5589
We use separate power for the arduino, relays, and outlets (this is all LED lights plugged into the outlets so running everything off our extension cord plugged into power)
As this is bulky and I'd rather leave it outside (as I did program it to always on so I could at least plug everything in while we figure out the input piece), I also have a little test system with LEDs that works great and doesn't flicker so trying to figure out what's going wrong between the two. This has 220 resistors in line with LEDs so I could figure out the code part and see what lights were going to be doing.
Any help figuring out how to stop the Christmas lights flickering would be great. If we can get the simple blink program working then I have a lot of more fun code ready, but it feels like it will give you a seizure with our current extra blinking going on. (I'd also love to understand what is going on differently between the LED test setup and the actual outlets into the lights outside so I can better replicate my test system so once we get this out we can move away from a very prototype mode to something more permenent.











