🚚 Free delivery on orders over: €35 Croatia • €60 EU • $100 US

HUM: HOW TO USE THE DS18B20 WITH PARASITIC POWER SUPPLY

HUM: HOW TO USE THE DS18B20 WITH PARASITIC POWER SUPPLY-Uncategorized

You are a beginner with Dasduino. 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 soldered 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 Dasduino 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 Dasduino’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)); 
}