This circuit is designed to monitor temperature using multiple DS18B20 1-Wire Temperature Sensors interfaced with an Arduino UNO microcontroller. The sensors are connected to a single digital pin on the Arduino through a 1-Wire bus, which allows multiple sensors to communicate with the microcontroller over a single wire. A pull-up resistor is used on the data line to ensure proper communication. The Arduino is programmed to read the temperature from each sensor and output the readings to the serial monitor in both Celsius and Fahrenheit.
/*
* Temperature Monitoring Sketch
* This sketch interfaces with multiple DS18B20 temperature sensors on a single bus.
* It uses the OneWire and DallasTemperature libraries to communicate with the sensors,
* reads the temperature from each sensor, and outputs the temperature readings to the serial monitor.
* The temperature is displayed in both Celsius and Fahrenheit.
*/
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into digital pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
int deviceCount = 0;
float tempC;
void setup(void)
{
// Start up the library
sensors.begin();
// Start serial communication
Serial.begin(9600);
// Locate devices on the bus
Serial.print("Locating devices...");
deviceCount = sensors.getDeviceCount();
Serial.print("Found ");
Serial.print(deviceCount, DEC);
Serial.println(" devices.");
Serial.println("");
}
void loop(void)
{
// Send command to all the sensors for temperature conversion
sensors.requestTemperatures();
// Display temperature from each sensor
for (int i = 0; i < deviceCount; i++)
{
Serial.print("Sensor ");
Serial.print(i + 1);
Serial.print(" : ");
tempC = sensors.getTempCByIndex(i);
Serial.print(tempC);
Serial.print((char)176); // Shows degrees character
Serial.print("C | ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
Serial.print((char)176); // Shows degrees character
Serial.println("F");
}
Serial.println("");
// Wait 1 second before next reading
delay(1000);
}
This code is designed to run on the Arduino UNO and interfaces with the DS18B20 temperature sensors. It initializes the sensors, reads temperatures, and outputs the results to the serial monitor.