In this project, we will create a temperature & relative humidity & light sensor with an alarm using a buzzer and a red LED. We will display ambient temperature and relative humidity on an LCD (Liquid Crystal Display) screen. In addition, the red LED and the buzzer will be used to indicate if the temperature exceeds a certain limit. Moreover, a blue LED will be used to tell the darkness of the surrounding area: the darker the surrounding environment is, the brighter the LED is.
Step 1: Connect the AMT 1001 sensor to the Arduino
In this step, I connected the AOSONG AMT 1001 temperature/humidity sensor to the Arduino. See the attached file called “pin diagram-amt 1001 sensor” to view the pin diagram of this sensor.
Here are steps that I followed to connect AMT 1001 sensor to the Arduino:
1. Connect Pin Tout (temperature output) with a resistor (R1) of a resistance of 10 k ohms and connect this resistor to the GND on the Arduino. And connect Pin Tout to Pin A5 on the Arduino.
2. Connect Pin Hout (humidity output) to Pin A4 on the Arduino.
3. Connect Pin GND of the AMT sensor to Pin GND on the Arduino.
4. Connect Pin Vcc of the AMT sensor to Pin 5V on the Arduino.
5. Connect the Arduino to the computer and run the code file called “display temperature and humidity.ino”.
6. Open the Serial Monitor from the Arduino to see the output. (You can find the Serial Monitor from the “Tools” button.) (You should see the output like the one in the attached picture called “display temp and humi”.)
7. Use the heat gun towards the sensor to see if the values for temperature and the relative humidity change.
You can also use the attached diagram called “circuit-how to connect buzzer, amt1001, and lcd to the Arduino.png” to help you connect the AMT 1001 sensor to the Arduino.
Inside the attached code file, there are two functions: getTemp() to get Temperature() and getHumi() to getHumi. In the following paragraphs, I will explain how I came up with codes for these functions:
The AMT 1001 sensor has two main components: a 10k ohms thermistor and a humidity sensor. The thermistor is a negative temperature coefficient (NTC) thermistor. This means that, when the temperature increases, NTC thermistor resistance will decrease. But the relationship between the temperature and the resistance is not linear. However, the good news is that researchers have found that the beta parameter equation (a simplification of the Steinhart-Hart equation) provides a good approximation of the thermistor’s temperature response curve. And we will use the beta parameter equation shown below to convert the resistance of the thermistor to a temperature reading:
1/T = 1/T0 + 1/B * ln(R/R0) (1)
The variable T is the ambient temperature in Kelvin, T0 is the room temperature, also in Kelvin (25°C = 298.15K), B is the beta constant which is provided in the datasheet of this sensor (beta = 3435), R is the thermistor resistance at the ambient temperature, and R0 is the thermistor resistance at temperature T0, which is 10k ohms. Since the Arduino cannot read the resistance of the thermistor directly and it can only read voltage, we need to create a voltage divider to calculate the thermistor’s resistance. So the first step is to connect Pin Tout (temperature output) with a resistor (R1) with a resistance of 10k ohms and connect this resistor to the ground (for the position of the Pin Tout, see the pin diagram of this sensor in the attached file called “pin diagram-amt 1001 sensor”). For the diagram of this volage divider, see the attached file called “voltage divider for amt 1001.jpeg”. From the diagram of this voltage divider, we can see that
Vout = Vcc * (R1 / ( Rth + R1 )), (2)
Rth = R1 * (( Vcc / Vout ) - 1). (3)
Then, connect the Pin Tout to the Pin A5 on the Arduino. Since Arduino reads the digital voltage, we need to first convert the digital voltage to the analog voltage in order to use Eq. 3. And the relationship between the analog voltage and the digital voltage is:
1023 / digital voltage = Vcc / Vout (analog voltage) (4),
where digital voltage is from the Arduino and analog voltage is from the sensor.
By combining Eq. (1), (2), (3), we can get
T = 1/(1/T0 + 1/B * ln( ( 1023 / digital voltage ) – 1 )). (5)
And this is how the getTemp() function in the attached code file works. So the Arduino first reads digital Vout from A5 and getTemp() function uses this Vout and Eq. 5 to calculate the temperature.
Moreover, the humidity sensor has been calibrated in a lab in such a way that there is a linear relationship between the relative humidity and the voltage measured in Pin Hout:
RH = voltage * 33.33/1000. (6)
Thus the Arduino first reads digital Vout from Pin A4. Then getHumi() function converts this digital Vout to the analog Vout by using Eq. 4. Lastly, this function uses Eq. 6 to get the relative humidity.
Step 2: Connect the 16 * 2 LCD (Liquid crystal display) to the Arduino.
In this project, we will use a 16x2 LCD to display the temperature and humidity. The reason that it is called a 16x2 LCD is that LCD has 2 lines and can display characters per line. Hence, a 16 x 2 LCD screen can display up to 32 characters at once.
The LCD is shorthand for Liquid Crystal Display, which is a type of flat panel display using liquid crystal in its primary form of operation. This display contains a grid of liquid crystal pixels held between layers of glass etched with transparent electrodes. Liquid crystal molecules are normally twisted, but untwisted when electricity is applied to them. This affects the way light passes through the pixel, allowing it to appear either darkened or undarkened. Inside this display, there is an HD44780 controller chip that receives commands from Arduino, and this chip turns the pixels on and off to form various letters, numbers, and symbols.
This LCD has 16 pins and it is polarized. The pins are numbered from left to right, 1 through 16. See the attached figure called “pin diagram-LCD.png” to view a list of each of the pins on the LCD. I used the following guide and the attached figure called “circuit-how to connect buzzer,amt1001, and lcd to the Arduino” to connect these bins to the Arduino:
Pin 1 (GND pin) needs to be connected to the GND pin of the Arduino.
Pin 2 (Vcc pin, the power supply for the LCD) needs to be connected to 5V of the Arduino.
Pin 3 (LCD contrast pin: it controls the contrast and brightness of the LCD) needs to be connected to a 5k potentiometer.
Pin 4 (Register Select Pin): if we want to send the command to control LCD, we need to set the RS pin to High. If we want to send the data to display on the LCD, we need to set this pin to LOW.
Pin 5 (Read/Write Select Pin): If we want to read data from LCD, this pin needs to be HIGH. If we want to send data to LCD, this pin needs to be LOW. Since I wanted to display the data, I connected this pin to the GND.
Pin 6 (Enable Pin)
Pins 7-10 (data lines d0-d3) (not used)
Pins 11-14 (data lines d4-d7) (data transferred in 4-bits at a time)
Pin 15 (backlight power) needs to connect to 5V
Pin16 (backlight GND) needs to connect the GND.
You can also see the picture called “circuit real -LCD.jpeg” to view how I connected the LCD to the Arduino.
Since it is very complicated to use the Arduino to control the HD44780 controller chip, we used LiquidCrystal library provided by the Arduino community to control this chip. This LiquidCrystal library has different functions for us to display information on the LCD. In the code file called “code_final project”, you can see that we directly send the calculated temperature and humidity to the LCD by using functions in the LiquidCrystal library. Once you have connected the Amt 1001 sensor and the LCD to the Arduino, you can run the code file called “code_final project” to see the temperature and relative humidity values on the LCD.
Step 3: Connect the HYD-4128 buzzer to the Arduino
When the temperature is above a certain value, we want the buzzer to be alarmed. The HYD-4128 buzzer is an active buzzer, meaning that we can directly apply a DC voltage to the buzzer without using any resistors. Thus, connect the red line of this buzzer to Pin 7 on Arduino and connect the black line of this buzzer to the GND on the Arduino. Since the buzzer will be alarmed only when the temperature is bigger than a specified limit, in the code file called “code_final project”, you can see there is an if statement that is used to specify the temperature limit and when the buzzer will be alarmed. If the value of the ambient temperature is bigger than the specified value, then the Arduino will send a 5V DC voltage to activate the buzzer. (See the attached figure called “circuit real-buzzer connection.jpeg” about how to connect the buzzer to the circuit.)
Step 4: Create a sound-activated switch
When the buzzer is alarmed, the Red LED will be lit up. This means that we need to create an automated sound-activated switch to achieve this function. I followed the attached circuit diagram called “circuit-sound activated switch” and the pin diagram of the 555 timer to build this switch (also view the attached picture called “circuit real - sound-activated switch.jpeg” to see the circuit using real components). Remember to connect this circuit to the Arduino’s 5V pin and the GND pin.
The main component of this switch circuit is the electric Condenser Mic, which has been used as a sound sensor. Condenser Mic converts sound energy from the surrounding environment into electrical energy. And such energy will raise the potential at the base of the 2N2222 NPN transistor, which will turn on this transistor. As soon as the transistor turns on, the potential at the trigger of the 555 timer will be low and such low potential will trigger the 555 IC timer. Then, the output of the 555 timer will be HIGH and there will be sufficient voltage to activate the LED. The LED will remain turned on for 1.1*R3*C2 seconds if the sound source is transient. But since the buzzer will keep alarming, the LED will always be turned on in our case. Note: the LED is a type of diode, which means it only allows current to flow in the circuit when the anode is at a higher voltage than the cathode. Normally, the longer leg of an LED is the anode. So, remember to connect the LED in the right way. And for this step, Arduino does not send commands to this circuit. Arduino is the power source of this circuit.
Once you have built this circuit, clap your hands to see if the LED turns on.
Step 5: Create a dark detector LED circuit
The dark detector circuit is used to tell how dark the surrounding environment is. Additionally, it helps the user quickly find our sensor in a dark environment. This circuit will automatically control and turn the blue LED on and off based on the brightness of ambient light. To build such a circuit, I used a light-dependent resistor (LDR). The resistance of the LDR is inversely proportional to the intensity of light. This means, in a dark environment, the resistance of the LDR is very big, while its resistance is very small in a bright environment. In addition, I used a 2N222 NPN transistor as the switch which is used to turn on or off the LED.
First, follow the attached circuit diagram called “circuit-diagram dark detector LED” to build this circuit. (Also check the picture “circuit real-dark detector LED.jpeg” to see the circuit using physical electronic components.) Connect this circuit to the Arduino’s 5V pin and the ground pin. Once you have built the circuit, test the function of this circuit by putting it in a dark environment. You will see that the LED is lit up. This is because, the resistance of the LDR is very big in a dark environment, which makes the voltage at the base of the transistor be high enough to activate the transistor. Once the transistor turns on, the LED will turn on. But if we put this circuit in a bright environment, the small resistance of the LDR is low and correspondingly the voltage at the base of the transistor is also very low, resulting in failing to activate the transistor, which in turn there is no current flowing through the LED. If your circuit does not behave as I have described above, try to vary the brightness of the ambient environment and measure the corresponding voltage between the LDR and the ground. Do you see that the value of voltage changes as your change the ambient light brightness?
Step 6: run the code file called ""final_electronics.ino".
Now I have built all components that I need. Then I ran the code "code_final_electronics.ino" to see if my circuits measure and display the temperature and humidity. And I also used a heat gun to change the surrounding temperature manually to check if the buzzer and the red LED will turn on. Lastly, I put my sensor in a dark environment to see if the blue LED will turn on. You can see the videos called "demo1" to see the functions of my circuits.