Go Down

Topic: DS18B20 Digital Thermometer with 4 Digit 7 Segment Display (Read 1 time) previous topic - next topic


For my first Arduino project I'm trying to use a 4 digit 7 segment display to display the temperature captured by DS18B20. I'm using two shift registers to control the display, as per http://tronixstuff.wordpress.com/2010/05/14/getting-started-with-arduino-chapter-six/. My problem is that when I run the code (partially shown):

void cleardisplay() //turn off all segments of all digits
  for (int a=0;a<4;a++)
    shiftOut(datapin,clockpin,MSBFIRST,posdisp[a]); //select position to clear
    shiftOut(datapin,clockpin,MSBFIRST,0); //clear selected position

void digdisp(int digit, int location)
  shiftOut(datapin,clockpin,MSBFIRST,posdisp[location]); //put input number in correct location
  shiftOut(datapin,clockpin,MSBFIRST,segdisp[digit]); //display input number

void getTemperature()
  sensors.requestTemperatures(); // Send the command to get temperatures
  temperatureValue = sensors.getTempCByIndex(0);
  Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"?

void TDisplay(int value)


void loop()

The display flickers, because getTemperature() in the loop is turning off the display every time it retrieves new temperature data. Ideally I want to keep the TDisplay digits showing on the foreground while I get new temperature data, and then replace the old digits on the display with new ones, but I'm not sure how I would go about doing that. Any advice is appreciated!


You're reading the temperature every time you have displayed your characters so your sketch is spending most of it's time reading the temperature and not so much time displaying the characters.
It's probably enough to read the temperature once a second (or once every 30 seconds).
Use the millis counter to determine how long it is since you last did a getTemperature() and do it only when a certain amount of time has passed.
See the Blink Without Delay example: http://arduino.cc/en/Tutorial/BlinkWithoutDelay

You could also use some other external chip like a MAX7219 to handle the 4 segment display and not have to worry a bit about flicker while you process other things but it should also be possible to reduce the flickering with your current setup by not reading the temperature in every loop.

Thanks for the help. I tried putting millis() into the code, and while it did improve the flickering, I was still not satisfied. So I bought some MAX7219 and will just let it drive the display while Arduino takes care of the temperature.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131