Ever have trouble programming code for seven segment displays? Well they made the 4511 to make things a whole lot easier. What the 4511 does is takes a 4 digit binary input value (ones and zeros), and converts it to a decimal value on a seven segment display, it's a really handy chip. In this instructable I'll show you how to use them with the arduino.

## Step 1: Materials

Parts:

1.) Arduino

2.) 4511 binary seven segment decoder

5.) 470 ohm resistor

6.) A to B programming cable

7.) CDS photocell

8.) 10K resistor

Tools:

1.) Computer

2.) A brain :)

## Step 2: How the 4511 Works

The 4511 takes a four-bit binary input on pins 1,2,6, and 7. Then translates it to a decimal output when connected to a seven segment display, which means that instead of programming 7 individual pins each time the display changes digits, you only have to program four. Also, instead of finding the exact led's to turn on for each digit, you just enter a binary value, which leads us to the next step:

## Step 3: A Thing About Binary

For those of you who already are fluent in binary, move on to the next step.

Binary is used in pretty much all mainstream electronics today. It is based on a four digit lines consisting of ones and zeros (each digit is called a bit, each line is called a byte). The first digit in the sequence is equal to one, the second is equal to two, the third is equal to four, and the fourth is equal to eight. So the byte 1001 would be equal to nine (one plus 8). To make it simpler:

Binary:    Decimal:
0000   =   0
0001   =   1
0010   =   2
0011   =   3
0100   =   4
0101   =   5
0110   =   6
0111   =   7
1000   =   8
1001   =   9
and so on... (This is as far as the 4511 will go, since it only has one digit capability, it cannot print 10 or up)

## Step 4: A Simple Timer

The first thing to do is to build a simple proof of concept circuit, a count up timer, and then go from there, for this, you'll need to have everything exept the CDS photocell and the 10K resistor.

## Step 5: Insert the Chip

Insert the chip into the board, make sure to note which way the chip is facing ( where the little notch is o the chip)

## Step 6: Add the Binary Inputs

An easy way to do this is just to use some tiny jumper wires for this, so that you don't have them in your way when you insert other components.

Digital Pin 8 of the Arduino connected to: pin 1 of 4511 (Binary pin 2)

Digital Pin 9 of the Arduino connected to: pin 2 of 4511 (Binary pin 3)

Digital Pin 11 of the Arduino connected to: pin 6 of 4511 (Binary pin 4)

Digital Pin 12 of the Arduino connected to: pin 7 of 4511 (Binary pin 1)

## Step 7: Power the Chip

Pins 3, 16, and 4 are connected to +5v. Pins 8 and 5 are connected to ground.

## Step 8: Connect to the Display

The 4511 works with common cathode (ground) displays only, but most seven segment displays are, so most of the time, you don't have to worry.

A connected to: pin 13 of 4511

B connected to: pin 12 of 4511

C connected to: pin 11 of 4511

D connected to: pin 10 of 4511

E connected to: pin 9 of 4511

F connected to: pin 15 of 4511

G connected to: pin 14 of 4511

Ground pin of the display connected to the ground of Arduino with a 470 to 1K resistor to prevent

## Step 9: The Code:

Alright, now for the fun part!

Here's the code, just copy and paste after this line.

/* Code written and designs made by Kyle Hovey (aka Speleomaniac on www.instructables.com)

For this code, a 4511 binary to seven-segment display decoder is used to make
writing code for displays a whole lot easier (if you happen to have a 4511
lying around somwhere)

Seven segment display:
A connected to: pin 13 of 4511 (the 4511 chip is a 16 prong chip for all wondering)
B connected to: pin 12 of 4511
C connected to: pin 11 of 4511
D connected to: pin 10 of 4511
E connected to: pin 9 of 4511
F connected to: pin 15 of 4511
G connected to: pin 14 of 4511

Arduino to 4511:
Digital Pin 8 connected to: pin 1 of 4511 (Binary pin 2)
Digital Pin 9 connected to: pin 2 of 4511 (Binary pin 3)
Digital Pin 11 connected to: pin 6 of 4511 (Binary pin 4)
Digital Pin 12 connected to: pin 7 of 4511 (Binary pin 1)

Binary:
B:   DEC:
0000: 1
1000: 2
0100: 3
1100: 4
0010: 5
1010: 6
0110: 7
1110: 8
0001: 9 (the 4511 only accepts digits up to nine, the seven segment display
1001: 10 cannot display two-digit numbers unless you have two displays and two chips)
0101: 11
1101: 12
0011: 13
0111: 14
1111: 15

The code for a simple count-up timer:
*/

const int Bin1 = 12; //These are all identifying the binary inputs of
const int Bin2 = 8; //the 4511 Seven Segment Decoder
const int Bin3 = 9;
const int Bin4 = 11;

void setup() //Enters the setup phase
{
pinMode(Bin1, OUTPUT); // sets up binary output one as a digital output
pinMode(Bin2, OUTPUT); //and so on...
pinMode(Bin3, OUTPUT);
pinMode(Bin4, OUTPUT);
}

void loop() // Pretty much just saying "loop whatever code is after this line"
{
digitalWrite(Bin1, B0); //Write "0" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);
delay(500);
digitalWrite(Bin1, B1); //Write "1" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);
delay(500); //Wait for half of a second (or else the numbers would be a blur)
digitalWrite(Bin1, B0); //Write "2" to the display
digitalWrite(Bin2, B1);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);
delay(500); //Wait for half of a second
digitalWrite(Bin1, B1); //Write "3" to the display
digitalWrite(Bin2, B1);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);
delay(500); //Wait for half of a second
digitalWrite(Bin1, B0); //Write "4" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B1);
digitalWrite(Bin4, B0);
delay(500); //Wait for half of a second
digitalWrite(Bin1, B1); //Write "5" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B1);
digitalWrite(Bin4, B0);
delay(500); //Wait for half of a second
digitalWrite(Bin1, B0); //Write "6" to the display
digitalWrite(Bin2, B1);
digitalWrite(Bin3, B1);
digitalWrite(Bin4, B0);
delay(500); //Wait for half of a second
digitalWrite(Bin1, B1); //Write "7" to the display
digitalWrite(Bin2, B1);
digitalWrite(Bin3, B1);
digitalWrite(Bin4, B0);
delay(500); //Wait for half of a second
digitalWrite(Bin1, B0); //Write "8" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B1);
delay(500); //Wait for half of a second
digitalWrite(Bin1, B1); //Write "9" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B1);
delay(500); //Wait for half of a second
}

## Step 10: A Light Meter

I thought it would be cool to take the code from the count up timer, and modify it into a light meter, this is how to do it:

## Step 11: Add the CDS Photocell

Try bending the leads to the photocell so that it is directed away from the Arduino and display to prevent unwanted light.

## Step 12: Power the Photocell

A  resistor is attached to one lead of the photocell to ground. A wire goes from that same lead to analog input 0 of the Arduino. The other lead of the photocell goes to +5v.

## Step 13: The Code

Alright, here's the code, just copy and paste:

/* Code written and designs made by Kyle Hovey (aka Speleomaniac on www.instructables.com)

For this code, a 4511 binary to seven-segment display decoder is used to make
writing code for displays a whole lot easier.

Seven segment display:
A connected to: pin 13 of 4511 (the 4511 chip is a 16 prong chip for all wondering)
B connected to: pin 12 of 4511
C connected to: pin 11 of 4511
D connected to: pin 10 of 4511
E connected to: pin 9 of 4511
F connected to: pin 15 of 4511
G connected to: pin 14 of 4511

Arduino to 4511:
Digital Pin 8 connected to: pin 1 of 4511 (Binary pin 2)
Digital Pin 9 connected to: pin 2 of 4511 (Binary pin 3)
Digital Pin 11 connected to: pin 6 of 4511 (Binary pin 4)
Digital Pin 12 connected to: pin 7 of 4511 (Binary pin 1)

CDF to arduino:
10K resistor attatched to ground and  analog out wire from one pin
of the CDF, other pin of CDF cell is attatched to +5v.

Binary:
B:   DEC:
0000: 0
1000: 2
0100: 3
1100: 4
0010: 5
1010: 6
0110: 7
1110: 8
0001: 9 (the 4511 only accepts digits up to nine, the seven segment display
1001: 10 cannot display two-digit numbers unless you have two displays and two chips)
0101: 11
1101: 12
0011: 13
0111: 14
1111: 15

The code for a digital light meter on a seven segment display.
*/

const int Bin1 = 12; //These are all identifying the binary inputs of
const int Bin2 = 8; //the 4511 Seven Segment Decoder
const int Bin3 = 9;
const int Bin4 = 11;
int val = 0;
int CDSpin = 0;

void setup() //Enters the setup phase
{
pinMode(Bin1, OUTPUT); // sets up binary output one as a digital output
pinMode(Bin2, OUTPUT); //and so on...
pinMode(Bin3, OUTPUT);
pinMode(Bin4, OUTPUT);
Serial.begin(9600);
}

void loop() // Pretty much just saying "loop whatever code is after this line"
{
val = analogRead(CDSpin); //Sets the analog value "val" to the ambient light level.
val = map(val, 0, 1029, 0, 100); //Scale down the value from 1029-max to 100-max
Serial.println(val, DEC);
delay(10); //Wait for arduino to catch up
if (val == 0 || val == 1) //if the value is at minimum:
{
digitalWrite(Bin1, B0); //Write "0" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);
}
if (val > 1 && val <= 10) //if the value is between one and ten:
{
digitalWrite(Bin1, B1); //Write "1" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);
}
if (val > 10 && val <= 20) //if the value is between ten and twenty:
{
digitalWrite(Bin1, B0); //Write "2" to the display
digitalWrite(Bin2, B1);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);
}
if (val > 20 && val <= 30) //if the value is between twenty and thirty:
{
digitalWrite(Bin1, B1); //Write "3" to the display
digitalWrite(Bin2, B1);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);
}
if (val > 30 && val <= 40) //if the value is between thirty and fourty:
{
digitalWrite(Bin1, B0); //Write "4" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B1);
digitalWrite(Bin4, B0);
}
if (val > 40 && val <= 50) //if the value is between fourty and fifty:
{
digitalWrite(Bin1, B1); //Write "5" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B1);
digitalWrite(Bin4, B0);
}
if (val > 50 && val <= 60) //if the value is between fifty and sixty:
{
digitalWrite(Bin1, B0); //Write "6" to the display
digitalWrite(Bin2, B1);
digitalWrite(Bin3, B1);
digitalWrite(Bin4, B0);
}
if (val > 70 && val <= 80) //if the value is between sixty and seventy:
{
digitalWrite(Bin1, B1); //Write "7" to the display
digitalWrite(Bin2, B1);
digitalWrite(Bin3, B1);
digitalWrite(Bin4, B0);
}
if (val > 80 && val <= 90) //if the value is between eighty and ninety:
{
digitalWrite(Bin1, B0); //Write "8" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B1);
}
if (val > 90 && val <= 100) //if the value is between ninety and wne hundred;
{
digitalWrite(Bin1, B1); //Write "9" to the display
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B1);
}
}

## Step 14: Thanks for Viewing!

Any questions, comments or ideas, feel free to comment, happy experimenting!
<p>Thanks for the tutorial, it was nice having all the information in one place to follow along with. I coded it a little differently for brevity: https://gist.github.com/myanaros/7bd3b39e1d29836cc9c50315be3839af</p>
IIRC, a 4511 should go to 15, as it should support HEX.<br /> So it would be 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.<br />
<p>The '4511 chip does not support HEX -- it shows a blank display for inputs above 9. Perhaps you are thinking of other very similar seven-segment decoder-driver chips? Perhaps the Motorola MC14495 chip, which displays all 16 HEX digits? Or chips that at least show unique symbols for inputs above 9 -- such as the 74LS47, 74LS48, 74LS49, 74LS247, 74LS248, etc.?</p>
the chip I worked with did not support letter readouts
<div> Thanks for the wonderful info. Kindly could you help me with information/schematics on how I can use the CD4511 chip with ARDUINO MEGA 2560 R3 to RUN a 3 digit seven segment display.I want to display 0---999. please feel free to email me: mrshorty105@gmail.com. Thank you.<br> <br> &nbsp;</div>
this is so funny, i did the exact same thing when i first got my arduino and wanted to control a 7 segment led display. and i had the electronics learning lab from radioshack, and the IC which came with it. i love that lab, it is so useful for prototyping.
Couple questions.. Wouldn't it be easier to map the 10bits of CdS values to 0 - 9 and have the if statements just say if(val == 0 ){ // send 0 in binary} and i believe the analog inputs are between 0 - 1023 rather than to 1029
Yes, actually much easier. If I were to go back and make the code again I would make a lot of changes. I made this instructables when I was relatively new to Arduino.