Ultrasonic sensor for finding the number of people who pass by

My setup for this project used an ESP32, a micro SD card reader and an ultrasonic sensor. The sensor was attached to the wall outside of my room, a few inches off of the ground in order to detect when someone passed by it. My code took a reading from the sensor and converted it into centimeters which would show if there was any change to distance. The hallway was around 150 centimeters across, so my code would only mark someone passing if the distance detected dropped below 145 or went above 190. For some reason, there was a general range where, if something was in the way, the ultrasonic sensor would read it as being farther away than was correct or even possible. Since this only happened if something was in the way and not when it was just sitting there, I could write my code to accept that someone passed by if the distance was low or very high. I used my SD card to store the number of people who passed in the last 10 minutes so I had a .txt file with each reading on a separate line. However, I wasn’t able to use the data in the file to actually analyze it because of an aspect of the ESP32 and how it runs code that I had absolutely no idea about. After I had collected my data, I unplugged the device from my computer and left it. When I plugged it back in to run the code that would read and then output the data I had (since I didn’t have an SD card reader for my computer), it began running the original code it had, which was used for detecting and storing my data. In the setup function, I had a line that would erase my results.txt file so I wouldn’t be creating a bunch of files through my testing. I hadn’t known that plugging my ESP32 back in would run the code from the start or at all, so I didn’t think to unplug the SD card reader to prevent any unintended erasure. Due to this, my 24+ hours of data were destroyed instantly, so when I ran my code to read the file, I had no readings. I did record data for well over 24 hours and I had tested that saving to and reading from the file worked perfectly. There was no issue with my code or how I did this project, it was simply an intricacy of the ESP32 that I didn’t know that erased it. From what I remember of the data, the readings mostly ranged from 0 to somewhere below 10, but there were a few outliers, with a maximum at 16 because some of my friends would go back and forth in front of it. Making an estimate at the average number of people who passed, I would say 4 to 5 per 10 minutes. There were probably more people passing in the evening(6-10 PM) as people were done with classes and work for the day, and much less people passing early in the morning (1-6 AM) because they were sleeping.

0 Lifts 

Artifacts

Name Description
Main Code This is the main program that takes and stores data   Download
SD Card Reader Code This code is used for reading what is found on the SD card   Download
Video Explanation A video that shows the setup, code and how my project works   Link