I have been trying to use shift registers (74HC595) in one of my projects and I am using daisy chaining in the same since I have to control switching of 9 devices.
I only have 3 GPIO available on my ESP32 board, need to control 9 relays and 3 LEDs using 2x74HC595 Shift registers.
The issue I have is, no matter what I try, the relay switches do not seem to work as expected.
Ideally, a shift register works in this way.
//Pin connected to ST_CP of 74HC595
int latchPin = 1;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 0;
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, B10010100);
digitalWrite(latchPin, HIGH);
}
When I use "B10010100" as the value, my understanding is out of 9 relays, I should be able to control 8 using above code.
With B10010100, I should have below configuration.
- Relay 1 - ON
- Relay 2 - OFF
- Relay 3 - OFF
- Relay 4 - ON
- Relay 5 - OFF
- Relay 6 - ON
- Relay 7 - OFF
- Relay 8 - OFF
But, I have spend atleast 2 days trying to figure out, why am I not able to control them in the way I expect. I am still able to control them using 595's, using different codes available on internet (mostly LED), which means the schematic is right.
I have attached a wiring diagram, with just one Shift Register, to make it simple to understand, and finally the three transistor on the left have their Emitter connected to relays. I have 9 of such transistor and 9 relays connected.