Introduction: Temperature Displayed on 4 Digit 7 Segment (common Anode)
In this project I’ll display the temperature in a 4 digit 7 segment display (common anode).
The sensor is the cheapest you can find so actually the temperature changes pretty easily which makes the display to show always different temperatures. But the idea is to apply this code to other projects with 7 segment displays that I might do later. if you want to learn a bit more of 7 segment displays you can read more at this post I've made.
This project is great to learn more about:
http://randomnerdtutorials.com/
You can see this project working right now:
The sensor is the cheapest you can find so actually the temperature changes pretty easily which makes the display to show always different temperatures. But the idea is to apply this code to other projects with 7 segment displays that I might do later. if you want to learn a bit more of 7 segment displays you can read more at this post I've made.
This project is great to learn more about:
- Reading sensors (in this case temperature)
- 7 segment displays (4 digit 7 segment displays)
- 8 bit Shift Registers (74HC595)
- Pratice wiring
http://randomnerdtutorials.com/
You can see this project working right now:
Step 1: Parts Required
- 1x Arduino Uno
- 1x Temperature Sensor (I’m using the LM335Z)
- 1x 4 Digit 7 Segment Display (common anode)
- 1x 74HC595 8 Bit Shift Register
- 8x 220 Ohm Resistors
- 1x 4700 ohm Resistor
- 1x Breadboard (or two)
- Jumper Cables
Step 2: Schematics
I think it's a bit hard to follow the yellow connections with this schematic.
So i recommend that you take a look at the 74HC595 pins and to the internal circuit diagram of the 4 digit 7 segment display (common anode).
So how does the yellow connections were made?
Basically the pin 11 connects to the QA, the pin 7 to the QB and so one…
Step 3: Upload the Code
You can find the code here: https://gist.github.com/ruisantos16/5419223
Step 4: Final Product
Check this video to see the circuit in action!
you can also visit my website for more electronic projects, interesting news and tips
you can also visit my website for more electronic projects, interesting news and tips
32 Comments
Question 2 years ago
I have a problem, that the display is displaying only one digit at time. I know that it couldn't be done differently but the changing between the digits is too slow.
Here is my code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const byte addresses[][6] = {"00001", "00002"};
float angley;
const int digitPins[4] = {
A1,A2,A3,A4}; //4 common anode pins of the display
const int clockPin = 10; //74HC595 Pin 11
const int latchPin = 9; //74HC595 Pin 12
const int dataPin = 6; //74HC595 Pin 14
const byte digit[10] = //seven segment digits in bits
{
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100100, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111 //9
};
int digitBuffer[4] = {
0};
int digitScan = 0, flag=0, soft_scaler = 0;
;
void setup(){
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1, addresses[0]);
radio.setPALevel(RF24_PA_LOW);
for(int i=0;i<4;i++)
{
pinMode(digitPins[i],OUTPUT);
}
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
//writes the temperature on display
void updateDisp(){
for(byte j=0; j<4; j++)
digitalWrite(digitPins[j], LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
digitalWrite(latchPin, HIGH);
delayMicroseconds(100);
digitalWrite(digitPins[digitScan], HIGH);
digitalWrite(latchPin, LOW);
if(digitScan==2)
shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] | B10000000)); //print the decimal point on the 3rd digit
else
shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
digitalWrite(latchPin, HIGH);
digitScan++;
if(digitScan>3) digitScan=0;
}
void loop(){
radio.startListening();
if (radio.available()) {
radio.read(&angley, sizeof(angley));
delay(100 * sizeof(angley));
angley = int(angley*100);
Serial.println(angley);
digitBuffer[3] = int(angley)/1000;
digitBuffer[2] = (int(angley)%1000)/100;
digitBuffer[1] = (int(angley)%100)/10;
digitBuffer[0] = (int(angley)%100)%10;
updateDisp();
}
}
7 years ago
just to clear things out :
segments pins pinout :
74hc595 -- 7 segments
15 = a
1 = b
2 = c
3 = d
4 = e
5 = f
6 = g
Reply 5 years ago
DP pin on the display to be connected to QH?
Reply 3 years ago
Just to try to prevent any future confusion on the pins of the 595, Remember to keep an eye on which the [QH] & the [QH'] notice the ' mark on the #9 pin. A helpful reminder for any new users> the #7Pin QH Is a normal output, where the
#9PinQH' (with the accent) is for daisy-chaining to another shift register's SER pin14.
Not too confusing, but I feel like they could have been more clear when coming up with the pin numbering scheme🤦♂️lol... enjoy!
Reply 5 years ago
Hi, Im still a beginner at this but I find your comment a lot clearer than the schematic Im following, but Im still in the process of clearing things out, I hope you could help me where to connect the skyblue wires in the 7segment display.. Thank you so much!
Tip 4 years ago
import RPi.GPIO as GPIO
import time
dataPin = 17 # 74HC595 Pin 14 (SDI)
latchPin = 18 # 74HC595 Pin 12 (RCLK)
clockPin = 27 # 74HC595 Pin 11 (SRCLK)
digitPins = [22,23,24,25] # 4 common anode pins of the display
digit = [0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff] # [0,1,2,3,4,5,6,7,8,9, ]
digitBuffer = []
sampleFreq = 60 #time in seconds
def setup():
GPIO.setup(dataPin, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(latchPin, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(clockPin, GPIO.OUT, initial=GPIO.LOW)
for i in range(len(digitPins)):
# Shift the data to 74HC595
def hc595_shift(dat):
GPIO.output(clockPin, GPIO.HIGH)
GPIO.output(clockPin, GPIO.LOW)
GPIO.output(latchPin, GPIO.LOW)
# writes the temperature on display
def updateDisp():
while True:
GPIO.output(digitPins[digitScan], GPIO.HIGH)
hc595_shift(digit[digitBuffer[digitScan]])
digitScan += 1
if digitScan > 3:
def main():
while True:
strTemp = str(highTemp)
digitBuffer = []
for i in range(4-int(len(strTemp))):
updateDisp()
time.sleep(sampleFreq)
def destroy():
try: main()
except KeyboardInterrupt:
4 years ago
Thanks Rui for this awesome project. I managed to get it working to display distance measured in meters using a HC-SR04 sensor. As the display flickers due to sensor delay, it is not letting me stabilize the display completely, but using NewPing library for the sensor, I was able to reduce the flicker to a reasonable extent. I have used a common cathode 4-digit 7-segment display and the instructions in the comment by Raphango helped me in making it work. Keep up the good work sir!
5 years ago
I tried to make, and it didn't work as expected.
The display says: 2.2.2.2 (or 8.8.8.8. some LEDs aren't lit up all the way.) I've checked everything, wiring and the code, and everything is correct exept the result.
any suggestions?
(I use LM 35)
5 years ago
It didn't work for me, I checked everything. The display says 2.2.2.2.( or actually 8.8.8.8. but some LEDs don't light 100% up)
any ideas to find out what's wrong?
I checked the wiring and coding.
5 years ago
Hello,
first of all, great work! this was the first tutorials that actually worked for me.
i just have a small question: is it possible, to set the display let say "1234" in the setup and leave it like that, without refreshing in every loop? In my project I'm using a ultrasonic sensor parallel to the segment display and the delays cause some trouble(the segment display isn't refreshing fast enough).
mabye you have an idea to solve such a problem.
thanks in advance and keep up the good work ;)
Reply 5 years ago
if you input any piece of code in the void setup(){} area of code it runs it on a single static system. This means it will only run it once, and the code won't refresh as setup() is not a loop system.
5 years ago
How can I do this same project but using the atmega328p on a breadboard and using a c programming language..any tutorial links will be greatly appreciate..ty..
5 years ago
is it ok i will use lm 35 temperature sensor?
Reply 5 years ago
The one used in this tutorial is a LM35 so you're good I think :P ( I'm pretty sure).
5 years ago
and can anyone send me the schematics for the (common cathode) display ? please.
5 years ago
will this work with mega 2560 ?
5 years ago
Excellent project! Is there anyway to get it to read negative temps. I'm trying to with the DS18B20 but cannot seem to get the code to work right. I removed the 100's place to just a 10's decimal like 20.2 instead of 20.22 to make the left most digit for minus sign. Also, is there a way to drop the leading zero on the left digit? It now comes up as 020.2 or 002.2 . Many thanks!
6 years ago
Hi. Nice project. Im very beginner for arduino.
Could you post circuit diagram of your project?
9 years ago on Introduction
What if I'm using a common cathode 4 digit 7 segment? Does it changes the cirtuit/code very bad?
Reply 9 years ago on Introduction
yeah it actually changes the code and the circuit a bit... but it's totally possible!
if you make a quick search you'll see the difference and what you have to change.
I hope this helps! thanks for commenting!