Interfacing
of TMP36 Temperature Sensor with an Arduino in Tinkerad.
This project
will turn the Arduino into a thermometer! By using the tmp36 temperature
sensor. We can able to measure our body temperature and turn on the 3 LEDs.
Green LED indicates the low-temperature range, Yellow LED indicates the medium
temperature range and Red LED indicates the high-temperature range. One can
test the circuit starting the simulation, clicking on the sensor, then
adjusting its temperature value using the slider, and can test the desired
resulting LED patterns. For making the actual circuit, you need to use the
Arduino, breadboard, USB cable, male-female jumper wires, three LEDs, three
resistors (any value from 100-1K, 220 ohms), a TMP36 sensor,
Circuit Diagram:
Components Required:
§ Arduino UNO
§ TMP36 (Temperature sensor)
§ Resistor-03
§ LED – Green
§ LED – Yellow
§ LED – Red
§ Connecting wires
Connection:
The hardware
a part of this project is quite simple and easy to place together. First of
all, make the connections for the TMP36 sensor with the Arduino. The
connections for the TMP36 sensor with the Arduino given in the above circuit
diagram:
Connect the
VCC pin of the TMP36 sensor to the 5V pin on the Arduino.
Connect GND
pin of TMP36 sensor to the GND terminal of An Arduino.
Connect the
green LED anode pin to pin no 4 of an Arduino
Connect the
yellow LED anode pin to pin no 3 of an Arduino.
Connect the
red LED anode pin to pin no 2 of an Arduino.
Connect the
cathode of all the LEDs to the Arduino GND.
About TMP 36 Temperature Sensor:
The TMP36
temperature sensor is used to measure temperature using an Arduino in various
applications! This sensor can measure a wide range of temperature range from
-40°C to 125°C, and its low-cost sensor, making it a popular choice. TMP36
gives a voltage output that is straightaway proportional to the outside
temperature. The TMP36 needs a very low voltage power supply to operate, it’s
an accurate temperature sensor.
It won’t
require any external calibration circuitry to give the accuracies of ±1°C at
+25°C and ±2°C over the −40°C to +125°C temperature range. TMP36 creates a
varying voltage output depending on the outside temperature it senses. It has
three pins: one which is connected to the ground, another one connects to 5
volts, and a third one is the output pin which is connected to an analog input
of an Arduino that is A0
Working of project:
As per the circuit diagram,
the output voltage of the TMP36 is connected to the analog input pin of an
Arduino. The analog Pin A0 reads the voltage and gives some analog value to
Arduino. Or in simple words we can say the TMP36 sensor produces a changing voltage
signal depending on the outside temperature it senses So, when temperature
increases, the pin connected to A0 increases its voltage. And You can see in
the circuit diagram that three LEDs are each connected to their digital pin.
This circuit operates in
three mode
When the temperature is low
it will turn on the green LED.
When the temperature medium
it will turn on the yellow LED.
When the temperature is high it will turn on the red
LED.
Code
Explanation (Block Based):
First of all, we create a variable named temp, to store the temperature that is nothing but the sensor value to declare the variable click on the variable block and create a variable, see the below picture.
After declaring the variable drag
out the set block and set to the following blocks
Step to set the variable to “map” or converting temperature into
degree Celsius
Step 1: In the Math section, take out a "map" block, and
merge two arithmetic blocks inside the first field.
Step 2: Set
the temperature range -40 to 125.
Step 3: go
to the Input section and take out an "analog read pin A0" block, and
fix it into the first arithmetic block inside the "map" block.
Step 4: now
set the math’s blocks to "(read analog pin A0 - 20) x 3.04".
After completing all steps, it should look like following picture
Take out the serial monitor block to
print the temperature on the screen
[ Note: About an
Arduino map function
The map function in Arduino is used to change one scale of values
(that is analogue input values) into another scale of values, and a mainly it
is use to read an analogue input which is 10 bit that is it
converts varying voltage to 0 to 1023 using internal ADC (analogue to digital
converter) and map function change the output to desired range of values.for ex.output values from 0 to 255.
Example “C” code:
/* Map an analog value
to 8 bits (0 to 255) */
void setup() {}
void loop() {
int val = analogRead(0);
val = map(val, 0, 1023, 0, 255);
analogWrite(9, val);
}
For reference click here Arduino map function ]
Let’s use the main conditional
statement of the program that is ‘if’ block
first if statement block:
In this if block we will use the
less than “<” comparison operator.
Condition:
If the temperature value is less than 25 degree Celsius then pin 4 will be high and pin no 3 and pin no 2 will be Low. This will make green LED to turn on and other two LEDs will turn off this indicates the low temperature.
Second if statement block:
In this, if block we will use the
three different operators two comparison operator that is less than “<”
comparison operator and “>” greater than comparison operator and last the
logical operator that is “&&” (and) operator
Condition:
If the temperature value is less than 50
degrees Celsius and If the temperature value is greater than 25 degrees Celsius
then pin 3 will be high and pin no 4 and pin no 2 will be Low. This will make
green-yellow LED turn on and other two LEDs will turn off this indicates the medium
temperature.
Third if statement block:
In this, if block we will use the
three different operators two comparison operator that is less than “<”
comparison operator and “>” greater than comparison operator and last the
logical operator that is “&&” (and) operator.
Condition:
If the temperature value is less than 125
degrees Celsius and If the temperature value is greater than 50 degrees Celsius
then pin 2 will be high and pin no 4 and pin no 2 will be Low. This will make
the green-yellow RED turn on and the other two LEDs will turn off this
indicates the high temperature.
[ Note:The logical operators
return TRUE or FALSE, which are defined as 1 and 0, respectively, logical operators use where
needs to make the decision based on multiple conditions.
&& is the logical and operator: it returns a true value only when
if both the conditions are true and returns a false value when both the
conditions are false]
int temp = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
}
void loop()
{
temp = map(((analogRead(A0) -
20) * 3.04), 0, 1023, -40, 125);
Serial.println(temp);
if (temp < 25) {
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
if (temp > 25 &&
temp < 50) {
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
}
if (temp > 50 &&
temp < 125) {
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
}
delay(10); // Delay a little
bit to improve simulation performance
}
|
Glad to read this informative and helpful post, it shares lots of great information, keep sharing such posts.
ReplyDeleteSubmersible Level Transducers