Greetings,
I'm fairly new to the electronics scene and trying to build various things to learn from. My latest attempt is trying to use shift registers to allow my Arduino to control a bunch of lights individually. I created a circuit using three separate shift registers to control the individual lights. I've attached an image of the circuit I've built.
After trying to build it on some perfboard though I find it does not seem to work well. The lights are 3.5v bulbs from an old string of christmas lights. They seem to work fine at the 5v that I am using to power the circuit anyway. The problems I'm seeing is that the lights do not light up as expected.
If I shift out a value that turns all lights on then it works and they all light up. If I try and light up only one at a time in each group then sometimes none will light, multiple will light, or the wrong one will light. I've not been able to identify any pattern to the errors, they seem random.
Is there something wrong with the circuit that might cause this or is it most likely a problem with my attempt to create it? I can't see any obvious problems on my perfboard like bad connections / shorts.
This is the code I am using on my Arduino to test for now.
const int PIN_DATA=3;
const int PIN_G1_CLK=4;
const int PIN_G2_CLK=5;
const int PIN_G3_CLK=6;
unsigned int clocks[3]={PIN_G1_CLK, PIN_G2_CLK, PIN_G3_CLK};
unsigned char masks[3]={1,1,1};
int dir=1;
void setup() {
pinMode(PIN_DATA, OUTPUT);
pinMode(PIN_G1_CLK, OUTPUT);
pinMode(PIN_G2_CLK, OUTPUT);
pinMode(PIN_G3_CLK, OUTPUT);
digitalWrite(PIN_G1_CLK, LOW);
digitalWrite(PIN_G2_CLK, LOW);
digitalWrite(PIN_G3_CLK, LOW);
}
void loop() {
display();
delay(1000);
if (dir == 1){
masks[0] = masks[0] << 1;
masks[1] = masks[1] << 1;
masks[2] = masks[2] << 1;
} else {
masks[0] = masks[0] >> 1;
masks[1] = masks[1] >> 1;
masks[2] = masks[2] >> 1;
}
if (masks[0] == 0x80 || masks[0] == 0x00){
masks[0] = masks[1] = masks[2] = 0xFF;
display();
delay(3000);
if (dir == 1){
dir = -1;
masks[0] = masks[1] = masks[2] = 0x80;
} else {
dir = 1;
masks[0] = masks[1] = masks[2] = 0x01;
}
}
}
void display(){
int i, len = sizeof(masks)/sizeof(masks[0]);
for (i = 0; i < len; i++){
shiftOut(PIN_DATA, clocks[i], MSBFIRST, masks[i]);
}
}