Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
R
Published © GPL3+

PeopleCount

A LoRa enabled sensor which logs foot traffic in its sensing area providing data to better gauge social distancing over a given time.

BeginnerFull instructions provided3 hours1,001
PeopleCount

Things used in this project

Hardware components

PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
SMA edge mount
×1
Tinned Copper Wire, Solid
Tinned Copper Wire, Solid
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Helium Developer Kit
Helium Developer Kit
×1

Software apps and online services

Helium Console
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Plier, Long Nose
Plier, Long Nose
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Programmer.zip

Unzip the file for full programming environment

Schematics

Image of wiring

Code

index.ino

C/C++
This is the only code required to build the sensor. Just copy and paste it into the arduino IDE
#include "LoRaWAN.h"
//User keys 
const char *devEui = "FILLMEIN";
const char *appEui = "FILLMEIN";
const char *appKey = "FILLMEIN";

//variables
int pirState = LOW;
int inputPIR = PA9;
int watch = 0;
int cout = 0;
int val = 0;
void setup( void )
{
    Serial.begin(9600);
    pinMode(inputPIR, INPUT);
    while (!Serial) { }

    // US Region
    LoRaWAN.begin(US915);
    // Helium SubBand
    LoRaWAN.setSubBand(2);
    // Disable Adaptive Data Rate
    LoRaWAN.setADR(false);
    // Set Data Rate 1 - Max Payload 53 Bytes
    LoRaWAN.setDataRate(1);
    // Device IDs and Key
    LoRaWAN.joinOTAA(appEui, appKey, devEui);

    Serial.println("JOIN( )");
}

void loop( void )
{
 Serial.println("Loop begin");
 //read the sensor and check if their is movement and update people counter
 val = digitalRead(inputPIR);
 if (val == HIGH){
    cout = cout+1;
    if (pirState == LOW){
      pirState = HIGH;
    }
 } else {
  if(pirState == HIGH){
    pirState = LOW;
  }
 }
 //Check if 12 hours have passed and their is coverage. If that is fuffiled send a packet
    if (watch == 21600 && LoRaWAN.joined() && !LoRaWAN.busy())
    {
        Serial.print("TRANSMIT( ");
        Serial.print("TimeOnAir: ");
        Serial.print(LoRaWAN.getTimeOnAir());
        Serial.print(", NextTxTime: ");
        Serial.print(LoRaWAN.getNextTxTime());
        Serial.print(", MaxPayloadSize: ");
        Serial.print(LoRaWAN.getMaxPayloadSize());
        Serial.print(", DR: ");
        Serial.print(LoRaWAN.getDataRate());
        Serial.print(", TxPower: ");
        Serial.print(LoRaWAN.getTxPower(), 1);
        Serial.print("dbm, UpLinkCounter: ");
        Serial.print(LoRaWAN.getUpLinkCounter());
        Serial.print(", DownLinkCounter: ");
        Serial.print(LoRaWAN.getDownLinkCounter());
        Serial.println(" )");

        // Send Packet
        LoRaWAN.beginPacket();
          LoRaWAN.write(cout);
         LoRaWAN.endPacket();
         //reset timer
         watch = 0;
    }

    delay(2000); //2 Seconds
    watch = watch + 1; //add that 2 seconds have elapsed to the timer
}

Credits

R

R

2 projects • 0 followers

Comments