Introduction
In this tutorial, I will introduce and explain how to use a water temperature sensor to sense the water temperature inside a river or other water features. There are lots of water temperature sensors you could use with Arduino, but I am using Gikfun DS18B20 Waterproof Temperature Sensor for this tutorial, you can find and buy it at this link or other websites:https://www.amazon.com/Gikfun-DS18B20-Temperature-Waterproof-EK1083x3/dp/B012C597T0
Parts List
DS18B20 Waterproof Temperature Sensor
Our key element for this tutorial is our temperature sensor. The DS18B20 temperature sensor is a one-wire digital temperature sensor. This means that it just requires one data line and GND to communicate with the Arduino. And you should not use a non-waterproof temperature sensor for sensing the water temperature. Notice, DS18B20 also has a non-waterproof version of it!
DS18B20 can be powered by an external power supply or it can derive power from the data line, which eliminates the need for an external power supply. DS18B20 can measure temperatures from -55°C to +125°C, it has a ±0.5°C accuracy from -10°C to +85°C. This is totally enough for sensing water temperature inside rivers or water bodies in normal geographic locations.
For more information, you can check the DS18B20 datasheet at this link:https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
Circuit
First, we need to look at the pinout of DS18B20.
As you can there are three pins: Black, Red, and Yellow.
Black Pin needs to be connected to GND
Red Pin needs to be connected to VCC (5V or 3.3V)
Yellow Pin needs to be connected to a digital pin on Arduino.
Code
The next step is to run the code. Before having the code, make sure to install two libraries in your Arduino.
Open your Arduino IDE and go to
Sketch > Include Library > Manage Libraries.
Search OneWire by Paul Stoffregen and Dallas Temperature by Miles Burton. There are many similar libraries, make sure the authors are right.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
// Make sure to include Onewire and Dallas Temperature libraries #include <OneWire.h> #include <DallasTemperature.h> // Connect your yellow pin to Pin12 on Arduino #define ONE_WIRE_BUS 12 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire); void setup(void) { // initialize the Serial Monitor at a baud rate of 9600. Serial.begin(9600); sensors.begin(); } void loop(void){ // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus sensors.requestTemperatures(); Serial.print("Celsius temperature: "); Serial.print(sensors.getTempCByIndex(0)); Serial.print(" - Fahrenheit temperature: "); Serial.println(sensors.getTempFByIndex(0)); delay(1000); } |
Output
Finally, after running the code, we can open up our serial monitor in Arduino IDE, and you should see similar output as below.
Since it is a waterproof temperature sensor, you can just test it in your own bowl!
Reference
https://arduinogetstarted.com/tutorials/arduino-temperature-sensor