OneWire temperature measurement and connection methods

Hello, I'm giving you a guide that many people are looking for, especially for beginners.
All beginners try to create, for example, a weather station where they want to measure temperatures, pressure and other quantities.
Temperature sensors are most often used by the Dallas Maxim Temperature Sensors (DS18B20)
These sensors support the OneWire bus. After one wire it is possible to send data + "electrique".
Each DS18B20 sensor has a different address. This means that it is possible to read from each sensor separately, according to its index (the order of the cable). The power supply is just 3.3V, while at 5V the sensors are soft and the measurement is inaccurate. For each connection, it is necessary to use a 4.7KΩ resistor.
Wiring for Parasite Power Mode:
Obrázek
Wiring for Normal Power Mode:
Obrázek
Wiring for one DS18B20 sensor connected to a digital Arduino Uno pin:
Obrázek
WARNING at WIRING! Depending on the sensor type, it is possible that Vcc and GND have it opposite.
Sample Arduino code:
#include <OneWire.h> //KNIZNICA ONEWIRE PRE VYUZITIE ONEWIRE ZBERNICE #include <DallasTemperature.h> //KNIZNICA PRE TEPLOTNE CIDLA DS18B20 #define ONE_WIRE_BUS 5 //DEFINICIA PINU AKO ZBERNICE PRE ONEWIRE ZARIADENIA.. TU ZBIERAME UDAJE OneWire oneWire(ONE_WIRE_BUS); //ONEWIRE ČÍTAŤ IBA NA PORTE DEFINOVANOM VYSSIE DallasTemperature sensors(&oneWire); //PRIRADENIE SENZOROV DALLAS DS18B20 NA ONEWIRE ZBERNICU void setup() { sensors.begin(); //START SENZOROV POD ONEWIRE (DALLASTEMPERATURE) delay(2000); Serial.begin(9600); //SPUSTENIE SERIOVEJ LINKY NA CITACIU RYCHLOST 9600 while (!Serial) { ; //CAKA POKYM SA SERIOVY PORT NEZAPNE } } void loop() { sensors.requestTemperatures(); B delay(500); //delay je dobry, niektore DS senzory musia počkať, kým vrátia hodnotu! Serial.println("Teplota prve cidlo:"); Serial.println(sensors.getTempCByIndex(0)); Serial.println("Teplota druhe cidlo:"); Serial.println(sensors.getTempCByIndex(1)); Serial.println("Teplota tretie cidlo:"); Serial.println(sensors.getTempCByIndex(2)); Serial.println("Teplota stvrte cidlo:"); Serial.println(sensors.getTempCByIndex(3)); delay(2000); }


Comments

Popular posts from this blog

Web scraper via Arduino & NodeMCU & ESP32

ESP32 control via UDP datagrams

Biking on Google Maps - Arduino Leonardo (32u4) - HID device