// Digital thermometer with Arduino and LM335 temperature sensor // include LCD library code #include #define LM335_pin 0 // LM335 output pin is connected to Arduino A0 pin // LCD module connections (RS, E, D4, D5, D6, D7) LiquidCrystal lcd(2, 3, 4, 5, 6, 7); void setup() { // set up the LCD's number of columns and rows lcd.begin(16, 2); } char message1[] = "Temp = 00.0 C"; char message2[] = "= 00.0 K"; int Kelvin, Celsius; void loop() { delay(1000); // Wait 1s between readings Kelvin = analogRead(LM335_pin) * 0.489; // Read analog voltage and convert it to Kelvin (0.489 = 500/1023) Celsius = Kelvin - 273; // Convert Kelvin to degree Celsius if(Celsius < 0){ Celsius = abs(Celsius); // Absolute value message1[7] = '-'; // Put minus '-' sign } else message1[7] = ' '; // Put space ' ' if (Celsius > 99) message1[7] = '1'; // Put 1 (of hundred) message1[8] = (Celsius / 10) % 10 + 48; message1[9] = Celsius % 10 + 48; message1[12] = 223; // Put degree symbol message2[2] = (Kelvin / 100) % 10 + 48; message2[3] = (Kelvin / 10) % 10 + 48; message2[4] = Kelvin % 10 + 48; lcd.setCursor(0, 0); lcd.print(message1); lcd.setCursor(5, 1); lcd.print(message2); }