For fast transaction call 0916.457.0748
Reading Room Temperature using  DS18b20 Temperature Sensor

Reading Room Temperature using DS18b20 Temperature Sensor

The DS18B20 Digital Thermometer provides 9 to 12-bit (configurable) temperature readings which indicate the temperature of the device. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor.In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.

Things you'll need:

  • DS1820 Stainless steel package Waterproof DS18b20 temperature probe temperature sensor 18B20
  • Arduino UNO R3
  • 4.7k or 5k ohm Resistor
  • Breadboard

Connection Diagram

 

 Arduino to Sensor

  • Connect Digital Pin 2 to Sensor Data Pin (Yellow)
  • Connect 5V to Sensor 5V Pin (Red)
  • Connect Ground to Sensor Ground Pin (Black)
  • Connect 4.7k ohm Resistor between 5V(Red) and Data Pin(Yellow)

 Software Needed

Download the following library:

After download is done, add the Library in your Arduino Software.

Sketch >> Include Library >> Add .ZIP File

and locate the library you downloaded earlier.

Now write the following code in your Arduino IDE.

//we need to include the libraries
#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() 
{ 
 Serial.begin(9600); // start serial monitor
 Serial.println("Room Temperature Reading"); 
 sensors.begin();  // Start up the library 
} 
void loop() 
{ 

 Serial.print(" Requesting temperatures..."); 
 sensors.requestTemperatures(); // request command to get temperature readings 
 Serial.println("DONE"); 

 Serial.print("Temperature is: "); 
 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); // delay of 1 second
} 

Compile and Upload the code to your Arduino UNO R3 board.
Open Serial Monitor and set Baud Rate to 9600.

Done.

Happy Coding!

0 comments

Leave a comment

Please note, comments must be approved before they are published

Payment Methods

Facebook Rewards Program