Friday, February 13, 2015

[Wireless Room Temperature Monitoring System] Temperature sensing with DS18B20 sensor and Arduino Pro Mini

The goal here is to plug the DS18B20 Temperature sensor to the Arduino Pro Mini.
For my project i decided to go with an already complete module with the sensor as well as the 4,7 kOhms ... less soldering !

The wiring : 

The DS18B20 Module has 3 pins just like the DS18B20 sensor alone.

      DS18B20 Module > Arduino Pro Mini

  • - (Negative) > GND
  • + (Positive) > VCC
  • Data > Pin 3 

The software :

Once the wiring is all done, the next step is to try finding out what is the address of the sensor in order to get the temperature measure later on.

You need to install the OneWire and the DallasTemperature libraries
- One wire :
- DallasTemperature :

The idea is to upload the following code to the Arduino Pro Mini with the sensor wired :
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire  ds(3);  // Connect your 1-wire device to pin 3
void setup(void) {
void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  Serial.print("Looking for 1-Wire devices...\n\r");
  while( {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
    for( i = 0; i < 8; i++) {
      if (addr[i] < 16) {
      Serial.print(addr[i], HEX);
      if (i < 7) {
        Serial.print(", ");
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
  Serial.print("\n\r\n\rThat's it.\r\n");
void loop(void) {
  // nothing to see here
code source :

Once up and running with the program in the Arduino, go to :

Tool > Serial Monitor.

The sensor address will then show up on the monitor. In my case it was :
0x28, 0xFF, 0xED, 0x0F, 0x11, 0x14, 0x00, 0xD2 
With this address we can move on to the next and final step, measure some temperatures finally !
Upload the following code to the Arduino Pro Mini
#include <OneWire.h>   
#include <DallasTemperature.h>
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress Thermometer = { 0x28, 0xFF, 0xED, 0x0F, 0x11, 0x14, 0x00, 0xD2 };
void setup(void)
  // start serial port
  // Start up the library
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(Thermometer, 10);
void printTemperature(DeviceAddress deviceAddress)
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(" F: ");
void loop(void)
  Serial.print("Getting temperatures...\n\r");

  Serial.print("Inside temperature is: ");
Code source :

Once the Arduino is running the program, go to the Serial Monitor again.
The temperature should be printed on the screen

Tada ! Temperature is displayed on screen !

Next step is to try and combine the temperature sensing and to send it via TX 433 Mhz to the Raspberry Pi to sniff !

If anyone has any idea on how to do that ... i am interested !

No comments:

Post a Comment