Created
August 23, 2014 02:39
-
-
Save ledlogic/0aa81e8b138535ad648e to your computer and use it in GitHub Desktop.
LCD display of temp with lcd + onewire + dallas libraries
This file contains hidden or 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 <OneWire.h> | |
#include <DallasTemperature.h> | |
#include <LiquidCrystal.h> | |
// Data wire is plugged into pin 1 on the Arduino | |
#define ONE_WIRE_BUS 1 | |
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |
OneWire oneWire(ONE_WIRE_BUS); | |
// Pass our oneWire reference to Dallas Temperature. | |
DallasTemperature sensors(&oneWire); | |
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel | |
void setup(void) | |
{ | |
lcd.begin(16, 2); // start the library | |
// start serial port | |
Serial.begin(9600); | |
Serial.println("Dallas Temperature IC Control Library Demo"); | |
// Start up the library | |
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement | |
} | |
void loop(void) | |
{ | |
// call sensors.requestTemperatures() to issue a global temperature | |
// request to all devices on the bus | |
Serial.print("Requesting temperatures..."); | |
sensors.requestTemperatures(); // Send the command to get temperatures | |
Serial.println("DONE"); | |
Serial.print("Temperature for Device 1 is: "); | |
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire | |
lcd.setCursor(0, 0); // set the LCD cursor position | |
double data = sensors.getTempCByIndex(0); | |
// print the results to the lcd | |
lcd.print("T: "); | |
lcd.print(data); | |
lcd.print("C "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment