Jonathan BroomeJulian Doe
Published

The COVID Counter

The COVID Counter is used to track the number of customers within a store at any given time due to the capacity limits of the pandemic.

IntermediateFull instructions provided467
The COVID Counter

Things used in this project

Hardware components

Argon
Particle Argon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×2
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Development Kit Accessory, Jumper Wire Kit
Development Kit Accessory, Jumper Wire Kit
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Entrance Argon

Exit Argon

Code

Exit Argon

C/C++
This code is used to tally the amount of customers exiting a store. As the motion sensor is tripped, the argon's built-in LED lights up and data concerning the trip is published to a particle console as a "-1" under the event titled, "Exit data"
// The Covid Counter Exit Argon by Julian Doe and Jonathan Broome

// The following code is used to tally the amount of customers leaving a business
// This Argon should be paired to a PIR motion sensor
// This data obtained is relayed back to the Particle console, where the Entrance Argon can collect the data

int ledPIN = D7;
int PIRsensor = D5;
int pirState = LOW;    //Initial State = No motion



void setup() {
    pinMode(PIRsensor, INPUT);  //This states the PIRsensor will be an input function
    pinMode(ledPIN, OUTPUT);    //This states the ledPIN will be an output function
}

void loop()  {
    delay(10);
    if (digitalRead(PIRsensor) == HIGH) {  //If there is motion
      digitalWrite(ledPIN, HIGH);  //LED turns on
      delay(1000);
      Particle.publish("Exit data", "-1", PUBLIC); //relays data to console to show motion sensor has been tripped for someone exiting the store
      delay(1000);
   }
    else {
        digitalWrite(ledPIN, LOW);   //LED turns off
   }
}

Entrance Argon

C/C++
This code is used to track how many customers enter the store and extracts data from the "Exit data" event in order to calculate the total number of customers at any given time. An LCD module is used display the calculated customer count as well as a "WELCOME!" message when the store is below capacity and a "DO NOT ENTER" message when the store reaches capacity. The entry and exit data is sent to a console event titled, "Customers". This data is then sent to a real-time graph through the ThingSpeak platform and is used to plot the exact number of customers at a given time. In order for the code to work properly, the ThingSpeak.h library and the LiquidCrystal.h library must be included in the app.
// The Covid Counter Entrance Argon by Julian Doe and Jonathan Broome

// The following code is used to keep track of how many customers are within a store at an exact time
// This Argon should be paired with a PIR Motion Sensor and an LCD 1602 Module
// As motion is detected, customer count is added up by the Entrance Argon
// The Entrance Argon pulls data from the Exit Argon to subract customers as they pass the exit and the exact number of customers is kept on display
// The produced data is relayed to ThingSpeak in order to create a real-time data trend
// A store capacity of 20 customers is assumed, but this is subject to change depending on the business


// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.h>

LiquidCrystal lcd(6, 4, 3, 2, 1, 0); //Declare pins of the LCD module
int ledPIN = D7;   //Built in argon LED
int PIRsensor = D5;    //Pin of PIR motion sensor
int pirState = LOW;    //No motion assumed
int val = 0;      //Variable for reading the pin status
int counter = 0;     //Initial customer count is zero
int currentState = 0;
int previousState = 0;
void confirm(const char *event, const char *data);  //Forward Declaration
byte skull[] = {   //Custom 8 byte design for skull 
	0b01110,
	0b11111,
	0b10101,
	0b11011,
	0b01110,
	0b01110,
	0b00000,
	0b00000
};
byte smile[] = {   //Custom 8 byte design for smiley face
    0b00000,
	0b01010,
	0b01010,
	0b00000,
	0b10001,
	0b01110,
	0b00000,
	0b00000
};
int state = 0;  //Zero motion is assumed
int Customers = 0;  //There are initially zero customers
TCPClient client;
unsigned int myChannelNumber = 1250092;  //Replace with your ChannelID
const char * myWriteAPIKey = "5IPA2W9YVJM8W39N";  //Replace with your WriteAPIKey

void setup() {
     Particle.subscribe("Exit data", confirm);   //Pull data from the exit argon's console
     pinMode(ledPIN, OUTPUT);   //Declare LED as output
     pinMode(PIRsensor, INPUT); //Declare sensor as input
     lcd.begin(16, 2);    //specify column and row count of lcd module
     lcd.setCursor(0,1);  
     lcd.print("Customers:");
     lcd.setCursor(4,0);
     lcd.print("WELCOME!");
     lcd.createChar(0, skull);   //create skull design
     lcd.createChar(1, smile);   //create smile design
     lcd.setCursor(2,0);
     lcd.write((byte)1);    //print smile design
     lcd.setCursor(13,0);
     lcd.write((byte)1);    //print smile design
     ThingSpeak.begin(client);
}
void loop(){
    val = digitalRead(PIRsensor);   // read PIR sensor input value
    if (val == HIGH) {       // check if the input is HIGH
            digitalWrite(ledPIN, HIGH);    // turn LED ON
            if (pirState == LOW) {  
                currentState = 1;
                pirState = HIGH;
                delay(1000);
           }
   } 
    else {
        digitalWrite(ledPIN, LOW);  // turn LED OFF
        if (pirState == HIGH){
            currentState = 0;
            pirState = LOW;
       }
   }
    if(currentState != previousState){
        if(currentState == 1){
           counter = counter + 1;  // Adds a customer to previous customer count
           lcd.setCursor(11,1);  
           lcd.print(counter);   //Displays new number of customers in the store
           Particle.publish("Customers","+1");  //Relays change to console
           state = !state;
           Customers= Customers+1;  //Customer tallied for ThingSpeak data
           unsigned long now = millis();
           ThingSpeak.setField(1,Customers);
           ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  
           delay(1000);
       }
            if(counter >= 20){  //set maximum amount of customers allowed in the store at any given time
               lcd.clear(); //clears display
               lcd.setCursor(2,0);
               lcd.print("DO NOT ENTER");
               lcd.setCursor(0,0);
               lcd.write((byte)0);  //prints skull design
               lcd.setCursor(15,0);
               lcd.write((byte)0);  //prints skull design
               lcd.setCursor(0,1);
               lcd.print("Customers:");
               lcd.setCursor(11,1);  
               lcd.print(counter);   //Displays new number of customers in the store
           }
            if(counter == 0){     //this statement is to drop the extra digit left behind by the -1 
               lcd.clear();   //clears display
               lcd.setCursor(4,0);
               lcd.print("WELCOME!");
               lcd.setCursor(2,0);
               lcd.write((byte)1);    //print smile design
               lcd.setCursor(13,0);
               lcd.write((byte)1);    //print smile design
               lcd.setCursor(0,1);
               lcd.print("Customers:");
               lcd.setCursor(11,1);  
               lcd.print(counter);   //Displays new number of customers in the store
           }
   }
     
}

void confirm(const char *event, const char *data){  //called when "-1" data is published to the console from the exit argon
    if(strcmp(data,"-1")==0) {
       counter = counter - 1;  //subtracts customer from customer total
       lcd.setCursor(11,1);
       lcd.print(counter);
       Particle.publish("Customers","-1");  //relays change to console
       state = !state;
       Customers= Customers-1;  //Customer count is calculated for ThingSpeak 
       //       delay(1000);
       unsigned long now = millis();
       ThingSpeak.setField(1,Customers);
       ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  
        if(counter == 19) {   //this statement is to revive the welcome sign once store is below capacity
            lcd.clear();   //clears display
            lcd.setCursor(4,0);
            lcd.print("WELCOME!");
            lcd.setCursor(2,0);
            lcd.write((byte)1);    //print smile design
            lcd.setCursor(13,0);
            lcd.write((byte)1);    //print smile design
            lcd.setCursor(0,1);
            lcd.print("Customers:");
            lcd.setCursor(11,1);  
            lcd.print(counter);   //Displays new number of customers in the store
       }
        if(counter == 9) {  //this statement is to drop the extra digit left behind from the 10
            lcd.clear();   //clears display
            lcd.setCursor(4,0);
            lcd.print("WELCOME!");
            lcd.setCursor(2,0);
            lcd.write((byte)1);    //print smile design
            lcd.setCursor(13,0);
            lcd.write((byte)1);    //print smile design
            lcd.setCursor(0,1);
            lcd.print("Customers:");
            lcd.setCursor(11,1);  
            lcd.print(counter);   //Displays new number of customers in the store
       }
        if(counter == 99) {   //this statement is to drop the extra digit left behind from the 100
            lcd.clear(); //clears display
            lcd.setCursor(2,0);
            lcd.print("DO NOT ENTER");
            lcd.setCursor(0,0);
            lcd.write((byte)0);  //prints skull design
            lcd.setCursor(15,0);
            lcd.write((byte)0);  //prints skull design
            lcd.setCursor(0,1);
            lcd.print("Customers:");
            lcd.setCursor(11,1);  
            lcd.print(counter);   //Displays new number of customers in the store
       }
   }
}

Credits

Jonathan Broome
1 project • 1 follower
Contact
Julian Doe
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.