Close

PIR Senor Play

A project log for Simple, Scrolling, RTC Clock

Amuse-myself-for-a-couple-of-hours-Scrolling-Clock with an Arduino Uno, generic, 8x8 led matrices, and a RTC.

peterPeter 09/05/2019 at 21:090 Comments

At night the clock can get kind of bright and during the day it is just the dog watching the clock. I wanted a clean way to display the time without having to push a button. 

Well, I have a HC-SR501 PIR Sensor laying around. So tonight (I don't have the clock with me) and going to play around some. I want to get the skeleton code to add to the clock when I get home. I added a 8x8 matrix display, it makes it a little more like the project that it will integrate into. 

// Libraries required
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>

// Definitions and variables
#define pirPin 2
int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;

// Setup the 8x8 matrix
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

void setup() {
   Serial.begin(9600);
   pinMode(pirPin, INPUT);
   matrix.begin(0x74);
}

void loop() {

   // Calling the sensor function 
   PIRSensor();
}

void PIRSensor() {
   // If there is motion, put something on the scree
   if(digitalRead(pirPin) == HIGH) {
      if(lockLow) {
         PIRValue = 1;
         lockLow = false;
         Serial.println("Motion detected.");
         matrix.clear();
         matrix.setCursor(2,1);
         matrix.print("B");
         matrix.writeDisplay();
         delay(50);
      }
      takeLowTime = true;
   }
   // No more motion, clear the screen
   if(digitalRead(pirPin) == LOW) {
      if(takeLowTime){
         lowIn = millis();takeLowTime = false;
      }
      if(!lockLow && millis() - lowIn > pause) {
         PIRValue = 0;
         lockLow = true;
         Serial.println("Motion ended.");
         matrix.clear();
         matrix.writeDisplay();
         delay(50);
      }
   }
}

Discussions