I found a project that counts people passing through one direction door, which I liked but of course I will put my touch on it, So lets see how.
Software and Material used:
For circuits simulation I used Tinkercad (online website), to test the connections before implementation.
Design and Preparations:
When it comes to electronic parts, it is recommended to look at the datasheet of each components to know the operating voltage and current ranges, polarity and if it is connected with more than 2 terminals, and this is very important to avoid damage that can affect all the circuits components.
This circuit consist of a Ultrasonic sensor, 7 segment and a led so lets get more information about them.
Ultrasonic:
This sensor made to calculate the nearest object distance, it can measure up to 16m distance, the tow cylindrical parts are transducers one send an ultrasonic wave and the other receive it and by calculating the duration between sending the signal and receiving it with default sound speed (around 340m\s) it is easy to calculate the distance.
The 4 terminals of the ultrasonic are:
VCC: connected to 5volt
Trig: connecter as output pin to the Arduino
Echo: connected as input pin to the Arduino
GND: connected to the ground.
7 Segment:
This is a simple 7 segment led that can be controlled by it's terminals to show numbers from 0 to 9, this is a common cathode component which means that all the 8 parts (7segments + decimal point) share the same cathode but each has it's own anode.
As shown the 7 segment terminals corresponding to its position, all we need is to set the pins to (high\low) to power the segments needed to present a specific number, but do not forget to put resistors with (220ohm) with every anode to protect the segment from high power.
But what a Resistor is?
resistor is an electronic element that is used to control the voltage that is delivered to a specific part of the circuit.
To simulate this project with Tinkercad open the website, then create a new circuit design, and by drag and drop you can easily bring all of the components to your design.
after dragging the Arduino, Ultrasonic sensor, 7Segmint and LED now its time to set the connections.
With no problems in the simulation, we can go to implement the whole circuit on the breadboard, which is a board that is make circuits testing very easy, by fitting male terminals into it's female bins which are connected together as shown.
Adruino Code File : Door in/out Counter
the counter is presented on 7sigments as it connected to bins (2,3,4,5,6,7,8) respectively to segments litters (a,b,c,d,e,f,g). by setting bins to (high\low), to represent the number from 0 to9.
A variable called (State) is created to avoid multiple count with the same person, when the ultrasonic get the first near distance read it increases the counter by1 and change the (state) to make sure the counter will not count the same person more then once, and when the ultrasonic get far distance read it reset the state variable to allow the next read.
noticing that the 7sigments range is (0-9) so if it reached the maximum value, it will not increase the counter.
The exact same code is used for the second ultrasonic sensor but with another State variable and counter decrement instead of increment.
A variable called (State) is created to avoid multiple count with the The last part of the code is about the led, once the counter get grater then zero and specifically grater than 7 it starts to blink. but if the counter is between 1 and 7 the led just tuned on.
By implementing the circuit exactly the same as the simulation, it will get a little bit crowded weirs as we notice about 20 jumpers is used, so it is hard to clarify the connections using real photos.
This project is designed to count number of people in a 2doors room that allows 7 peoples maximum to be in it at the same time, one ultrasonic for entrance door and the other for the exit door.
As shown at first the led (which simulates the room light) is turned off, and by passing the first person in it turned on and increased the counter by one, this goes for every new person interning the room, and the same goes for the exit door but with decreasing the counter by one, once the counter getting over the maximum capacity of the room (7) the led starts to blink as a sign of over crowding in it there until someone gets out of the room.
The firs time I wrote the code of the ultrasonic sensors like this causing the counter increases more than one time as the it reads near distance and this logical error take me a while to figure out, after I asked one of my peers he advised me to add state variable to avoid this error.