People Counter

by cxu42 in Circuits > Arduino

332 Views, 0 Favorites, 0 Comments

People Counter

Screen Shot 2022-05-09 at 9.01.38 PM.png
Screen Shot 2022-05-09 at 9.02.57 PM.png
Screen Shot 2022-05-09 at 9.03.33 PM.png
Screen Shot 2022-05-09 at 9.18.52 PM.png

During the brainstorming phase, we focused our efforts on interviews that explored the experiences of humans utilizing the MTD bus system. In addition, we practiced empathetic listening in order to expand our views of the transportation experience beyond what we had witnessed as students. In the interviews, we learned that the bus system was utilized mostly by underclassmen as well as off-campus students. In addition, we learned that the user experience is a priority for students. Finally, we saw that the more popular routes were less efficient because of the large crowds. This led us to realize that the accessibility of information and data regarding crowds and user trends would greatly change the MTD system for the better. We decided to build a system to help us keep track of the number of passengers on buses. This number will be broadcasted on a site and the data will be compiled to MTD to use for product improvement. With this information, MTD can better optimize bus routes to eliminate buses that run empty or increase the bus frequencies during peak hours on specific routes.

During the ideation phase, the team went out in the field to better understand the current bus system and how it functions on a day-to-day basis. We took data points on whether or not students would choose to walk overtaking the bus, as well as the number of students that found buses to be crowded. In addition, through observation, we saw that buses start to become congested between 10:00 AM and 3:00 PM while students head to and from class. This is seen primarily on the 22N or 22S. Finally, we used academic resources to gain more general information from transportation systems across the country. From this, we saw the statistic that “passengers feel uncomfortable when they perceive there’s less than a 40% probability of getting a seat” (Ridango, 2). This led our team to conclude that controlling crowds and increasing route efficiency would be our goals. This led us to the idea of using IR sensors to keep a net count of riders on each bus.

Supplies

Bill of Materials

Cost IR Sensor, Quantity: 2, $3.59

Wires (Male to Male, Male to Female), Quantity: 25, $6.89

Photon Wifi, Quantity: 1, $19.65

Arduino Uno, Quantity: 1, $23.00

LCD Display, Quantity:1, $9.19

Breadboard

1 $5.00

Setting Up IR Sensors

Screen Shot 2022-05-09 at 9.05.57 PM.png

After obtaining the materials, we worked on creating the IR sensor circuit. This was particularly difficult for us as we have very limited experience with wiring. We used a lot of blog posts and YouTube videos and ultimately used one from dpvtechnology.com for a reference point. Originally, we planned on having four IR sensors, two on either side of an entrance. However, the IR sensors we got were able to track objects with the sensor on one side. Therefore, we used the circuit diagram below and changed up the coding to fit our project, again, referencing dvptechnology.com.

Code the IR Sensors & Final Box Designs

Screen Shot 2022-05-09 at 9.07.17 PM.png

After building the circuit, we focused on coding. We were having trouble with the sensors noting the middle space as the “room” rather than the far left edge as “inside” and the right edge as “outside.” Additionally, there was a lot of calibration work needed as the sensors were only picking up the object sometimes. In tweaking the code and testing the sensors we realized a few things. The delay time changes how quickly the sensor will read an object after it reads one initially. We increased this to account for the speed at which individuals board a bus. Secondly, the IR sensors need to be a few inches apart from each other and need to be registered by both sensors to be counted as “inside” or “outside”. We also realized that we needed to use a large and opaque object to test the sensors, rather than just our hands. A bigger water bottle worked well for this.

We thought through many design iterations to visualize what the box could potentially look like to house the Arduino UNO. In the end, we decided on a sliding door mechanism with two ellipses on one end of the box to allow for the IR sensors to operate. We went for a sliding door because it would make it difficult for the box to come unhinged on accident but also makes it simple to open if we needed to change out any components. As mentioned previously, we designed the box on Fusion 360.

Through trial and error, we found that the 3D printed box is better than any other material because we are able to control the thickness of the box better. For our sensor to work, we needed to fully expose the IR sensors. We also discovered that prior to printing we have to use the split command to separate the two components. Additionally, it was a lot easier if we separated the two components into two different save files. These two steps made printing a lot easier.

Here is the link to our final box: Box: https://a360.co/3JPS4eB Lid: https://a360.co/3JPS4eB

Dimensions: Length: 154mm, Width: 90mm, Height: 50mm, Thickness: 2mm, Clearance: 0.25mm

Once we were able to get the IR sensors properly coded and working at the desk, we decided to test it with humans and placed the sensor on a raised surface near the door. At this point, we realized that the person had to be very close (only a few inches away) from the sensors for it to register the person. This did not make sense as the specifications of the sensors detect about 30cm or 1 foot away. This is where the potentiometer comes in. The little screw-like object on the top needs to be turned clockwise until just before the light stays continuously green. This helped increase the distance by about 6 inches. The potentiometer is very sensitive and requires very small adjustments. This may take a while to figure out and adjust.

LCD Display and Photon Particle Configuration

Screen Shot 2022-05-09 at 9.30.29 PM.png
Screen Shot 2022-05-09 at 9.30.34 PM.png
Screen Shot 2022-05-09 at 9.09.14 PM.png

After getting the sensors calibrated, it was time to connect the LCD display. We used a 16x2 display that came with a potentiometer. We looked at a lot of different circuit diagrams to complete this. We had a lot of trouble figuring out the wiring as well as having the wires stay in place. We decided to first get the display working without integrating the display code into our main program. For this we used the design below and a simple code that we found online to make sure that the display works.

Particle Photon Research:
Prior to this project, we never got the opportunity to explore wifi modules. In order to gain a solid foundation for this project, we began with some initial research to familiarize ourselves with photon particles. From our research, we were able to better understand what each component of the photon was able to accomplish like the RESET vs SETUP button as well as what each light function meant. The image in this section summarized our findings.

If you want more information or run into other LED settings, this website is useful: https://docs.particle.io/tutorials/device-os/led/...

Other important factors:

  • Programing language: JavaScript
  • Do not press down on Photon Module - doing so will reset the photon

Connecting Particle Photon:

To connect Particle Photon to the internet we followed a series of steps detailed on this website: https://docs.particle.io/quickstart/photon/

We will also detail our process here. To start, we began by connecting our device to a power source using a USB cable. We found that our computers (Macbook) served as a great power source! Once plugged in, the device’s LED began to blink a dark blue immediately indicating that it is ready to pair. Next, we download the particle app on our iPhones to connect the photon to the internet. The app had a step-by-step walk-through on what to do which made the process a lot easier than expected. Essentially, once the device is turned on, you will be able to connect to Photon’s wifi through the particle app on your phone. Here it is important to note that establishing this connection takes quite a while. This led to a lot of confusion on our end so just wait a while and your phone will connect to Photon’s wifi on its own eventually. Once connected, the app will ask you to connect to another wifi source. We also ran into some issues here connecting our university wifi. In the end, we found it easiest to connect to a hotspot. After this step, our photon device was ready to operate!

Photon Particle Coding, LCD Debugging, 3D Printed Box

Screen Shot 2022-05-09 at 9.12.14 PM.png
Screen Shot 2022-05-09 at 9.12.43 PM.png

Arduino: Later on we ran into some issues with the display and wiring and spent some time troubleshooting. One issue was that we did not have Liquid Crystals downloaded into Arduino. We also realized that our LCD display needed to be set up very specifically in order for it to display correctly. Otherwise, it would not show anything or the wires would disconnect. However, we were able to get the display to show what we wanted, meaning the code was correct (this part really taught us patience!)

Photon Code and Website: After we got the photon to connect to the internet, we began coding how we will transfer the data from Arduino to the internet. As mentioned before, particle uses Javascript as the coding language. This part was really difficult as our backgrounds were mainly business-focused (i.e. accounting, marketing, information systems, etc.) with very little coding experience (we only know basic python). Therefore, in order to complete this section, we needed to gain a better understanding of JavaScript and HTML.

We found this website to be very helpful since we had no experience in this area: https://docs.particle.io/cards/firmware/introduct... - reference manual

https://docs.particle.io/datasheets/app-notes/an03... - Here contains an example on how to create a website and push data onto it. We use this as a base to build our code.

The comments on the code explain how this code functions. But to summarize the whole thing, this code is built to display the current number of passengers and is set to refresh itself every 3 seconds. The first section

  • "Particle. function("passengers", FUNCTION_NAME)"
    • = focuses on the connection between the Arduino and Photon Wifi - more on this would be discussed in the next section.
  • document.getElementById("statusSpan").innerHTML = '';
    • = sets the “current stats of the application” on the website to blank.
  • particle.callFunction({deviceId, name:'passengers', auth:accessToken}).then
    • = calls upon the photon particle to execute the function Particle.function("passengers", FUNCTION_NAME).
    • The “then” statement then triggers the following section after the call function is completed:
  • If function calling succeeds
    • = Changes the status span output to be complete and displays the current number of passengers
  • If the function call to the Arduino fails
    • = changes the status span to “error calling devices” and the error that it ran into and displays “error” in output.

The last part of the code creates the website to which the photon particle would send the data. The website would display “Current Passenger Count”: "output", and "output" would equal the number of passengers or error depending on the state of the function. It would also display “Current status of the application”: "statusSpan", where "statusSpan" would display the current status as outlined previously.

Website code link:https://pastebin.com/pGcVZ5jx

Compiling Everything Together

Screen Shot 2022-05-09 at 9.17.32 PM.png
Screen Shot 2022-05-09 at 9.18.52 PM.png
Screen Shot 2022-05-09 at 9.18.47 PM.png

We combined and compiled everything we were working on. We started by testing out the new display, which we realized was not much better than the first. However, we coded the display to the main code, so that it would show the count as people entered and exited the bus. We then tested the complete project. We had an issue with combining the Arduino and Wifi Photon because we would have had to rewire and recode the entire project. For this reason, we were not able to meet the stretch goal. However, the final wiring of the project is depicted below. The last thing to do is to upload the final code to Arduino and then plug a battery onto the board. Again, the wires were very loose, but the sensors and display did work with the wires.

Then we attempted to form a communication channel between the Arduino and the photon particle. At first, we thought that we just needed to include this section: Particle. function("passengers", FUNCTION_NAME)into the Arduino UNO. However, it seems to be a lot more complicated than that. Initially, we wanted the photon particle to act as a wifi module/middleman between the Arduino and the internet. Although communication is possible, we experienced many difficulties sending the information from the Arduino to the Photon particle. We reached out to CS and engineering majors that had a background in coding to see if we can solve this issue but none of them has experience working with Photon Particles making it more complicated. This is still an area that we would need to explore further.

If given more time looking forward, we believe that a potential solution for this situation may be to discard the Arduino UNO entirely and use the Photon Particle instead. This is because as we explored the Photon particle we realized that it has hardware and coding capabilities of its own. Some pros to this solution are that it could potentially help us bypass the Arduino UNO. This could make the project more stream-line and less complicated as we would only have to work with one system. One con to this suggestion is that this would have called for a completely new implementation process which would take more time. Another option is to switch to the ESP8266, another wifi module. For this option, we can continue to use the Arduino UNO but switch out the Photon Particle for the ESP8266. This option may be more viable than the photon particle because, from our research, it seems a bit more beginner friendly. This is because we were able to find more readily available information on the ESP8266 in comparison to the Photon Particle. Additionally, this seems to be a more common method to connect the Arduino UNO to the internet so there are a lot more tutorials available on the process. This can be extremely useful, especially for those with no prior experience.

Here is a website for ESP8266 connection with Arduino: https://create.arduino.cc/projecthub/neveroffthei...

Final Presentation

BADM 357 People Counter Demo

Additional Code:

Code for Sensors and LCD:

#include

int Contrast=75;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int irPin1=7;

int irPin2=8;

int count=0;

boolean state1 = true;

boolean state2 = true;

boolean insideState = false;

boolean outsideIr=false;

boolean isPeopleExiting=false;

int i=1;

void setup() {

analogWrite(6,Contrast);

lcd.begin(16, 2);

Serial.begin(9600);

pinMode(irPin1, INPUT);

pinMode(irPin2, INPUT); }

void loop() {

if (digitalRead(irPin1) && i==1 && state1){

outsideIr=true;

delay(500);

i++;

state1 = false;

}

if (digitalRead(irPin2) && i==2 && state2){

Serial.println("Entering into bus");

outsideIr=true;

delay(500);

i = 1 ;

count++;

Serial.print("No of persons inside the bus: ");

Serial.println(count);

lcd.setCursor (0,0);

lcd.print(count);

state2 = false;

}

if (digitalRead(irPin2) && i==1 && state2 ){

outsideIr=true;

delay(500);

i = 2 ;

state2 = false;

}

if (digitalRead(irPin1) && i==2 && state1 ){

Serial.println("Exiting from bus");

outsideIr=true;

delay(500);

count--;

Serial.print("No of persons inside the bus: ");

Serial.println(count);

lcd.setCursor (0,0);

lcd.print(count);

i = 1;

state1 = false;

}

if (!digitalRead(irPin1)){

state1 = true;

}

if (!digitalRead(irPin2)){

state2 = true;

}

}

Code to Validate LCD Display:

#include

int Contrast=75;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()

{

analogWrite(6,Contrast);

lcd.begin(16, 2);

}

void loop()

{

lcd.setCursor(0, 0);

lcd.print("Only Innovative");

lcd.setCursor(0, 1);

lcd.print("Subscribe");

}