Sunday, 12 October 2014 15:12

Using HEF4094 Shift Registers with Arduino

I have many seven segment modules in my hand. Each module consists of 5 digits and each digit is controlling by individual HEF4094 shift register. As shown in figure above is the seven segment module.

HEF4094 is an 8-stage serial shift register. Data is shifted on the LOW-to-HIGH transitions of the CP (Clock) input. The product data sheet is available here.

HEF4094 operates over a recommended VDD power supply range of 3 V to 15 V referenced to VSS (usually ground). There is also 74HC4094 available which operates at 2V to 6V.

The HEF4094 is very similar to 74HC595, here is the comparison:

Table 1. Comparison of Shift Register

We can use the shiftout() function from Arduino IDE to control the HEF4094 since the data input and output pins (one serial input and eight parallel output) for HEF4094 and 74HC595 is exactly the same, additionally the clock input is no different (data is shifted on the LOW to HIGH transitions), with only 3 data pins (CP:Clock Input, STR:Strobe Input, D:Data Input), we can control an almost unlimited amount of outputs.

Code below use to control the 74HC595, the latchPin must first set to LOW before sending data to the Shift Register, the latchPin is then set to HIGH to transfer data to the storage register.

  1. digitalWrite(latchPin, LOW); //Pull latch LOW to send data
  2. shiftOut(dataPin, clockPin, MSBFIRST, data); //Send the data
  3. digitalWrite(latchPin, HIGH); // Pull latch HIGH to stop sending data



Code below use to control HEF4094, notice that the latchPin (Strobe input) is transitioned from HIGH to LOW.

  1. digitalWrite(latchPin, HIGH); //Pull latch HIGH to send data
  2. shiftOut(dataPin, clockPin, MSBFIRST, data); //Send the data
  3. digitalWrite(latchPin, LOW); // Pull latch LOW to stop sending data


Here is the fully working sketch for HEF4094, each LED is turn ON and OFF in sequence.

  1. const byte COL_COUNT = 8;
  2. //array to hold the data
  3. unsigned char sequence[COL_COUNT] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
  4. //unsigned char sequence[COL_COUNT] = {1, 2, 4, 8, 16, 32, 64, 128};
  5. //unsigned char sequence[COL_COUNT] = {0x01, 0x02, 0x04, 0x8, 0x10, 0x20, 0x40, 0x80};
  6. //Define which pins will be used for the shift register control
  7. //can be any digital pin on the Arduino
  8. int latchPin = 8; //Pin connected to STR(pin 1) of HEF4094
  9. int clockPin = 12; //Pin connected to CP(pin 3) of HEF4094
  10. int dataPin = 11; //Pin connected to D(pin 2) of HEF4094
  11.  
  12. void setup() {
  13. pinMode(latchPin, OUTPUT);
  14. pinMode(clockPin, OUTPUT);
  15. pinMode(dataPin, OUTPUT);
  16. }
  17.  
  18. void loop()
  19. {
  20. for (int col = 0; col < COL_COUNT; col++)
  21. {
  22. digitalWrite(latchPin, HIGH); //Pull latch HIGH to send data
  23. shiftOut(dataPin, clockPin, MSBFIRST, sequence[col]); //Send the data
  24. digitalWrite(latchPin, LOW); // Pull latch LOW to stop sending data
  25. delay(500);
  26. }
  27. }

Figure 1. Circuit diagram


Sketch below demonstrated how to display 5 digits on the common anode seven segment LED using five HEF4094 Shift Register, you can change the value of DIGIT_COUNT matching your requirement. However you must add leading zero (or blank character) to the number if you are trying to display a number which is less than DIGIT_COUNT.

  1. const byte DIGIT_COUNT = 5;
  2. //array to hold the data (0,1,2,3,4,5,6,7,8,9,blank)
  3. unsigned char digits[11] = {B11000000, B11111001, B10100100, B10110000, B10011001, B10010010, B10000010, B11111000, B10000000, B10010000, B11111111};
  4. //Define which pins will be used for the shift register control
  5. //can be any digital pin on the Arduino
  6. int latchPin = 8; //Pin connected to STR(pin 1) of HEF4094
  7. int clockPin = 12; //Pin connected to CP(pin 3) of HEF4094
  8. int dataPin = 11; //Pin connected to D(pin 2) of HEF4094
  9.  
  10. void setup() {
  11. pinMode(latchPin, OUTPUT);
  12. pinMode(clockPin, OUTPUT);
  13. pinMode(dataPin, OUTPUT);
  14. }
  15.  
  16.  
  17. void loop()
  18. {
  19. disp_the_number(12345);
  20. delay(1000);
  21. disp_the_number(65432);
  22. delay(1000);
  23. }
  24.  
  25.  
  26. void disp_the_number(int the_number)
  27. {
  28. for (int col = 0; col < DIGIT_COUNT; col++)
  29. {
  30. disp_one_character(getDigit(the_number,col+1));
  31. }
  32. }
  33.  
  34.  
  35. //Extract a digit from an number (integer), eg. getDigit(5678,2) return 6
  36. int getDigit(unsigned int number, int digit) {
  37. for (int i=0; i<digit-1; i++) {
  38. number /= 10;
  39. }
  40. return number % 10;
  41. }
  42.  
  43.  
  44. void disp_one_character(char theChar)
  45. {
  46. digitalWrite(latchPin, HIGH); //Pull latch LOW to send data
  47. shiftOut(dataPin, clockPin, MSBFIRST, digits[theChar]); //Send the data
  48. digitalWrite(latchPin, LOW); // Pull latch HIGH to stop sending data
  49. }
  50.  
  51.  

Figure 2. Cascading the HEF4094 Shift Register

Read 15937 times Last modified on Sunday, 12 October 2014 19:32

1 comment

  • Comment Link William Thursday, 07 September 2017 09:12 posted by William

    I happened to be given a few of these 4094 IC's. I now know how to use them in a circuit!
    Interesting tutorial! Thanks for sharing!

    William

Leave a comment

Back to Top