Professional Documents
Culture Documents
Arduino Based Digital Temperature Sensor With 7-Segment Displays-1 DOCUMENTATION
Arduino Based Digital Temperature Sensor With 7-Segment Displays-1 DOCUMENTATION
Components Required:
The only downside is they use the Dallas 1-Wire protocol, which is
somewhat complex and requires a bunch of code to parse out the
communication. We toss in a 4.7k resistor, which is required as a pull up
from the DATA to the VCC line when using the sensor.
LM35 vs DS18B20:
A DS18B20 is factory calibrated to output the right temperature. An LM35
is factory calibrated for voltage (not temperature), and the Arduino has to
convert this to temperature.
LM35 is an analog temperature sensor, so any distortion in input can
rapidly affect the reading. But DS18B20 is a digital temperature sensor, so
input doesn’t affect the output reading.
If the long wire is used for measuring the temperature at a certain distance,
wire length can deviate the value in analog LM35 Sensor. But DS18B20 is
a digital sensor, there is no effect in any output value.
About Arduino:
“ARDUINO IS AN OPEN-‐SOURCE ELECTRONICS PROTOTYPING
PLATFORM BASED ON FLEXIBLE, EASY-‐TO-‐USE HARDWARE
AND SOFTWARE. IT'S INTENDED FOR ARTISTS, DESIGNERS,
HOBBYISTS AND ANYONE INTERESTED IN CREATING
INTERACTIVE OBJECTS OR ENVIRONMENTS1”
Since Arduino is Open Source, the CAD and PCB design is freely
available. Everyone can buy a pre-‐assembled original Arduino board2or a
cloned board from another company. You can also build an Arduino for
yourself or for selling. Although it is allowed to build and sell cloned
Arduino boards, it’s not allowed to use the name Arduino an the
corresponding logo. Most boards are designed around the Atmel
Atmega328.
Inthis section,we will learn in easy steps, how to set up the Arduino IDE
on our computer and prepare the board to receive the programvia USB
cable.
Step1:Firstyou must have your Arduino board (you can choose your
favorite board) and a USB cable. In case you use Arduino UNO, Arduino
Duemilanove, Nano, Arduino Mega 2560, or Diecimila, you will need a
standard USB cable (A plug to B plug),the kind you would connect
to a USB printeras shown in the following image.In case you use
ArduinoNano, youwillneed anA to Mini-Bcable insteadas shown in the
following image.
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;
int digitBuffer[4] = {
0};
int digitScan = 0;
int soft_scaler = 0;
float tempC, tempF;
int tmp;
void setup() {
TCCR2A = 0;
TCCR2B = (1<<CS21);
TIMSK2 = (1<<TOIE2);
TCNT2 = 0;
pinMode(ledPin,
OUTPUT); for(int
i=0;i<4;i++)
{
pinMode(digitPins[i],OUTPUT);
}
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
sensors.begin();
sensors.getAddress(insideThermometer, 0);
}
ISR(TIMER2_OVF_vect) {
soft_scaler++;
if(soft_scaler==15)
{
refreshDisplay();
soft_scaler = 0;
}
};
void refreshDisplay()
{
for(byte k=0;k<4;k++)
{
digitalWrite(digitPins[k], LOW);
}
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST,
B11111111); digitalWrite(latchPin, HIGH);
delayMicroseconds(400);
digitalWrite(digitPins[digitScan], HIGH);
digitalWrite(latchPin, LOW);
if(digitScan==2)
{
shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]]
| B10000000));
}
else
{
shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
}
digitalWrite(latchPin, HIGH);
digitScan++;
if(digitScan>3) digitScan=0;
}
void loop()
{
digitalWrite(ledPin, HIGH);
sensors.requestTemperatures();
tempC = sensors.getTempC(insideThermometer);
tempF =
DallasTemperature::toFahrenheit(tempC); tmp =
int(tempF*100);
digitBuffer[3] = tmp/1000;
digitBuffer[2] = (tmp%1000)/100;
digitBuffer[1] = (tmp%100)/10;
digitBuffer[0] = (tmp%100)%10;
digitalWrite(ledPin, LOW);
delay(50);
}
Applications
• This can be used as a simple home ambient temperature device. It
can also measure and display temperatures up to 99°C.
• The temperature of liquids can be measured after waterproofing the
sensor
• It can be used to monitor equipment that gets easily damaged due to
over-heating.