For my first Arduino based project I decided to take the output of am LM34 Fahrenheit temperature sensor (could be adapted for the LM35 easily) and have it read out on a 2 digit 7 segment display. You can see my horrid code and a flash-annihiliated picture below. The jumper wires were precut standard lengths, so it isn't pretty, but it works. The ICs are 74LS48 7-segment display drivers. They convert a BCD number into the 7 signals required to make the equivalent decimal number. Hope someone finds this useful.
int MSBpins[] = {2,5,4,3}; // digital pins to use for the MSB 7-segment display
int LSBpins[] = {8,11,10,9}; // digital pins to use for the LSB 7-segment display
int sensor_pin = 0; // the analog pin for LM34 temp sensor
float sensor_reading = 0.0; // variable to store the value coming from the sensor
float vref = 1.084; // variable to store the voltage reference used (check for validity with a DMM)
int fahrenheit = 0; // variable to store the actual temperature
int acquisition_timer = 1000; // variable to control the time between updates (in ms)
int MSBdecimal = 0; // variable to store the decimal MSB of the fahrenheit temperature
int LSBdecimal = 0; // variable to store the decimal LSB of the fahrenheit temperature
void setup()
{
pinMode( sensor_pin, INPUT ); // set LM34 temp sensor pin as an input
analogReference(INTERNAL); // set the analog reference to the 1.1V internal reference
for ( int i = 0; i < 4; i++ ) // set all pins mentioned in the arrays to outputs
{
pinMode( MSBpins[i], OUTPUT );
pinMode( LSBpins[i], OUTPUT );
}
delay(1000);
}
void loop()
{
sensor_reading = analogRead(sensor_pin); // stores the digitized (0 - 1023) analog reading from the LM34
fahrenheit = (100.0 * sensor_reading * vref)/1023; // calculates the actual fahrenheit temperature
MSBdecimal = fahrenheit / 10; // separates the MSB of the fahrenheit temperature and stores it
LSBdecimal = fahrenheit % 10; // separates the LSB of the fahrenheit temperature and stores it
switch(MSBdecimal)
{
case 0:
digitalWrite( MSBpins[0] , LOW );
digitalWrite( MSBpins[1] , LOW );
digitalWrite( MSBpins[2] , LOW );
digitalWrite( MSBpins[3] , LOW );
break;
case 1:
digitalWrite( MSBpins[0] , LOW );
digitalWrite( MSBpins[1] , LOW );
digitalWrite( MSBpins[2] , LOW );
digitalWrite( MSBpins[3] , HIGH );
break;
case 2:
digitalWrite( MSBpins[0] , LOW );
digitalWrite( MSBpins[1] , LOW );
digitalWrite( MSBpins[2] , HIGH );
digitalWrite( MSBpins[3] , LOW );
break;
case 3:
digitalWrite( MSBpins[0] , LOW );
digitalWrite( MSBpins[1] , LOW );
digitalWrite( MSBpins[2] , HIGH );
digitalWrite( MSBpins[3] , HIGH );
break;
case 4:
digitalWrite( MSBpins[0] , LOW );
digitalWrite( MSBpins[1] , HIGH );
digitalWrite( MSBpins[2] , LOW );
digitalWrite( MSBpins[3] , LOW );
break;
case 5:
digitalWrite( MSBpins[0] , LOW );
digitalWrite( MSBpins[1] , HIGH );
digitalWrite( MSBpins[2] , LOW );
digitalWrite( MSBpins[3] , HIGH );
break;
case 6:
digitalWrite( MSBpins[0] , LOW );
digitalWrite( MSBpins[1] , HIGH );
digitalWrite( MSBpins[2] , HIGH );
digitalWrite( MSBpins[3] , LOW );
break;
case 7:
digitalWrite( MSBpins[0] , LOW );
digitalWrite( MSBpins[1] , HIGH );
digitalWrite( MSBpins[2] , HIGH );
digitalWrite( MSBpins[3] , HIGH );
break;
case 8:
digitalWrite( MSBpins[0] , HIGH );
digitalWrite( MSBpins[1] , LOW );
digitalWrite( MSBpins[2] , LOW );
digitalWrite( MSBpins[3] , LOW );
break;
case 9:
digitalWrite( MSBpins[0] , HIGH );
digitalWrite( MSBpins[1] , LOW );
digitalWrite( MSBpins[2] , LOW );
digitalWrite( MSBpins[3] , HIGH );
break;
default:
digitalWrite( MSBpins[0] , HIGH );
digitalWrite( MSBpins[1] , HIGH );
digitalWrite( MSBpins[2] , HIGH );
digitalWrite( MSBpins[3] , HIGH );
break;
}
switch(LSBdecimal)
{
case 0:
digitalWrite( LSBpins[0] , LOW );
digitalWrite( LSBpins[1] , LOW );
digitalWrite( LSBpins[2] , LOW );
digitalWrite( LSBpins[3] , LOW );
break;
case 1:
digitalWrite( LSBpins[0] , LOW );
digitalWrite( LSBpins[1] , LOW );
digitalWrite( LSBpins[2] , LOW );
digitalWrite( LSBpins[3] , HIGH );
break;
case 2:
digitalWrite( LSBpins[0] , LOW );
digitalWrite( LSBpins[1] , LOW );
digitalWrite( LSBpins[2] , HIGH );
digitalWrite( LSBpins[3] , LOW );
break;
case 3:
digitalWrite( LSBpins[0] , LOW );
digitalWrite( LSBpins[1] , LOW );
digitalWrite( LSBpins[2] , HIGH );
digitalWrite( LSBpins[3] , HIGH );
break;
case 4:
digitalWrite( LSBpins[0] , LOW );
digitalWrite( LSBpins[1] , HIGH );
digitalWrite( LSBpins[2] , LOW );
digitalWrite( LSBpins[3] , LOW );
break;
case 5:
digitalWrite( LSBpins[0] , LOW );
digitalWrite( LSBpins[1] , HIGH );
digitalWrite( LSBpins[2] , LOW );
digitalWrite( LSBpins[3] , HIGH );
break;
case 6:
digitalWrite( LSBpins[0] , LOW );
digitalWrite( LSBpins[1] , HIGH );
digitalWrite( LSBpins[2] , HIGH );
digitalWrite( LSBpins[3] , LOW );
break;
case 7:
digitalWrite( LSBpins[0] , LOW );
digitalWrite( LSBpins[1] , HIGH );
digitalWrite( LSBpins[2] , HIGH );
digitalWrite( LSBpins[3] , HIGH );
break;
case 8:
digitalWrite( LSBpins[0] , HIGH );
digitalWrite( LSBpins[1] , LOW );
digitalWrite( LSBpins[2] , LOW );
digitalWrite( LSBpins[3] , LOW );
break;
case 9:
digitalWrite( LSBpins[0] , HIGH );
digitalWrite( LSBpins[1] , LOW );
digitalWrite( LSBpins[2] , LOW );
digitalWrite( LSBpins[3] , HIGH );
break;
}


