Last active
June 2, 2016 11:07
-
-
Save nickrobson/c8d188520982a1877f68ae4e3982e861 to your computer and use it in GitHub Desktop.
Read a temperature from A0, print to LCD at 0x3F.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
#define I2C_ADDR 0x3F | |
#define TEMP_SENSOR A0 | |
LiquidCrystal_I2C lcd(I2C_ADDR, 20, 4); | |
void setup() { | |
lcd.init(); | |
lcd.begin(16, 2); | |
lcd.backlight(); | |
uint8_t degree[8] = { 0b0110, 0b1001, 0b1001, 0b0110 }; | |
lcd.createChar(0, degree); | |
} | |
void loop() { | |
int tempRead = analogRead(TEMP_SENSOR); | |
float voltage = tempRead * 5.0 / 1024.0; | |
lcd.setCursor(0, 0); | |
lcd.print(String(voltage)); | |
lcd.print(" volts"); | |
// now print out the temperature | |
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset to degrees ((voltage - 500mV) times 100) | |
lcd.setCursor(0, 1); | |
lcd.print(String(temperatureC)); | |
lcd.write(0); | |
lcd.print("C"); | |
delay(1000); //waiting a second | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment