Go Down

Topic: LCD and Dallas 18B20 (Read 2051 times) previous topic - next topic

david95

Hi guys I've got an 16x2 LCD and I just tried it with this code:
Code: [Select]

/*
  LiquidCrystal Library - Hello World

Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.

This sketch prints "Hello World!" to the LCD
and shows the time.

  The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)

Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

and it works perfectly.
Now, I wanted to register the temperature too, so, how do I connect my 18B20 to the Arduino board do make it work???
What code do I need to insert?
I've already got the DallasTemperature library and the 18B20 arduino temperature library, but I'm a newbie so I don't know :P

Nick_Pyner

I found the Hacktronics tutorial the best way to go. There are two essential programmes, one to find the address of your sensor, the other to use it. The installation is simple enough but you need a 4.7k resistor.  You need to use, and specify, a different pin for the sensor so it does not clash with the LCD on pin 3.

At some future date, you should also try to get the LCD on different pins as well. Pin 4 is commonly used by ethernet shields.

david95

Is there any schematic on how to connect the pins????
can you link me some tutorials????

Useful link: http://www.lmgtfy.com/?q=ds18b20+arduino

That sensor uses a one wire interface. One pin is VCC, another is ground and the middle one is the signal pin. You connect the signal pin to a pin you choose on your arduino.
Schematic:
http://milesburton.com/images/e/e5/Schematic-dallas-18s20.gif

Nick_Pyner


Is there any schematic on how to connect the pins????
can you link me some tutorials????


As I said, hacktronics ds18b20 tutorial. Google it, and all will be revealed.

As I said, you need to use, and specify, a different pin for the sensor so it does not clash with the LCD on pin 3. This is because that tutorial wants to use pin 3 for the sensor
Code: [Select]
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

and you are already using it for the LCD, which is working fine.

You can either change the LCD wiring or the sensor, it is just a matter of convenience or confidence, but don't use the same pin for both.

Ultimately, you will be well-advised to change the wiring for the LCD altogether. What you have is a poor choice, or bad advice, but there is no need to do that immediately if you are uncomfortable about it.

david95

#5
Jul 14, 2013, 04:52 pm Last Edit: Jul 14, 2013, 05:12 pm by david95 Reason: 1
ok I downloaded the OneWire library and the dallasTemperature library.
Wrote this code:
Code: [Select]

/*
Lettura_ds18b20.pde
Il programma permette la misurazione della temperatura
che viene mostrata su un display LCD



Creato il 20/9/2010
da Adriano Gandolfo <http://www.adrirobot.it>
This example code is in the public domain.
*/

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

// Il terminale data del sensore รจ connesso
// alla porta 2 di Arduino
#define ONE_WIRE_BUS 7

// Imposta la comunicazione oneWire per comunicare
// con un dispositivo compatibile
OneWire oneWire(ONE_WIRE_BUS);

// Passaggio oneWire reference alla Dallas Temperature.
DallasTemperature sensors(&oneWire);

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(void)
{
 // Start up the library
 sensors.begin();
 // Imposta il valore di righe e colonne del display LCD
 lcd.begin(16, 2);
}

void loop(void)
{

 sensors.requestTemperatures(); // Invia il comando di lettura delle temperatura
 lcd.clear();
 lcd.setCursor(0, 0); // bottom left
 lcd.print("Temperatura di: ");
 lcd.setCursor(0, 1); // bottom left
 lcd.print (sensors.getTempCByIndex(0));
 lcd.print (" C");
}


as you can see, I've chosen the digital Pin 7 for the 18B20, but I get this on the LCD: Temperature:-127.00 C
i connected the 18B20 as you can see in the photo:Pin 1 +5V,Pin 2 to Digital pin7,pin 3 GND, 4.7k resistor between VCC and data cable

bperrybap

It is impossible for us to tell how you have wired up your part from the photo
as we cannot see where both ends of the wires are going. The photo is too close.
Because of this we can only guess which is not good. Please post another photo
taken at a further distance so we can see both ends of the wires so we can
see all the wire connections.

Also when referring to pin numbers always use the same pin numbers as the manufacturer's
datasheet. i.e. in your case pin 1 is gnd, pin 2 is data, pin 3 is Voltage.
http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

One thing that appears incorrect in the photo is the pullup resistor.
The resistor goes between the data line and voltage not the data line and ground.
In your photo the 18B20 pin 1 is on the left, pin 2 is the middle, pin 3 is on the right.

In this case I will admit that the datasheets provided by Dallas Semiconductor &  maxim
tend to be confusing (at least to me) as they show a flat bottom view of the part vs a perspective view.
I've actually gotten the pins backwards myself a few times and when backwards the part
will get smoking hot when using external power.
One time when I realized that the pins had been wired backwards
I touched the top of the part to see if was warm, and it severely burned my finger
and left a nice semi-circle blister that lasted for weeks until it healed.
Amazingly, the part still worked when wired correctly.

Other information:

The part has two ways it can wired up for power.
- external power
- parasitic

While the example schematic that TheCoolest provided may work with parasitic power,
it is not the recommended way of hooking up the part as noted in the datasheet.
The datasheet recommends grounding the voltage input pin on the part (pin 3)
when using parasitic power.


--- bill



Nick_Pyner

I think -127 means no connection.

david95

#8
Jul 15, 2013, 10:56 am Last Edit: Jul 15, 2013, 11:02 am by david95 Reason: 1
Ok, I connected wrong the GND, so it wasn't working, but now I connected it well and it says Temperature: 85 C
Still too much, know why? attached some photos.
additional information: as you said, bperrybap, the first time I connected the 18B20 backwards, and it started to warm, and I nearly had my finger burned.
Could be this poblem related with it's previous backwards connection?
Maybe it's broken ?

david95


I think -127 means no connection.

Yeah, it wasn't well connected, my fault ;)

Nick_Pyner

#10
Jul 15, 2013, 04:02 pm Last Edit: Jul 15, 2013, 06:11 pm by Nick_Pyner Reason: 1

Ok, I connected wrong the GND, so it wasn't working, but now I connected it well and it says Temperature: 85 C

Maybe it's broken ?


Probably not, they can take a lot of abuse, you will be glad to hear. And I'm glad to hear I'm not the only person to wire one the wrong way round.

The 85 c is the power-on reset value.

The DS18B20 may not be receiving the command to perform a temperature conversion. This could be a software screwup. You may be asking for a readout before you execute the get command, or are simply not giving it enough time to do the job. Indeed, looking at the code, a one second delay in your loop could work wonders here.

The problem may also be caused by inadequate power here. If you are using USB power, a wall wart could be a good investment right now.



bperrybap

From the photos it is difficult to tell how the sensor is wired up.
In looking at the 3rd photo, (the close blurry photo of the sensor),
the sensor does not look like it is wired up correctly but is hard
to tell where the wires are plugged in and I can't see the wires/pins
on the sensor to tell which holes they are in because of the bad photo
so it is difficult to tell for sure.


Are you trying to run the part in external power mode or parasitic mode?
What is connected to each of the sensor pins?

Can you post a clearer photo of the sensor and describe how you
have hooked up each of the wires with respect to the photo?
(a nice clear photo like that first one that clearly shows all the wires on the sensor)



--- bill

david95

#12
Jul 15, 2013, 08:55 pm Last Edit: Jul 15, 2013, 09:04 pm by david95 Reason: 1


Ok, I connected wrong the GND, so it wasn't working, but now I connected it well and it says Temperature: 85 C

Maybe it's broken ?


Probably not, they can take a lot of abuse, you will be glad to hear. And I'm glad to hear I'm not the only person to wire one the wrong way round.

The 85 c is the power-on reset value.

The DS18B20 may not be receiving the command to perform a temperature conversion. This could be a software screwup. You may be asking for a readout before you execute the get command, or are simply not giving it enough time to do the job. Indeed, looking at the code, a one second delay in your loop could work wonders here.

The problem may also be caused by inadequate power here. If you are using USB power, a wall wart could be a good investment right now.




Yes, I was running the circuit via USB, now I tried with an AC adaptor at wall,OUTPUT 12V(maybe too much for arduino), but had the same result.


From the photos it is difficult to tell how the sensor is wired up.
In looking at the 3rd photo, (the close blurry photo of the sensor),
the sensor does not look like it is wired up correctly but is hard
to tell where the wires are plugged in and I can't see the wires/pins
on the sensor to tell which holes they are in because of the bad photo
so it is difficult to tell for sure.


Are you trying to run the part in external power mode or parasitic mode?
What is connected to each of the sensor pins?

Can you post a clearer photo of the sensor and describe how you
have hooked up each of the wires with respect to the photo?
(a nice clear photo like that first one that clearly shows all the wires on the sensor)



--- bill

bill, ok I'll try to draw a schematic on paint

david95

PS, I solved the problem, now it says the right temperature(28C-30C)
The problem was on an incorrect wiring between the +5V and the digital pin of arduino.
Thanks to all for the great help :)

Go Up