7 Segment display on Arduino with 595

7_segment_display7 Segment displays are easy to attach to an arduino (or other microprocessor). Just connect the digital Outputs of the Arduino with a segment of the display (via a current limiting 470-560 ohm resistor: the IC can in total only deliver 70mA) and fire away.

Nothing wrong with that except for normally needing 8 digital pins for that (if you are using the point as well), and in some cases that might just be too much.

It is possible to use only 3 output pins if you are using a serial shift register like the 74HC595.
This chip will take a base-10 number and translate that into a binary number on its 8 output pins. So if I send  ‘0’ the output will be ‘00000000’ and if I send ‘255’ the output will be ‘11111111’ so with the proper connections to the pins of the display, the correct segments can be made to lit up.

When you get a 7 segment display it is not always clear what the pin configuration of that chip is. Sometimes it is not even clear if it is a common anode or a common cathode display, so that is what we need to figure out first. Ofcourse if you have a datasheet, that helps, but it can’t hurt to check, just to make sure. If you look at the picture below, it is already clear what the common pins are. Use a simple multimeter, keep  one probe on the common pin and see what segments light up  when you touch a pin with the other probe

7seg_dispA simple way  to set up the proper connections is to follow the more or less standardized connections below:
Q0 ->A  (or, to be more precise, the pin that lights up segment ‘A’)
It is obvious that  sending ‘0’  to the display will not light up any segments while sending ‘255’ to the display will light up all the segments, including the DP.
As the DP is connected to Q7 it is clear that sending 127 will light up all the segments except DP, which means it will form an ‘8’.

For the ‘0’ you need all the elements to light except G. As G is connected to  Q6, you will need ‘11111100’ on the 595, which is ’63’
With the chosen connections, the following numbers will make the ‘0’ til ‘9’:

63, 6, 91,79, 102, 109, 125,7, 127,111.

(192,249,164,176,153,146,130,248,128,144  for common anode)
If for whatever reason (easier in yr print design perhaps), just set up a truth table and determine the base numbers you need to send

After you have those base-numbers that represent a specific number, store those in an array, from where you can send them to the HCT595.

Your connections between Arduino, 74HC595 and 7 segment will look like this:

Arduino pin 5 => 74HC595 pin 12 (latch)
Arduino pin 6 => 74HC595 pin 14 (data)
Arduino pin 7 => 74HC595 pin 11 (clock)

74HC595 pin 1  (Q1)   => LED Pin 5  (B)
74HC595 pin 2  (Q2)   => LED Pin 9  (C)
74HC595 pin 3  (Q3)   => LED Pin 7  (D)
74HC595 pin 4  (Q4)   => LED Pin 6  (E)
74HC595 pin 5  (Q5)   => LED Pin 2  (F)
74HC595 pin 6  (Q6)   => LED Pin 1 (G)
74HC595 pin 7  (Q7)   => LED Pin 10  (DP)
74HC595 pin 8  (GND)  => Ground
74HC595 pin 9  (Q7S)  => Not connected
74HC595 pin 10 (MR)   => Vcc (High)
74HC595 pin 11 (SHCP) => Arduino pin 7
74HC595 pin 12 (STCP) => Arduino pin 5
74HC595 pin 13 (OE)   => Ground (Low)
74HC595 pin 14 (DS)   => Arduino pin 6
74HC595 pin 15 (Q0)   => LED Pin 4  (A)
74HC595 pin 16 (Vcc)  => Vcc

the choice for the arduino pins connecting to the 595 lines… that is  randomly chosen. they could have been other pins

LED pin 3 or 8 => 470 Ohm resistor => Vcc  (for a common anode display)  or  => Ground (for a common cathode display)
With regard to the last line there is some debate whether with a 7 segment display it would be enough to use only one resistor in the common anode or cathode or that they each should have their own resistor. Obviously, displaying a ‘1’ involves only 2 segments to light up, whereas a ‘0’ requires 6 segments to light up and therefore would be less bright. For testing purposes you could use 1 resistor of say 330 ohm in the common lead. For final circuit I would advise separate resistors.





Using a 7-segment display with the 74HC595 shift register

int latchpin = 5;// connect to pin 12 on the '595
int clockpin = 7; // connect to pin 11 on the '595
int datapin = 6; // connect to pin 14 on the '595
// the array contains the binary value to make digits 0-9
// for the number '11'  use code '31' for CC and '224' for CA
int segment[10] = {63,6,91,79,102,109,125,7,127,111 }; // for common cathode
//int segment[10] = {192,249,164,176,153,146,130,248,128,144 }; // for common anode

void setup()
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
void loop()

digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0); // clears the display
digitalWrite(latchpin, HIGH);

for (int lus=0; lus<10; lus++)
// counts from 0 to 9, using the values in the array
// whose values correspond to the binary outputs 0~9
// add 128 for digital point
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, segment[lus]+128);
digitalWrite(latchpin, HIGH);

digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0); // clear the display
digitalWrite(latchpin, HIGH);

digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 128); // light the decimal point
digitalWrite(latchpin, HIGH);


mind you that it is possible to count to ’11’ on the display. just write ’31’ (‘00011111’) to the 595

VQB 27 E
VQB 27 E

A popular 7 segment matrix is the VQB 27 E Y3. The pin out is a bit different. You will find it in the image


Opamp for your garden


(You may want to have look at the improved version right away)

I admit that this has little to do with Arduino’s, but when working on my previous articles on moisture probes and garden irrigation with an Attiny, I mentioned using op-amp comparators instead of microcontrollers, so I thought I’d publish one like that as well.
The concept of an op-amp comparator is simple, if the ‘+’ gate is higher than the ‘-‘ gate, the output goes high, otherwise it goes low.
So with a humidity sensor attached in dry soil, the resistance of that sensor is high and therefore the voltage on the ‘-‘ gate is low and presumably lower than the voltage on the ‘+’ pin and therefore thge output of the opamp will go high.

This will switch on the Solidstate relay and the pump will start pumping. The water that flows into the plantbed will decrease the resistance between the humidity spikes, th evoltage on the ‘-‘ pin wil rise until it is above the level set with P1, the output will go low and the pump will be switched off.

Instead of a Solidstate relay you can also choose for a regular relay, hence the circuit around T1.

Capacitor C2 is in fact a bit optional. after the output of the op-amp goes low, C2 will still have a bit of charge that will keep the pump turn a little bit longer after the humidity is ‘enough’. It also gives a bit of delay in switching the pump on. This avoids jittering of the pump.

The value of R1 largely depends on the type of soil probe you decide to make. Some people have two spikes close together and that would call for a lower value of R1, some people choose to have the spikes at opposite sides of a plantbed, obviously that calls for a higher value of R1.

It is not really necessary to adapt R1, but if R1 and the resistance of the probe  in ‘almost to dry’ condition are far off, the gain of P1 will be limited.

As this is an Arduino dedicated site, I will pull the arduino in here as well. You could choose not to let the Arduino do the measuring of the soil through its analog gates, but you could hook up th eoutput of the above opamp to a digital port of the Arduino and only let it check high or low.
You could build, say 4 of these circuits, each (use a quad opamp then) and have your arduino just do the measuring of the outputs and take appropriate action.

this is a design that is for toner transfer. So you are looking at it from the pertinax side.  PDF design here. (NOTE There is  new design in which a flaw was eliminated)
Below the component placing on the PCB. Unfortunately (I use a different program for the circuit and the PCB as I dislike Fritzing’s circuit design), the numbering of the components is different, but it does not take a rocket scientist to figure it out.

U3 is the connector for the power. J1 is the connector for the probesu6 is there for a different spacing of the capacitor. U2, U4 and U5 are for a relay. U5 and U2 should be drilled according to the size of the relay you happen to use.
J2 is the switching output of the SSR. The entire PCB is about 4×5 cm.

Mounting components on the PCB

Power supply is 5-10 Volt. Depending on what type 741 you are using it could be up to 18 or 22 volts. If you feed with more than 10 Volts you need to recalculate and adapt the value of R2 in the circuit (unfortunately this has come out as R4 on the PCB design) . The forward voltage on the 39MF22 is 1.2 Volts, for a regular LED that is nominal 2 Volts. So if you would feed with say 15V and say 10 mA, you would need a resistor of  12.8/10=1.28k (say 1.4 k). With the current resistor you would have a current of12.8/0.330=39mA. That is too much for the 39MF22 (max 20 mA). The max supply voltage with the current 330 ohm resistor is in fact 10 Volts (and that is alreday pushing it with 20.6mA).

The current 330 Ohm resistor gives a value of 5.5 mA, which is just above the trigger current of the 39MF22.
Because of variations in resistor values and forward voltages of the LED, 330 might in some instances be just a bit too much if you are feeding the circuit with just 5 volts.  Try 220 or a 180 Ohm resistor then.

You should stick to the following minimal and maximal values of your resistor (in Ohm)

Voltage Min value Max value
5 90 360
6 140 560
7 190 760
8 240 960
9 290 1160
10 340 1360
11 390 1560
12 440 1760
13 490 1960
14 540 2160
15 590 2360
16 640 2560
17 690 2760
18 740 2960

As you may have noticed, there is a small mistake in the PCB design as that the LED and the resistor to the 39MF22 have been switched. This should not make any difference for the SSR version, but it may cause the Relay not to shut off. So if you are making the relay version, just switch the LED and the 330 Ohm (or adapted value) in position: The circuit is right, the PCB is wrong