Introduction: Temperature With DS18B20
It's a small project about temperature monitoring. I used a DS18B20 digital device to get the temperature. The device uses OneWire protocol. You need only an Arduino board, a DS18B20 and a 4.7KOhm resistor and a breadboard. If you have a display shield for the Arduino that's a plus.
Step 1: What You Have to Know About DS18B20
The device is communicating on one common bus. It means that you can connect several devices. We use only two pins on the device to connect them to the Arduino board. We need two libraries in the sketch: OneWire and DallasTemperature .
So we must include these libraries.
So we must include these libraries.
Step 2: Setup
We define the communication IO port:
#define ONE_WIRE_BUS 3
We need two object to communicate with the device(s):
OneWire ds(ONE_WIRE_BUS);
DallasTemperature sensors(&ds);
ds object will handle the onewire protocol
sensors object will handle the temperature monitoring devices
I chained 3 devices in this example on a breadboard. On the left side I used a potmeter instead of a 4.7K resistor.
#define ONE_WIRE_BUS 3
We need two object to communicate with the device(s):
OneWire ds(ONE_WIRE_BUS);
DallasTemperature sensors(&ds);
ds object will handle the onewire protocol
sensors object will handle the temperature monitoring devices
I chained 3 devices in this example on a breadboard. On the left side I used a potmeter instead of a 4.7K resistor.
Step 3: Inventory
1st step is to start the sensors:
sensors.begin();
2nd step is to count the number of sensors on the bus. This function sets the global variable: maxsensors
scanSensors();
3rd step is to request the temperatures from the devices:
sensors.requestTemperatures();
4th step is to read the temperatures one by one:
for (int i=0;i {
float f = sensors.getTempCByIndex(i);
lcdprint(dtostrf(f, 5, 1, buffer));
}
lcdprint is a function to display the result on an LCDshield
dtostrf is a function defined in stdio library. it must be included.
sensors.begin();
2nd step is to count the number of sensors on the bus. This function sets the global variable: maxsensors
scanSensors();
3rd step is to request the temperatures from the devices:
sensors.requestTemperatures();
4th step is to read the temperatures one by one:
for (int i=0;i {
float f = sensors.getTempCByIndex(i);
lcdprint(dtostrf(f, 5, 1, buffer));
}
lcdprint is a function to display the result on an LCDshield
dtostrf is a function defined in stdio library. it must be included.
Step 4: Source Code
Some link for downloading the source codes
Full source code
Dallas Temperature library by Miles Burton
LCD shield library, I used in this project
The LCD shield was ordered from here
Full source code
Dallas Temperature library by Miles Burton
LCD shield library, I used in this project
The LCD shield was ordered from here