/* Project: 4 digit 7 segment display module /common cathode/ Thermistor 10 KOhm Function: Temperature displayed on 4 digit 7 segment display */ /****************************************************************************/ const int digitPins[4] = {4,5,6,7}; //4 common cathode pins of the display const int clockPin = 11; //74HC595 Pin 11 SHcp const int latchPin = 12; //74HC595 Pin 12 STcp const int dataPin = 13; //74HC595 Pin 14 DS const int sensorPin =A0; //Thermistor 10 KOhm attached to analog pin A0 const byte digit[10] = //seven segment digits in bits { B11000000, //0 B11111001, //1 B10100100, //2 B10110000, //3 B10011001, //4 B10010010, //5 B10000010, //6 B11111000, //7 B10000000, //8 B10010000 //9 }; int digitBuffer[4] = {0}; int digitScan = 0; double Thermistor(int RawADC) { double Temp; Temp = log(10000.0 * ((1023.0 / RawADC - 1))); Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp )) * Temp ); Temp = Temp - 273.15; Temp = (Temp * 9.0) / 5.0 + 32.0; return Temp; } /**********************************************************************/ void setup(){ for(int i=0;i<4;i++) { pinMode(digitPins[i],OUTPUT); } pinMode(sensorPin, INPUT); pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); Serial.begin(9600); } //writes the temperature on display void updateDisp(){ for(byte j=0; j<4; j++) digitalWrite(digitPins[j], HIGH); digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, B00000000); digitalWrite(latchPin, HIGH); delayMicroseconds(1000); digitalWrite(digitPins[digitScan], LOW); digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]); if(digitScan==2){ shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] & B01111111)); //print the decimal point on the 3rd digit } digitalWrite(latchPin, HIGH); digitScan++; if(digitScan>3) digitScan=0; } void loop(){ double temp; int val = analogRead(sensorPin); temp = Thermistor(val); float celsius = (temp-32)*5/9; //Fahrenheit temperature display - uncomment if you want to use it /* digitBuffer[3] = (int(temp) % 100) / 10; digitBuffer[2] = (int(temp) % 100) % 10; digitBuffer[1] = (int(temp) % 1000) / 100; digitBuffer[0] = int(temp) / 1000; updateDisp(); delay(2); */ //Celsius temperature display - comment if you do not want to use it digitBuffer[3] = (int(celsius) % 100) / 10; digitBuffer[2] = (int(celsius) % 100) % 10; digitBuffer[1] = (int(celsius) % 1000) / 100; digitBuffer[0] = int(celsius) / 1000; updateDisp(); delay(2); }