Looking to display 2 temperatures on LCD using DS18B20 sensors. The sensors are working on the serial monitor but not on the LCD. Could anyone help. My code can be seen below.
/********************************************************************/
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
int sensorVal1 = A1;
int sensorVal2 = A2;
/********************************************************************/
// Data wire for temp in is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
/********************************************************************/
// 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);
/********************************************************************/
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
//Declare Inputs
pinMode(sensorVal1, INPUT);
pinMode(sensorVal2, INPUT);
}
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 temperature readings
Serial.println("DONE");
lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
lcd.print("Temp Inside: "); // Prints Sensor Val: to LCD
lcd.print(analogRead(sensorVal1)); // Prints value on sensorVal1 to LCD
lcd.setCursor(0,1); // Sets the cursor to col 1 and row 0
lcd.print("Temp Outside: "); // Prints Sensor Val: to LCD
lcd.print(analogRead(sensorVal2)); // Prints value on sensorVal2 to LCD
/********************************************************************/
Serial.print("Temperature out: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 0 refers to the first IC on the wire
delay(1000);
{
Serial.print("Temperature in: ");
Serial.print(sensors.getTempCByIndex(1)); // Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 1 refers to the second IC on the wire
delay(1000);
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
You aren't printing the DS18B20 temperatures to the lcd. You are printing the value of analogRead(sensorVal1) and analogRead(sensorVal2).
Pete
Sorry Im new to this. Do i have to get the addresses of the sensors and declare them. Any help with the code would be great as im not really sure what to do here.
Instead of this:
lcd.print(analogRead(sensorVal1));
use this:
lcd.print(sensors.getTempCByIndex(0));
and do the same for the other sensor.
You will need to know the address of at least one of the DS18B20s if you want to be able to which printed temperature corresponds to which DS18B20. The comments in the code that "0 refers to the first IC on the wire" and "1 refers to the second IC on the wire" are very misleading.
I explain how the DS18B20 sensors are enumerated on the bus in this thread and see also this thread where I post a sketch which lists 9 DS18B20 addresses and their bit-reversed form (which is the order used by the Dallas Temperature library).
Pete
I have two ds18b20 sensors on the circuit but they are not displaying to the LCD. When i open the serial monitor the sensors seem to be working fine and are give the values but the LCD has different values for both readings. I have just noticed that one of the values is approx ten times higher than the other on the LCD. Could anyone help with this please. My code can be seen below.
/********************************************************************/
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
int sensorVal1 = A1;
int sensorVal2 = A1;
/********************************************************************/
// Data wire for temp in is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
/********************************************************************/
// 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);
/********************************************************************/
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
//Declare Inputs
pinMode(sensorVal1, INPUT);
pinMode(sensorVal2, INPUT);
}
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 temperature readings
Serial.println("DONE");
lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
lcd.print("Temp Inside: "); // Prints Sensor Val: to LCD
lcd.print(analogRead(sensors.getTempCByIndex(0)); // Prints value on sensorVal1 to LCD
lcd.setCursor(0,1); // Sets the cursor to col 1 and row 0
lcd.print("Temp Outside: "); // Prints Sensor Val: to LCD
lcd.print(analogRead(sensors.getTempCByIndex(1)); // Prints value on sensorVal2 to LCD
/********************************************************************/
Serial.print("Temperature out: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 0 refers to the first IC on the wire
delay(1000);
{
Serial.print("Temperature in: ");
Serial.print(sensors.getTempCByIndex(1)); // Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 1 refers to the second IC on the wire
delay(1000);
}
}
Kindly reformat the program codes of your post in accordance with the following instructions:
(a) Open your post in the Edit/Modify Mode.
(b) Bring the cursor at the very beginning of your code. Now, type this word: [ c o d e ]. Please, do not keep spaces among the letters while typing the word. Keep them together. I have to keep spaces due to some technical reasons.
(c) Bring the cursor at the very end of your code. Now, type this word: [ / c o d e ]. Please, do not keep spaces among the letters while typing the word. Keep them together. I have to keep spaces due to some technical reasons.
(d) Press the save button.
Now, your codes/post looks so beautiful!
Kindly reformat the program codes of your post . . .
Good idea.
. . . in accordance with the following instructions:
AARRGGHH
Simply highlight the code and use the 'code' button. It's the one at the left that looks like this: </>
Don
Thanks. Im only new to this so sorry about that. Any ideas of what im doing wrong.
Any ideas of what im doing wrong.
You have to convert the raw data that you got from the DS18B20 into the ASCII codes corresponding to that data before you can display it on the LCD. Look into the dtostrf() function.
EDIT: On second thought - why are you using 'analog read'?
EDIT: On third thought - it looks like you already got the answer previously --> multiple DS18B20 to 16x2 LCD - #4 by el_supremo - Project Guidance - Arduino Forum
Don
Thanks. Im only new to this so sorry about that. Any ideas of what im doing wrong.
There are compilation errors in your codes. I had to make a real setup on UNO and execute your codes. Please, compare the code that you have posted with the codes that I have posted below (after editing and executing your codes), you will be able to find the mistakes.
Please don't forget to connect a 2.2k resistor between Pin-2 of DS18B20 and 5V.
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//int sensorVal1 = A1;
//int sensorVal2 = A1;
/********************************************************************/
// Data wire for temp in is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
/********************************************************************/
// 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);
/********************************************************************/
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
lcd.print("OK!");
//Declare Inputs
// pinMode(sensorVal1, INPUT);
// pinMode(sensorVal2, INPUT);
}
void loop(void)
{
// Serial.println(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperature readings
// Serial.println("DONE");
//lcd.setCursor(0, 0); // Sets the cursor to col 0 and row 0
// lcd.print("Temp Inside: "); // Prints Sensor Val: to LCD
// lcd.print(analogRead(sensors.getTempCByIndex(0))); // Prints value on sensorVal1 to LCD
// lcd.setCursor(0, 1); // Sets the cursor to col 1 and row 0
// lcd.print("Temp Outside: "); // Prints Sensor Val: to LCD
// lcd.print(analogRead(sensors.getTempCByIndex(1))); // Prints value on sensorVal2 to LCD
{
Serial.print("Temperature out: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 0 refers to the first IC on the wire
//delay(2000);
Serial.print(" ");
Serial.print("Temperature in: ");
Serial.println(sensors.getTempCByIndex(1)); // Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 1 refers to the second IC on the wire
// delay(2000);
}
{
lcd.setCursor(0, 0);
lcd.print("Temp Out: ");
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(0, 1);
lcd.print("Temp In:: ");
lcd.print(sensors.getTempCByIndex(1));
}
delay(2000);
}
Please, STOP cross post (the very same subject in various sections). I have reported it to the Moderator.
Edit: Please, STOP cross post (the very same subject in various sections). I have reported it to the Moderator. (I am taking back the red color from the word STOP.)
Please don't forget to connect a 2.2k resistor between Pin-2 of DS18B20 and 5V.
You might also consider using the value recommended in the data sheet, 4.7k.
Don