Let's Workshop: Keysetudio DS18B20 Temperature Sensor Module
Posted by Sebastian Karam on
Here is a quick introduction to using the Keyestudio DS18b20 based temperature sensor module. This guide aim to provide you with the tools you require to start measuring temperatures in all manner of environments.
The example will demonstrate the use of an Arduino UNO in requesting and interpreting data from a DS18b20 sensor. Once connected and the program loaded, the serial monitor will display a live temperature readout. This will use the OneWire library created by Paul Stoffregen and the DallasTemperature library created by Miles Burton.
Components
- 1pcs Arduino UNO or Compatible - LCAA100005
- 1pcs Keysetudio DS18B20 Temperature Sensor Module - BDAA100019
- 3pcs Male to Female Jumper Cables - GBAA100002
Wiring
Wire the components together as can be seen in the image below, taking care to match the pin numbers.
Coding
The code consists of the an include, definition, launch, setup and loop. First the OneWire library and the DallasTemperature library are linked to the code. The sensor pin is defined followed by the OneWire library and DallasTemperature library instances established. The setup launches the serial connection and sensor connection. The loop contains the control program that will run continuously after the setup. It begins by requesting the information from the sensor instance. It then prints the value to the serial monitor.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the DallasTemperature library and DS18b20 Temperature probe - BDAA100019 The program uses the OneWire and DallasTemperature libraries to request and output temperatures from a DS18b20 sensor to the serial monitor. modified 24 October 2019 by Sebastian Karam - Flux Workshop The OneWire library created by Paul Stoffregen https://github.com/PaulStoffregen/OneWire The DallasTemperature library created by Miles Burton https://github.com/milesburton/Arduino-Temperature-Control-Library */ #include#include // Define the pin that the sensor pin #define ONE_WIRE_BUS 2 // Establish a oneWire instance OneWire oneWire(ONE_WIRE_BUS); // Establish Dallas Temperature instance DallasTemperature sensors(&oneWire); void setup(void) { Serial.begin(9600); // Open a serial communication line sensors.begin(); // Start up the DallasTemperature library } void loop(void){ sensors.requestTemperatures(); // Request temperatures from the sensors instance Serial.print("Temperature (Celsius): "); // Print to the serial monitor Serial.print(sensors.getTempCByIndex(0)); // Print the temperature from the library to serial monitor Serial.print("\n"); // Print to the serial monitor delay(1000); // Pause before restarting the loop }
Running
With the board is loaded with the program and all the connections made the module will begin to output a temperature in celcius. The animation below shows a brief loop of the sensor being placed beside a cold cup of water then above a a hot cup of water and then back to the cold.
What to try next?
- Using multiple temperature sensors - changing the number "0" in "sensors.getTempCByIndex(0)"
- Use the DallasTemperature library to produce the output in farenheit.
- Poll the sensor frequently to monitor the temperature of a green house through out the day - triggering the window motor based on the value.
Share this post
- 1 comment
- Tags: Arduino, BDAA100019, DS18b20, Hot Air, Keyestudio, October 2019, Sensor, Temperature, UNO
Muchas gracias. ?Como puedo iniciar sesion?