Directional Human Counter
by abchen in Circuits > Microcontrollers
130 Views, 0 Favorites, 0 Comments
Directional Human Counter
Hello!
In this Instructables page, you will learn now to create a tripwire system that is a directional counter. In case you don't understand what a directional counter with tripwires is, it is a system that can tell direction and add or subtract to a visual counter. In additional to this, every time the tripwire system is triggered, there will be a notification on my phone that tells me that some one has entered or left.
My original plan was to use facial recognition to identify each family member to then send me a notification specifying who it detected. It took me a couple of weeks, iterating through different versions of the Raspberry Pi to find one that could support to OpenCV app that allows you to store faces. I had successfully downloaded OpenCV once on a Raspberry Pi 4 but I ran into many other errors that may have been due to the tutorial that I had been following being a year old. With the limited time I had to at least turn something in, I did this project.
Supplies
- Particle Argon
- Photoresistor
- Leds
- Laser Dioide
- Breadboard
- Pushcut App
Setting Things Up
For starters, you should attach the Particle Argon to the breadboard and use female to female wires to connect the 3V3 to the + rail and the GND pin to the - rail so that we can have easy access to 3V3 and GND all around the breadboard.
Wiring the Photoresistors
Photoresistors give off an analog value so you would need to get a female to female wire to connect each photoresistor its own analog pin, represented on the Argon as a A pin. On one end of the photoresistor, you would attach a resistor, the GND rail, and a analog pin, on the other side of the photoresistor, you would attach it to the 3V3 rail. Do this twice but for the second photoresistor, assign it a different analog pin.
Wiring the Lasers
For the Lasers, you will need some cardboard to create a make-shift box to hold your 3 AA batteries unless you have a battery holder. For this project, I will be creating my own battery holder with cardboard.
- Create a box shape that will hold the batteries(I have two versions above)
- Connect the negative and positive end of the battery with wires
- Once that is done, you will have a positive and negative end remaining
- Solder the positive end to () and the negative end to the ()
- Finally solder the remaining end of the laser to the switch
- Do this twice
The switches are optional, they are only so I don't have to always remove the batteries from the case to prevent battery drainage.
Wiring the Leds
For each LED, you have to assign it a digital pin, labeled as D pins on the argon. You would use a female to male while to connect the LED to the digital pin. Then with a resistor on the whole GND rail, you would attach each LED it the GND rail and its own digital pin. Repeat this for as many LEDs as you have. (The image will only show how to wire one but you can do up to 7 LEDs)
How to Set Up Pushcut Notifications
The app that I used is Puchcut, you can download it for free on you mobile device.
- Download Pushcut app
- Add a notification by clicking the "+" button on the top right
- Name it whatever
- Take the webhook URL that they provide you
- In the Particle Console, create an integration with the webhook
My Code
My code is for 5 LEDs but you can add more or have less, you just have to initialize or remove some of the led int data types to your desired amount.
int resistor1 = A4;
int resistor2 = A3;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int count = 0;
void setup() {
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
}
void loop() {
int val = analogRead(resistor1);
int val2 = analogRead(resistor2);
if(val < 800)
{
delay(1000);
out();
}
if(val2 < 800)
{
delay(1000);
in();
}
delay(100);
}
void out(){
count--;
if(count == 0)
{
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if(count == 1)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if(count == 2)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if(count == 3)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if(count == 4)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
}
if(count == 5)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
}
Particle.publish("Left");
}
void in(){
count++;
if(count == 0)
{
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if(count == 1)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if(count == 2)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if(count == 3)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if(count == 4)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
}
if(count == 5)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
}
Particle.publish("Entered");
}
Finally
Once you have everything hooked up, give power to your Argon through a laptop. Afterwards, you should line up the laser so that it aligns to the photoresistors. Depending on how dark it is in your house, you might need to build a box to cover the photoresistors so that the sharp change in light can be detected. Once that is done, you have completed your project and it should be up and running.