Humidity sensor with led alarm | Arduino project


This page contains Arduino Humidity sensor with led alarm source code. This project is good for someone who wants to make a humidity meter or hygrometer with led alarm if humidity and temperature over a threshold. It's easy to make and doesn't require an external power supply, just use power from an Arduino UNO R3 board (USB power compatible with this project).

Electronic components list:
1 x Arduino Uno R3
1x 20 x4 I2C LCD display
1 x AM 2320 humidity/temp sensor
1 x 5 mm led ( 2 x if you plan to use led for pin 13 instead built-in led)
1 x 1000 ohms resistor ( 2 x if you plan to use led for pin 13 instead built-in led)
Any USB power adapter, 500 mA current at least.

Here is the Arduino code:
AM 2320 library https://github.com/hibikiledo/AM2320
LCD display i2c library https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library


#include <Wire.h>
#include <AM2320.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
AM2320 th;
int led2 = 12;
void setup() {

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(led2, OUTPUT);
 lcd.begin();
}

void loop() {
  switch(th.Read()) {
    case 2:
      lcd.print("CRC failed");
      break;
    case 1:
      lcd.print("Sensor offline");
      break;
    case 0:
    lcd.setCursor(0, 0);
      lcd.print("humidity: ");
      lcd.setCursor(10, 0);
      lcd.print(th.h);
      lcd.print("%");
    lcd.setCursor(0, 2);
      lcd.print("temperature: ");
      lcd.setCursor(13, 2);
      lcd.print(th.t);
      lcd.print("*C");
       break;}
      if (th.h > 55) {digitalWrite(LED_BUILTIN, HIGH);// turn the LED on (HIGH is the voltage level)
       }else {digitalWrite(LED_BUILTIN, LOW);// change humidity threshold (default is 55 percent)
           
       }
 if (th.t > 31.2) {digitalWrite(led2, HIGH);// turn the LED on (HIGH is the voltage level)
       }else {digitalWrite(led2, LOW); // change temperature threshold (default is 31.2 c)
           
       }

{  delay(500);
}
}


Copy the code to your Arduino IDE and you got what you want.
See how it work in this video.




Comments

Popular posts from this blog

How to add power supply filter capacitor to amplifier board.

Resistor color code

How to connect volume control to an amplifier

10 watts 8 ohms class d amplifier pam8610 sound test

Infrared proximity sensor circuit diagram

simple bass booster circuit diagram

lm3914 schematic diagram and test

how to repair water damage particle board

Hall effect sensor wiring diagram and test video