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);
}
}