Digital Thermometer (Electronics 101)

As promised I am adding the plans and code for the Digital Thermometer I wrote about in my blog post “Electronics 101”

The source code to run on the Arduino Uno once you have wired the above circuit is shown below: I will not go into detail on how to do this as you can learn it all on the Arduino website.
const int hot = 101;
const int cold = 97;
/********************************************************************/
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/********************************************************************/
void setup(void)
{
pinMode(3, OUTPUT); //green
pinMode(4, OUTPUT); //red
pinMode(5, OUTPUT); //blue
digitalWrite(5, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(5, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
digitalWrite(5, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
delay(1000);
digitalWrite(5, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(5, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
/********************************************************************/
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.println("DONE");
/********************************************************************/
Serial.print("Temperature is: ");
int temp = sensors.getTempFByIndex(0);
// Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 0 refers to the first IC on the wire
if (temp < cold) { //cold
digitalWrite(5, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
Serial.print(temp);
Serial.println(" It's Cold.");
}
else if (temp >= hot) { //hot
digitalWrite(5, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
Serial.print(temp);
Serial.println(" It's Hot.");
}
else { //fine
digitalWrite(5, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
Serial.print(temp);
Serial.println(" It's nice.");
}
delay(1000);
}
1 thought on “Digital Thermometer (Electronics 101)”
Comments are closed.