7 Segment Displays

As a part of my project to build a breathalyzer using the MQ-3, I needed a nice way of displaying how much drink you've had. I had some 7-segment displays in my box of stuff that I had bought previously. They are from futurlec. Datasheets can be found by googling 7DR8021BS.


2-digit 7-segment display (I accidentally blew the middle decimal point, which is why you cant see it - its blacked out with some texta).

These 7-segs use common outputs for each segment, and a separate input for each digit:


The segments are labelled as in the next image - I believe this is standard.


Since the outputs are common I had to switch between digit #0 and digit #1 really quickly while at the same time connecting the outputs to ground to make whatever digit I want display. I could have used a 4511 driver chip for this, but I still need some transistors to connect the output to ground. Also the 4511 only drives 7 segments (so no decimal point) so instead I decided to use a 595 shift register. Same amount of pins on my Arduino to drive it, but more outputs!

My initial design used a bunch of discrete transistors, but this got messy fast. Even though it worked, I wasn't satisfied. It also meant a HEAP of extra soldering if/when I put this on perfboard:


Original design - note the upside-down arduino to control it.


Too many transistors!


As I refined my design, I discovered that you can get a transistor array on an IC - the ULN2803a. This IC has a common ground, so it switches directly to ground - which is ideal for these displays.

When coding for a setup such as this, you just need to switch stuff super fast. The first thing I did was work out what number (in binary) represented each digit I wanted to display. Then you just turn off everything, shift the digit into the shift-register (to drive the transistors) and turn on one of your inputs. Then repeat. eg:

for(;;)
{
turn off both of your inputs (digit 0 and 1)
shift some data into the 595 chip to set-up the output transistors for digit 0
turn on input 0
sleep for a milli or something (not strictly necessary)

turn off both of your inputs (digit 0 and 1)
shift some data into the 595 chip to set-up the output transistors for digit 1
turn on input 1
sleep for a milli or something (not strictly necessary)
}

Theres obviously a bit more code around it than this, but you get the idea.

Comments