Arduino Uno零基础入门学习笔记——LCD1602屏+PIR运动检测器
一、电路连接
PIR运动检测器
VCC |
5V |
GND |
GND |
OUT |
A0(14) |
LCD1602IIC
VCC |
5V |
GND |
GND |
SDA |
A4 |
SCL |
A5 |
我这里的LCD1602是IIC的,所以只需要4根线
LED
二、代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #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);
} }
|
三、效果