一、电路连接
PIR运动检测器
PIR运动检测器引脚 | Arduino引脚 |
---|
VCC | 5V |
GND | GND |
OUT | A0(14) |
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7966e1b63b81b3e8f87c791a174ab66a.png)
LCD1602IIC
LCD1602IIC引脚 | Arduino引脚 |
---|
VCC | 5V |
GND | GND |
SDA | A4 |
SCL | A5 |
我这里的LCD1602是IIC的,所以只需要4根线
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/904d396791d80829be57c192ab01fb57.png)
LED
二、代码
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define PIR_sensor 14
#define ledpin 7
void setup()
{
pinMode(PIR_sensor, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" Automatic ");
lcd.setCursor(0,1);
lcd.print(" Lights opener ");
delay(3000);
lcd.clear();
}
void loop()
{
if(digitalRead(PIR_sensor))
{
lcd.setCursor(0,0);
lcd.print("Movement Detected");
lcd.setCursor(0, 1);
lcd.print(" Lights On ");
digitalWrite(ledpin, HIGH);
delay(1000);
lcd.clear();
lcd.print(" Lights Off ");
digitalWrite(ledpin, LOW);
delay(1000);
}
else
{
lcd.setCursor(0,0);
lcd.print(" No Movement ");
lcd.setCursor(0,1);
lcd.print(" Lights Off ");
digitalWrite(ledpin, LOW);
}
}
三、效果
![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/1167c282ecb93d19b66636e274d62e4a.gif)