pir.ino 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Description: Human body detection using PIR Unit.
  3. */
  4. #include <M5Stack.h>
  5. void setup() {
  6. M5.begin();
  7. M5.Power.begin();
  8. Serial.begin(115200);
  9. M5.Lcd.clear(BLACK);
  10. M5.Lcd.setTextColor(YELLOW);
  11. M5.Lcd.setTextSize(2);
  12. M5.Lcd.setTextSize(2);
  13. M5.Lcd.setCursor(80, 0);
  14. M5.Lcd.println("PIR example");
  15. Serial.println("PIR example: ");
  16. M5.Lcd.setCursor(65, 10);
  17. M5.Lcd.setTextColor(WHITE);
  18. pinMode(36, INPUT);
  19. }
  20. void loop() {
  21. M5.Lcd.setCursor(0,25); M5.Lcd.print("Status: ");
  22. M5.Lcd.setCursor(0,45); M5.Lcd.print("Value: ");
  23. M5.Lcd.fillRect(95,25,200,25,BLACK);
  24. M5.Lcd.fillRect(95,45,200,25,BLACK);
  25. if(digitalRead(36)==1){
  26. M5.Lcd.setCursor(95, 25);M5.Lcd.print("Sensing");
  27. M5.Lcd.setCursor(95, 45);M5.Lcd.print("1");
  28. Serial.println("PIR Status: Sensing");
  29. Serial.println(" value: 1");
  30. }
  31. else{
  32. M5.Lcd.setCursor(95, 25);M5.Lcd.print("Not Sensed");
  33. M5.Lcd.setCursor(95, 45);M5.Lcd.print("0");
  34. Serial.println("PIR Status: Not Sensed");
  35. Serial.println(" value: 0");
  36. }
  37. delay(500);
  38. M5.update();
  39. }