0% found this document useful (0 votes)
28 views

LCD in Out Relay: Liquidcrystal - I2C 0X

The document contains code for an Arduino project that uses a LCD display and sensors to count the number of people entering and exiting a room and controls a light based on if the room is occupied. It initializes the LCD display and pin assignments, defines functions for incrementing and decrementing the counter, and contains the main loop to monitor the sensors and update the display and light.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

LCD in Out Relay: Liquidcrystal - I2C 0X

The document contains code for an Arduino project that uses a LCD display and sensors to count the number of people entering and exiting a room and controls a light based on if the room is occupied. It initializes the LCD display and pin assignments, defines functions for incrementing and decrementing the counter, and contains the main loop to monitor the sensors and update the display and light.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <LiquidCrystal_I2C.

h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);


#define in 14
#define out 17
#define relay 3

int count = 0;

void IN()
{
count++;
lcd.clear();
lcd.print("SO NGUOI:");
lcd.setCursor(0, 1);
lcd.print(count);
delay(1000);
}

void OUT()
{
count--;
if (count < 0)
{
count = 0; // Đặt số người về 0 nếu số người âm
}
lcd.clear();
lcd.print("SO NGUOI:");
lcd.setCursor(0, 1);
lcd.print(count);
delay(1000);
}

void setup()
{
lcd.begin();
lcd.backlight();
Serial.begin(9600);
lcd.setCursor(0, 2);
lcd.print(" HELLO ");
delay(2000);
pinMode(in, INPUT);
pinMode(out, INPUT);
pinMode(relay, OUTPUT);
lcd.clear();
lcd.print("Person In Room:");
lcd.setCursor(0, 1);
lcd.print(count);
}

void loop()
{
if (!digitalRead(out))
IN();
if (!digitalRead(in))
OUT();
Serial.print(count);
Serial.println("");

if (count <= 0)
{
lcd.clear();
digitalWrite(relay, HIGH); // Tắt đèn khi không có người
lcd.clear();
lcd.print("KO CO NGUOI:");
lcd.setCursor(0, 1);
lcd.print("Den Tat");
delay(200);
}
else
{
digitalWrite(relay, LOW); // Bật đèn khi có người
}
}
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);


#define in 14
#define out 17
#define relay 3

int count = 0;

void IN()
{
count++;
lcd.clear();
lcd.print("SO NGUOI:");
lcd.setCursor(0, 1);
lcd.print(count);
delay(1000);
}

void OUT()
{
count--;
if (count < 0) {
count = 0; // Đặt số người về 0 nếu số người âm
}
lcd.clear();
lcd.print("SO NGUOI:");
lcd.setCursor(0, 1);
lcd.print(count);
delay(1000);
}

void setup()
{
lcd.begin();
lcd.backlight();
Serial.begin(9600);
lcd.setCursor(0, 2);
lcd.print(" HELLO ");
delay(2000);
pinMode(in, INPUT);
pinMode(out, INPUT);
pinMode(relay, OUTPUT);
lcd.clear();
lcd.print("Person In Room:");
lcd.setCursor(0, 1);
lcd.print(count);
}

void loop()
{
if (!digitalRead(out))
IN();
if (!digitalRead(in))
OUT();
Serial.print(count);
Serial.println("");

if (count <= 0)
{
lcd.clear();
digitalWrite(relay, LOW);
lcd.clear();
lcd.print("KO CO NGUOI:");
lcd.setCursor(0, 1);
lcd.print("Den Tat");
delay(200);
}
else
{
digitalWrite(relay, HIGH);
}
}

You might also like