Using a 74HC595 shift register with the Wemos

Sometimes in your projects you simply do not have enough I/O lines available, take for example a lot of the multiple LED examples, these use 8 outputs to control 8 LEDs via your Wemos Mini, that can restrict the amount of outputs you would have available to drive other devices. Instead of this we can use a shift register, in this case a 74HC595 and using 3 I/O pins we can control 8 LED’s, that’s a saving of 5 I/O pins for other uses.

You can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. You can link multiple registers together to extend your output even more. The 74HC595 has an 8 bit storage register and an 8 bit shift register. Data is written to the shift register serially, then latched onto the storage register. The storage register then controls 8 output lines

Lets look at the 74HC595

595 pin diagram
595 pin diagram
PINS 1-7, 15 Q0 to Q7 Output Pins
PIN 8 GND Ground, Vss
PIN 9 Q7″ Serial Out
PIN 10 MR Master Reclear, active low
PIN 11 SH_CP Shift register clock pin
PIN 12 ST_CP Storage register clock pin (latch pin)
PIN 13 OE Output enable, active low
PIN 14 DS Serial data input
PIN 16 Vcc Positive supply voltage  3.3v



This is the schematic on how to control the 74HC595 from your Wemos Mini and how to wire up 8 sets of LEDs to the 74HC595. I’ve connected the Vcc of the 74HC595 to the 3v3 output of the Wemos mini just to illustrate that we are using 3.3v for the 74HC595



In this example we will simply display a random value on the LEDs, this will also show how to generate a random number.



int latchPin = D8;
int clockPin = D7;
int dataPin = D6;
long randNumber;
void setup() 
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
void loop()
randNumber = random(1, 255);
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, randNumber);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:



10PCS SN74HC595N

30pcs SN74HC595N 8 Bit Shift Register


Please enter your comment!
Please enter your name here