4 digit 7 segments display with arduino

I want to use three tempature sensors with arduino.I will show each of the temprature values on separate
4 digit of 7 segment display.
Sample program does not work.What should I do? Sample program is shown below.

yedi_segment.ino (1.99 KB)

It is clearly not a large amount of code - why not simply post it?

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile:

Sample program does not work

The code does something. You forget to tell us what it does.

You expect the code to do something. You forgot to tell us what you expect it to do.

We can't help you get from point A to point B without knowing where A and B are.

The code looks OK so I would suspect a hardware problem. Are you using a Common Anode display? The code thinks you are. Do you have resistors on all of the Cathodes to limit the current to 5mA each? If not you need some kind of high-side driver on the Anodes to keep the current being drawn from the digit pins below the 40 mA Absolute Maximum of the Arduino.

const int D1 = 4;
const int D2 = 5;
const int D3 = 6;
const int D4 = 7;
const int digitPins[] = {D1, D2, D3, D4};                 //4 common anode pins of the display
const int clockPin = 11;    //74HC595 Pin 11
const int latchPin = 12;    //74HC595 Pin 12
const int dataPin = 13;     //74HC595 Pin 14
const int tempPin = A0;     //temperature sensor pin
const byte digit[10] =      //seven segment digits in bits
  B00111111, //0
  B00000110, //1
  B01011011, //2
  B01001111, //3
  B01100110, //4
  B01101101, //5
  B01111101, //6
  B00000111, //7
  B01111111, //8
  B01101111,  //9
int digitBuffer[4] = {0};
int digitScan = 0, flag = 0,  soft_scaler = 0;

float tempC, tempK;

void setup() {
  for (int i = 0; i < 4; i++)
    pinMode(digitPins[i], OUTPUT);
  pinMode(tempPin, INPUT);
  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);

  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
    shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
  digitalWrite(latchPin, HIGH);
  if (digitScan > 3) digitScan = 0;

void loop() {
  tempK = analogRead(tempPin);
  //Converts Kelvin to Celsius minus 2.5 deg
  tempC = tempK * 0.4887; //500Volt giriş için 5V karşılık gelen 0.489'un 10 katı alındı
  //tempF = ((tempK - 2.5) * 9 / 5) - 459.67;
  //Celsius temperature display
  tempC = int(tempC * 10);
  digitBuffer[0] = int(tempC) / 1000;
  digitBuffer[1] = (int(tempC) % 1000) / 100;
  digitBuffer[2] = (int(tempC) % 100) / 10;
  digitBuffer[3] = (int(tempC) % 100) % 10;