Thursday, 17 October 2024

Integrate Temperature Sensor with Arduino

In this experiment, we have integrated a temperature and humidity sensor (DHT 11) with Arduino. To check, if the integration is successful, we have tested following two cases:

  • When we bring the ice-pack closer to temperature sensor, the temperature should drop. When it drops to 29 degrees (which is visible on LCD), the buzzer should start ringing and LED should start glowing.
  • When we take the ice-pack away from the temperature sensor and supply body heat to the sensor, the temperature should increase. The buzzer should stop ringing and LED should stop glowing once the temperature reaches 30 degrees.
Given this experiment, we have four components which we need to integrate with Arduino. They are listed below:
  1. Passive Buzzer
  2. LCD Display
  3. LED
  4. Temperature Sensor (DHT 11)
The pin connections of these components are shown in the circuit diagram given below.  


Let me explain the pin connections:

Passive Buzzer: This buzzer has two pins "+" and "-", which are connected to Pin 5 and GND of Arduino respectively. The tone required for passive buzzer to produce the sound, is outputted onto pin 5 programmatically. (I will explain the CPP program later in this article). The passive buzzer image is shown below along with its pin identification for reference.




 LCD Display: The LCD display has following connections.
  • Arduino Digital Pin 7 - Connected to pin DB7 of LCD Display
  • Arduino Digital Pin 8 - Connected to pin DB6 of LCD Display
  • Arduino Digital Pin 9 - Connected to pin DB5 of LCD Display
  • Arduino Digital Pin 10 - Connected to pin DB4 of LCD Display
  • Arduino Digital Pin 11 - Connected to pin E of LCD Display
  • Arduino Digital Pin 12 - Connected to pin RS of LCD Display
  • Potentiometer '+' pin - Connected to Vcc
  • Potentiometer '-' pin - Connected to GND
  • Potentiometer 'Data' pin - Connected to pin V0 of LCD Display
  • Vcc 5V - Connected to pin LED+ of LCD display (through 220 ohms resistor)
  • GND - Connected to pin LED- of LCD display     
  • Vcc 5V - Connected to pin VDD of LCD display 
  • GND - Connected to pin Vss of LCD Display
  • GND - Connected to pin R/W of LCD Display
An image of the LCD Display compatible with Arduino UNO is as shown below.


NOTE: Please refer to the references section for more information about LCD connections. Although we are giving a useful tip here. LCD's onboard potentiometer is used to control the light intensity of the display, which will make the characters getting displayed more clearly.

LED: As shown in the circuit diagram, the anode (the large leg) of the LED is connected to pin 6 of Arduino. Whereas the cathode (the short leg) of LED is connected to ground of Arduino. 

Temperature Sensor (DHT 11 sensor): It records the local environment data especially the temperature and humidity. An image of the DHT 11 sensor is shown below for reference.  


This sensor has 3 pins. The 'S' pin (the signal pin) of DHT 11 goes to pin 2 of Arduino. The middle pin goes to Vcc. And the remaining pin goes to the GND. 

NOTE: Please go through the article about DHT 11 mentioned in the reference, in order to get more details about the functioning of the sensor.

Power Supply: We connect Arduino Uno to laptop, which acts as a +5V power source. 

Now that we have connected all the components of the circuit together, let's write an Arduino program to drive the circuit. The CPP code for the program is shared below. The program functions in two modes "Initialization" and "Loop". The initialization code is written in "setup" method. "setup" method gets executed only once in the lifecycle of Arduino program execution. The setup method includes the following:
  • The serial baud rate for printing the debug statements on the serial monitor is set to 9600 bps
  • Arduino's pin 5 is set in OUTPUT mode for outputting the buzzer melody. This melody will be played when the temperature will drop to 29 degrees
  • LCD is initialized to 16 columns and 2 rows display. That means totally 16 x 2 characters can be printed on to the LCD. We have written a static text "The temp is: " on the LCD
NOTE: We are not explaining the debug statements which are printed on to the serial monitor with the statements Serial.print

Let's explain the processing of "Loop":
  • We set the temperature and the humidity to zero at the start of the loop
  • These values will get further populated on calling the dht11.read method
  • We give 1 sec of delay to sample the readings of dht11 sensor, that means after every 1 sec the LCD display will get refreshed with the new value of temperature
  • We call lcd.setCursor(0, 1), that means the temperature will start getting printed from the 0th column and 1st row of the display matrix
  • When the temperature goes less than 30, we perform a digital write HIGH to pin number 6, which will make the LED glow. We also output the melody to pin 5 of the buzzer for 1.5 sec. As a result the buzzer starts ringing
  • When the temperature goes above 30, we perform a digital write LOW to pin number 6, which will turn off the LED. We will not play any tone during this time

References:


No comments:

Post a Comment