DS18B20 temperature sensor on pin 2, on an Arduino Uno
A DS18B20 on pin 2, with a 4.7k pull-up on its data line, measures the temperature over one wire; the Dallas library reads it once a second. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The parts retail for about $32. On Mokxi they're free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A DS18B20 on one wire: pin 2.
//
// DS18B20 DQ -> pin 2 (4.7k from DQ to 5V) VDD -> 5V GND -> GND
//
// The sensor sends its reading as a string of time slots on a single wire.
// OneWire times them; DallasTemperature asks for a conversion and reads the
// answer back in degrees.
//
// Drag the sensor's temperature.
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire bus(2);
DallasTemperature sensors(&bus);
void setup() {
Serial.begin(9600);
sensors.begin();
Serial.println("Mokxi Uno: DS18B20 on pin 2");
}
void loop() {
sensors.requestTemperatures();
Serial.print(sensors.getTempCByIndex(0));
Serial.println(" C");
delay(1000);
}
Parts list
3 parts, plus the jumper wires. They retail for about $32; on Mokxi they're free.
How it is wired
3 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; Temperature sensor, DS18B20 pin GND
- Arduino Uno R3 pin 2; Temperature sensor, DS18B20 pin DQ
- Arduino Uno R3 pin 5V; Temperature sensor, DS18B20 pin VDD
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.