• Worldwide Shipping

  • 24/7 Customer Support

  • FAQ
  • Worldwide Shipping

  • 24/7 Customer Support

  • FAQ

HUM: How to use the DS18B20 with parasitic power supply

You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Croduino and the basic code. Everything else is left to your imagination.

Introduction

In our tutorial about the DS18B20 digital thermometer, which you can read here, we have already mentioned parasitic power supply, and now it is time for us to explain what it is about and why it is useful.

How does it work?

If we observe communication between the sensor and microcontroller physically, we will notice that voltages 0 or +Vpu (voltage to which the bus is connected via pull-up resistor) appear on the data line, corresponding to logical '0' or '1'. Voltage on the bus will mostly be equal to +Vpu because the bus is connected via pull-up resistor. The way microcontroller or sensor can change voltage of the bus is that they activate their transistor which will pull the bus to the ground.

In order to enable parasitic power supply, we must connect Vdd connector of the sensor to the GND connector. Let's take a look at the following image, from which we can see the way parasitic power supply functions.

If we have previously connected Vdd and GND, diode D2 will never conduct and the sensor can detect that it is in the parasitic power supply mode. We have determined how the sensor detects which mode is it in, but how is it supplied?

Let's consider two sequences; the bus on the +Vpu or 0V voltage. When the bus is at +Vpu voltage which is higher than the voltage on the internal capacitor Cpp, diode D1 will conduct and start charging the capacitor. In the other case, the bus is at 0V voltage which means that diode D1 is polarization locked and it does not conduct, and the only path for current is towards the sensor. Therefore, while the bus is at +Vpu voltage, the capacitor is being charged, i.e. the energy is being accumulated and it is later used for power supply of the sensor. This mode allows using less wires, and eliminates the need for external power supply.

How to connect it?

For proper operation it is NECESSARY to mutually connect Vdd and GND connectors. Besides, GND connector of the sensor is connected to Croduino's GND, and the data line is connected to an arbitrary digital pin (pin 9 in our case). We must also connect a 4,7kΩ pull-up resistor between power supply of the Croduino and the data line.

 

Arduino code

As in the previous DS18B20 tutorial we will use two libraries: OneWire and DallasTemperature. If you do not know how to install the library, read our tutorial. The program code is displayed for easy temperature reading from one sensor. Within the function for temperature reading, automatic mode selection is installed so you do not have to worry about it.

 

#include "OneWire.h"
#include "DallasTemperature.h"

// digital pin to which the sensor is connected
#define ONE_WIRE_BUS 9

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
}

void loop(void)
{ 
  Serial.print("Mjeri temperaturu...");
  sensors.requestTemperatures(); // temperature reading command
  Serial.println("Gotovo");
  Serial.print("Temperatura je: ");
  Serial.println(sensors.getTempCByIndex(0));  
}
Leave a Reply