Project 12 TEMP SENSOR
Project 12 TEMP SENSOR
Want to create a DIY environmental monitor or weather station? You can use a small, low-cost
sensor like the TMP36 to make devices that track and respond to temperature. In this activity you
will also use the LCD screen to display sensor readings, a common use for LCDs in electronics
projects
Grab the following quantities of each part listed to build this circuit:
Page | 1
NEW COMPONENTS
DS18B20 DIGITAL TEMPERATURE SENSOR: This temperature sensor has three legs. One
connects to 5V, one to ground, and the voltage output from the third leg varies proportionally to
changes in temperature. By doing some simple math with this voltage, we can measure
temperature in degrees Celsius or Fahrenheit.
DS18B20 is 1-Wire digital temperature sensor from Maxim IC. Reports degrees in Celsius
with 9 to 12-bit precision, from -55 to 125 (+/-0.5). Each sensor has a unique 64-Bit Serial
number etched into it - allows for a huge number of sensors to be used on one data bus.
Features:
• Unique 1-Wire® interface requires only one port pin for communication
• Each device has a unique 64-bit serial code stored in an onboard ROM
• Multidrop capability simplifies distributed temperature sensing applications
• Requires no external components
• Can be powered from data line.
• Power supply range is 3.0V to 5.5V
PROJECT 12: TEMPERATURE SENSOR
NEW CONCEPTS
ALGORITHMS: An algorithm is a process used in order to achieve a desired result. Often, the
information needed to create an algorithm lives in the part’s datasheet. This sketch uses a few
formulas to turn a voltage value into a temperature value, making them all part of the larger
temperature-retrieving algorithm. The first formula takes the voltage read on analog pin 0 and
multiplies it to get a voltage value from 0V–5V:
The number we are multiplying by comes from dividing 5V by the number of samples the analog
pin can read (1024), so we get: 5 / 1024 = 0.004882813.
The second formula takes that 0–5V value and calculates degrees Celsius:
We are showing how to use DS18B20 one wire water proof temperature sensor. With the
help of DS18B20 one wire temperature sensor we can measure the temperature from -55℃
To 125℃ with accuracy of ±5 .
Additional Library:
Page | 3
PROJECT 12: TEMPERATURE SENSOR
Page | 4
SOURCE CODE:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celcius=0;
float Fahrenheit=0;
void setup(void)
{
PROJECT 12: TEMPERATURE SENSOR
Serial.begin(9600);
sensors.begin();
}
void loop(void)
{ Page | 5
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
Serial.print(" C ");
Serial.print(Celcius);
Serial.print(" F ");
Serial.println(Fahrenheit);
delay(1000);
}
SOURCECODE
#include <LiquidCrystal.h> //the liquid crystal library contains commands for printing to the display
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // tell the RedBoard what pins are connected to the display
void setup() {
lcd.begin(16, 2); //tell the lcd library that we are using a display that is 16 characters wide and 2
characters high
lcd.clear(); //clear the display
}
void loop() {
voltage = analogRead(A0) * 0.004882813; //convert the analog reading, which varies from 0 to 1023, back to a
voltage value from 0-5 volts
degreesC = (voltage - 0.5) * 100.0; //convert the voltage to a temperature in degrees Celsius
degreesF = degreesC * (9.0 / 5.0) + 32.0; //convert the voltage to a temperature in degrees Fahrenheit
delay(1000); //delay for 1 second between each reading (this makes the display less noisy)
}