Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

Arduino Based Digital temperature sensor

with 7-segment Displays


Introduction:

Indian industries majorly include biomedical, agricultural and


pharmaceutical which are the pillars of country economy. The
monitoring of temperature is a major area for all these industries. Any kind
of unbalancing in the environmental conditions or unset parameters can
create financial loss in the productivity of pharmaceutical and agriculture
industries. Monitoring of temperature is also required for biomedical
industry for drugs and cell culture methods. In healthcare sectors,
environment controlled conditions are also required for patients
threatening. This project deals with measuring temperature by using
Arduino tool and temperature sensor, which will be beneficial for
balancing the environment to increase the productivity.

The temperature sensor used in this project is The DS18B20


temperature sensor is a 1-wire digital temperature sensor. This comes with
a sealed package lets precisely measure temperatures in wet environments
with a simple 1-Wire interface. It communicates on a common bus. It
means it can connect several devices and read their values using just one
digital pin of the Arduino.

Components Required:

1. Arduino UNO Board


2. DS18B20 Waterproof Temperature Sensor
3. Common Anode 7 Segment Display – 4
4. 7HC595 IC (8 bit Shift Resistor)
5. 4.7K Resistor
6. 330 ohm Resistor – 8
7. Connecting Wires
Theory:
DS18B20 Waterproof Digital Temperature Sensor:
This is a pre-wired and waterproofed version of the DS18B20 sensor.
Handy for when you need to measure something far away, or in wet
conditions. The Sensor can measure the temperature between -55 to
125°C (-67°F to +257°F). The cable is jacketed in PVC.

Because it is digital, there is no any signal degradation even over long


distances. These 1-wire digital temperature sensors are fairly precise, i.e.
±0.5°C over much of the range. It can give up to 12 bits of precision from
the onboard digital-to-analog converter. They work great with any
microcontroller using a single digital pin.

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.

LM35 can measure the temperature between −55°C to 150°C but


DS18B20 can measure between −50°C to 125°C.
1 digital output pin of Arduino can be used to connect multiple DS18B20
but it doesn’t happen with LM35.

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.

Popular Arduino boards


There are several different Arduino boards on the market (both original
and cloned).•
Arduino UNO
• Most popular board. Ideal for starters.
• Standard USB for data and power and programming.
• Power Input connector.
• female headers.
• 14 digital I/O ports (of which 6 PWM).
• 6 analog input ports.
• 1 hardware serial port
(UART).• Arduino Nano
• Much smaller than the UNO (only 18×43 mm).
• Mini USB for data and power and programming.
• Input 6-‐20 V on Vinn (6-‐12 recommended).
• Male headers at the bottom side, so ideal to use on a solder less
breadboard.
• 14 digital I/O ports (of which 6 PWM).
• 8 analog input ports.
• 1 hardware serial port
(UART).• Arduino Mini
• Smallest Arduino board, used in small sized projects.
• No USB connector, you need a USB to serial convertor to program
this board.
• No separate power connector (you must use +9Vheader pins)
• Input 7-‐9 V.
• Male headers at the bottom side, so ideal to use on a solder less
breadboard.
• 14 digital I/O ports (of which 6 PWM).
• 8 analog input ports (4 of them are not connected to header pins).
• No hardware serial port
(UART) Arduino Mega
• Largest Arduino board for large number of I/O ports.
• Normal size USD for data and power and programming.
• Power input connector.
• Input 6-‐20 V (7-‐12 recommended).
Female headers at the top side.
• 54 digital I/O ports (of which 15 PWM).
• 16 analog input ports.
• 4 serial ports
Arduino UNO Implementation:

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.

Step 2: Download Arduino IDE Software. ARDUINO –INSTALLATION.


You can get different versions of Arduino IDE from the Download pageon
the Arduino Official website. You must select your software, which is
compatible with your operating system (Windows, IOS, or Linux). After
your file download is complete,unzip the file.
Step 3: Power up your board.The Arduino Uno, Mega, Duemilanove
and Arduino Nano automatically draw power from either,the USB
connection to the computer or an external power supply. If you areusing an
Arduino Diecimila, you have tomake sure that the board is configured to
draw power from the USB connection. The power source is selected with a
jumper, a small piece of plastic that fits onto two of the three pins between
the USB and power jacks. Check that it ison the two pins closest to the
USB port. Connect the Arduino board to your computer using the
USB cable. The green power LED (labeledPWR) should glow.
Step 4: LaunchArduino IDE.After your Arduino IDE software
isdownloaded,you need to unzip the folder.Inside the folder, you can find
the application icon with an infinity label (application.exe). Double-click
theicon to start theIDE.
Step 5: Open your first project.Oncethe softwarestarts, you have two
options:
Create anew project.
Open an existing project example
Here, we are selecting just one of the examples with the name Blink. It
turns the LED on and off with
Some time delay. You can select any other example from the list.
Step 6: Select your Arduino board. To avoid any error while uploading
your program to the board, you must select the correct Arduino board
name, which matches with the board connected to your computer. .Go to
Tools -> Board and select your board.
Fritzing
Fritzing is a tool you can use to create drawings of your Arduino projects.
In Fritzing you can draw in three different environments: Breadboard,
Schematic and PCB. You can switch between these three environments at
will. You can use Fritzing to document your projects, check your design,
route the connections on a breadboard or create a PCB (Printed Circuit
Board) to build your own Arduino shield.

Fritzing is not limited to Arduino. All drawings used in the Arduino


tutorials at arduino.cc and all drawings in this document have been created
by Fritzing.
Seven Segment Display:
A Seven-segment display is a form of electronic display device for
displaying decimal numerals. It is usually made up of a number of LEDs
and they have 10 pins that can be used to turn these LEDs on/off to display
the various numerals.
There are two types of Seven segment displays
Common cathode displays and Common anode displays. Their
difference in pin configuration is as indicated in the above figure.
The only difference in the connections is that Common cathode uses GND
at 2 pins (as shown in fig.) and a HIGH to turn the respective LEDs on
while common anode displays use VCC at 2 pins (as shown in fig.) and a
LOW to turn the respective LEDs on
Circuit Diagram:
Connect the VDD pin of DS18B20 to 5V and GND Pin to Ground.
Connect its data pin to digital pin 2 of Arduino and also to 4.7K Resistor
(Connect another end of 4.7K Resistor to 5V) as shown in the figure
below.
Working of the Project:
The DS18B20 Digital Thermometer provides 9 to 12-bit (configurable)
temperature readings which indicate the temperature of the device. It
communicates over a 1-Wire bus that by definition requires only one data
line (and ground) for communication with a central microprocessor. In
addition, it can derive power directly from the data line (“parasite power”),
eliminating the need for an external power supply.
The core functionality of the DS18B20 is its direct-to-digital temperature
sensor. The resolution of the temperature sensor is user-configurable to
9, 10, 11, or 12 bits, corresponding to increments of 0.5°C, 0.25°C,
0.125°C, and 0.0625°C, respectively. The default resolution at power-up is
12-bit.

To design DS18B20 Based Thermometer using Arduino & 4 Digits 7


Segment Display& to display temperature in degree Celsius you need two
different library
1. Download 1 Wire Library
2. Download Dallas Temperature Library
Add these to the library file to Arduino IDE and then simply compile and
upload the code.
Source Code:
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;

const int ledPin = 13;// LED connected to digital pin 13


const int latchPin = 8;//Pin connected to ST_CP of
74HC595
const int clockPin = 9;//Pin connected to SH_CP of 74HC595
const int dataPin = 10;//Pin connected to DS of 74HC595
const int digitPins[4] = {
3,4,5,6}; //pins to control the 4 common anode pins of the display

const byte digit[10] = //seven segment digit bits


{
B00111111, //0
B00000110, //
1 B01011011,
//2 B01001111,
//3
B01100110, //
4 B01101101,
//5 B01111101,
//6
B00000111, //
7 B01111111,
//8 B01101111
//9
};

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.

You might also like