Help with lcd

Im after some basic advice. I have a ds18b20 tempertaure sensor on my arduino mega and what the temperature to print on my 16x2 lcd screen. What do i need to add to my sketch?
So far my sketch for the sensor is

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire 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();
}

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

}

My lcd came on a shield and the pin numbers are 8,9,4,5,6,7

Thanks

Essentially, you just need to merge two basic programmes.

Ensure

  1. The DS18B20 programme delivers data to the serial monitor OK.
  2. You prove the LCD with a standard “Hello World!” example.

The, using the DS18B20 example, add at the start the LCD stuff

#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);

and in setup

lcd.begin(16, 2);
lcd.print("temp ");

and in the loop

lcd.setCursor (1,1);
lcd.print (tempC);

that should do it

thanks for that. i now have this sketch

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd (8, 9, 4, 5, 6, 7);
// Data wire 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
lcd.begin(16, 2);
lcd.print(“temp”);
Serial.begin(9600);
Serial.println(“Dallas Temperature IC Control Library Demo”);

// Start up the library
sensors.begin();
}

void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
lcd.setCursor (1,1);
lcd.print (tempC);
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
}

i now have an error message which is

sketch_dec12a.ino: In function ‘void loop()’:
sketch_dec12a:34: error: ‘tempC’ was not declared in this scope

Can anyone please help me with this?
thanks

lcd.print (tempC);

There.

Im still getting the error message tempC was not declared in scope

andynkirsty: Im still getting the error message tempC was not declared in scope

Well, where is it declared?

i dont understand i have the data wire of the temp sensor in pin 2. it will print the temperature on the monitor but not on the lcd. what do i need to add to my sketch?

This looks like too much copy-pasting and not enough understanding. But it is possible to solve this problem, since you posted the code.

The original suggestion from Nick was not the complete code. It references a variable called tempC but doesn't define it anywhere and doesn't ever assign it a value. Those parts of the code were skipped by Nick.

The program code needs to work with variables, which are like boxes with names on them. First you have to tell the program what type of thing you are going to put into the box and what name to put on the box. Then when you are using this box in your program, you must put something into the box. Otherwise, if you open the box to look at it (use the value in the variable) then there's no valid value to use. The Arduino environment always puts zero into the box when you first define it but this is not true in most other programming environments so don't ever write a program that depends on this.

To make this simple, I would remove the reference to tempC. Just put the code which prints to the LCD just after the code which prints to Serial and use exactly the same contents:

lcd.print(sensors.getTempCByIndex(0));