I^2C Temperature Sensor Configured with LCD screen and Buttons

//Reads Temp from I2C temperature sensor and prints it on the serial port
//Include Wire I2C library
#include <Wire.h>
#include <LiquidCrystal.h>

//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int temp_address = 72; //1001000 written as decimal number
int speaker = 8;
void setup()

{
 //Start serial communication at 9600 baud
Serial.begin(9600);
 //Create a Wire object
 Wire.begin();
 lcd.begin(16,2);
}
void loop()
{
 //Send a request//Start talking to the device at the specified address
 Wire.beginTransmission(temp_address);
 //Send a bit asking for register zero, the data register
 Wire.write(0);
 //Complete Transmission
 Wire.endTransmission();
 //Read the temperature from the device
 //Request 1 Byte from the specified address
 Wire.requestFrom(temp_address, 1);
 //Wait for response
 while(Wire.available() == 0);
 //Get the temp and read it into a variable
 int c = Wire.read();
 //Do some math to convert the Celsius to Fahrenheit
 int f = round(c*9.0/5.0 +32.0);
 //Send the temperature in degrees C and F to the serial monitor
 Serial.print(c);
 Serial.print("C ");
 Serial.print(f);
 Serial.println("F");
 delay(500);


 int sensorValue = analogRead(A0);
 // print out the value you read:
 Serial.println(sensorValue);

 if (1000 < sensorValue && sensorValue<1024){
  lcd.clear();
 }
 else if (100 <sensorValue && sensorValue < 190){
  lcd.print(f);
  lcd.print(" F ");
 
 }
 else if (500 < sensorValue && sensorValue < 510){
  lcd.print(c);
  lcd.print(" C ");
 }
 else{
  lcd.clear();
 }


}

Comments

Popular posts from this blog

Seismic Code

Strings

BMP180 Code + Library to SD card