DS18B20 Temperature Sensor Box
by iotgurulive in Circuits > Arduino
3672 Views, 3 Favorites, 0 Comments
DS18B20 Temperature Sensor Box
Simple DS18B20 based temperature sensor appliance with open source 3D printable box and prototype PCB.
The box and the prototype PCB is optional, only one ESP8266 based MCU is needed and one DS18B20 temperature sensor. I suggest to you a WEMOS D1 mini, but this example works with an ESP-01 as well.
This example does explain how to write and upload an Arduino program to the ESP8266 MCU, so be aware of this skill before following me. :)
Supplies
Must have:
- ESP8266 MCU
- DS18B20
- one 4.7 kOhm resistor
- some wire
Optionally have:
- WEMOS D1 mini as MCU
- prototype PCB for WEMOS D1 mini
- 3D printed box
How to Connect the Wires?
It's easy as pie, check the wiring schematics on the picture... :)
1, In case of bare ESP8266 board, connect the RX and TX to your USB-serial device, in case of any board with integrated USB this is not necessary.
2, Connect the GND and VCC to the ESP8266 board and to the DS18B20 sensor.
3, Connect the resistor between the VCC and the data wire of the DS18B20 sensor.
4, Connect the data wire of the DS18B20 sensor to one GPIO of the MCU (for example GPIO 2).
Configure the ArduinoIDE
You need three additional library:
- OneWire: https://www.arduinolibraries.info/libraries/one-wire
- DallasTemperature: https://www.arduinolibraries.info/libraries/dallas-temperature
- The IoT Guru Integration: https://www.arduinolibraries.info/libraries/the-io-t-guru-integration
Sign Up and Create a Device, a Node and a Field
The IoT Guru cloud is a free cloud backend, you can use it to save and show measurements really easy.
You need to create a device, a node and a field:
- Name of the device is ESP8266: https://iotguru.cloud/tutorials/devices
- Name of the node is DS18B20: https://iotguru.cloud/tutorials/nodes
- Name of the field is temperature: https://iotguru.cloud/tutorials/fields
To connect with the cloud, you need to gather five identifier:
- userShortId: the short identifier of you
- deviceShortId: the short identifier of your device
- deviceKey: the secret key of your device
- nodeShortId: the short identifier of your device
- fieldName: the name of the field
Arduino Code
Here is the example code, you need to replace the identifiers to your identifier, replace the SSID and the password to your WiFi credentials and check the GPIO number of the DS18B20 data wire.
#include <OneWire.h> #include <DallasTemperature.h> #include <IoTGuru.h> #include <ESP8266WiFi.h> const char* ssid = "iotguru.cloud"; const char* password = "********"; String userShortId = "l4jLDUDDVKNNzx4wt2UR6Q"; String deviceShortId = "uAjbSzf8LvlrofvwYU8R6g"; String deviceKey = "hacfIjPn6KbBf2md8nxNeg"; IoTGuru iotGuru = IoTGuru(userShortId, deviceShortId, deviceKey); String nodeKey = "tGib1WSRvEGJ98rQYU8R6g"; String fieldName = "temperature"; #define ONE_WIRE_BUS 2 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup(void) { Serial.begin(115200); delay(10); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(50); Serial.print("."); } Serial.println(""); iotGuru.setCheckDuration(60000); iotGuru.setDebugPrinter(&Serial); sensors.begin(); } void loop(void) { iotGuru.check(); sensors.requestTemperatures(); float measuredValue = sensors.getTempCByIndex(0); Serial.println("The first sensor temperature: " + String(measuredValue) + " °C"); iotGuru.sendHttpValue(nodeKey, fieldName, measuredValue); delay(30000); }
Run and Check
If everything is fine, your thermometer box will send the sensor measurements to the cloud and you'll see such nice graphs over time if enough measurements have accumulated.
Live examples:
- https://iotguru.cloud/field/srcPlk78rcpgCgCgKWcR6g/temperature
- https://iotguru.cloud/field/tGib1WSRvEGJ98rQYU8R6g/temperature
Extended GitHub project:
- https://github.com/IoTGuruLive/temperature_box