Inspiration: Jam-Packed Lines
If you live in the US, you've most likely experienced the "six feet lines" at grocery stores. Like we all know, they're usually much less than 6 feet. Just last week, I remember I went out with my family to buy groceries. However, I remember feeling incredibly uncomfortable outside, since many strangers would always come too close. With the recent attacks on Asian-Americans, we've been afraid to ask for space, which could potentially aggravate others to assault us. But since two of us are immunocompromised, it's incredibly dangerous for us to get infected with COVID-19 as our survival rate is lower than others. In an effort to properly control the number of people indoors, I decided to create a device that tracks the current population in a store. Coming in as a sociology major, I had little experience with coding so I spent most of the weekend watching videos online on ESP-32 microcontrollers. After stopping by Target on a shopping trip, I realized that many stores had a doorperson standing outside to let people in and out. That was when I had the idea for inSite.
How Does the Microcontroller Work?
The microcontroller uses two ultrasonic sensors to determine the direction that a person is entering from. By finding which sensor detects an object first, we're able to locate whether they are going into the store or leaving.
if (avgdX_1s < (endpoint - 20) && avgdX_1s < avgdX2_1s) {
currentpop += 1;
fromRight = true;
}
else if (avgdX2_1s < (endpoint - 20) && avgdX2_1s < avgdX_1s) {
fromLeft = true;
currentpop -= 1;
}
This proved to be more complex of an issue than expected because I had to figure out how to run two ultrasonic sensors while simultaneously running Telegram's API on a dual-core device. Normally, this would require up to a quad-core to run three processes at once. Despite the trouble, adding Telegram allowed me to create a notification system that contacts the management team that the maximum capacity has been passed. In addition, it provides them commands that they can use to check what the current population is, change the maximum capacity, and toggle their alerts. In scenarios where there might be extraneous circumstances like the Texas snowstorms, it may be necessary to pause the alerts and allow more people to enter than before.
void handleNewMessages(int numNewMessages) {
for (int i = 0; i < numNewMessages; i++)
{
if (bot.messages[i].type == "callback_query")
{
String chat_id = String(defaultChatId);
String text = bot.messages[i].text;
String from_name = bot.messages[i].from_name;
if (from_name == "") {
from_name = "Guest";
}
Serial.print("Call back button pressed by: ");
Serial.println(bot.messages[i].from_name);
Serial.print("Data on the button: ");
Serial.println(bot.messages[i].text);
}
else {
String chat_id = String(defaultChatId);
String text = bot.messages[i].text;
String from_name = bot.messages[i].from_name;
if (from_name == "") {
from_name = "Guest";
}
if (text == "/checkpop" || text == "check population") {
std:: string population = "Current Population: ";
population += std::to_string(currentpop);
bot.sendMessage(chat_id, population, "");
}
if (text == "/toggle" || text == "toggle alerts") {
if (alertsEnabled == true) {
alertsEnabled = false;
bot.sendMessage(chat_id, "Capacity alerts turned OFF", "");
}
else {
alertsEnabled = true;
bot.sendMessage(chat_id, "Capacity alerts turned ON", "");
}
}
if (text =="/setmax"){
bot.sendMessage(chat_id, "What would you like to change the maximum capacity to?", "");
}
if (text == "/start" || text == "/help") {
String welcome = "Welcome to Your inSite Dashboard, " + from_name + ".\n";
welcome += "The following commands are available.\n\n";
welcome += "/checkpop : reports the current population count\n";
welcome += "/setmax : set the max capacity of people \n";
welcome += "/toggle : mutes or unmutes inSite alerts\n";
welcome += "/options : returns a custom reply keyboard\n";
welcome += "/help : displays this message again\n";
bot.sendMessage(chat_id, welcome, "Markdown");
String keyboardJson = "[[\"/checkpop\", \"/setmax\"],[\"/toggle\", \"/help\"]]";
bot.sendMessageWithReplyKeyboard(chat_id, "Choose from one of the following options below", "", keyboardJson, true);
}
}
}
}
Attached to the board are a few LEDs, which allow us to visually see when someone enters the building (green), and whether or not the maximum capacity has been hit (red). However, sometimes small factors like leaves, dust, and random objects would activate the sensor. When I noticed that the LED was turning green even if nothing was there, I decided that I needed to adapt for external noise. In the real world, there might be objects like a backpack or purse strap that might get in the way. By using an averaging function, I smoothed out the noise from the measurements to give me an accurate reading of the presence of a person.
for (;;) {
Serial.println("Task 2: Calculate average of 10 distance measurements");
avgdX_1s = 0;
avgdX2_1s = 0;
for (int i = 1; i <= 10; i++) {
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
dT = pulseIn(echoPin, HIGH);
if (dT > MAX_dT) {
Serial.println("Out of Range");
dX = 400;
}
else {
dX = dT / 58.0;
Serial.printf("%d,%d\n", micros(), dX);
}
avgdX_1s = (avgdX_1s + dX);
delay(100);
}
avgdX_1s = avgdX_1s / 10;
Serial.printf("%d, Average Distance : %d\n", micros(), avgdX_1s);
for (int i = 1; i <= 10; i++) {
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
dT2 = pulseIn(echoPin2, HIGH);
if (dT2 > MAX_dT) {
Serial.println("Out of Range");
dX2 = 400;
}
else {
dX2 = dT2 / 58.0;
Serial.printf("%d,%d\n", micros(), dX2);
}
avgdX2_1s = (avgdX2_1s + dX2);
delay(100);
}
avgdX2_1s = avgdX2_1s / 10;
Serial.printf("%d, Average Distance : %d\n", micros(), avgdX_1s);
Conclusion: Social Impact
By using these in businesses around the country, we can properly control the number of people allowed into a store at once. Usually, there's a doorperson standing outside to navigate traffic, though proving to be inefficient. The device allows the store to track how many people enter and leave the store, which tallies into a total count of people on the premise. Then, this data is sent through Telegram to the management team where they find use various functions to check the number of people and make decisions accordingly. By controlling the number of people in the store, we can reduce the spread of COVID-19 to create a safer environment for immunocompromised people and minority groups. For businesses, we can create opportunities for them to serve more customers over a longer period of time, which reduces the density of people at peak hours. Imagine a world where you can find the exact times that Costco has the least amount of people and safely shop without worries of catching COVID-19. Based on my independent research, I found that 78% of students would shop more often if they could see how many people were in the store at present time. In normal circumstances, the students would not shop at all, so that is a net benefit for the business and customers combined. By implementing this to apps like Google Maps, Apple Maps, and Yelp, we can create an environment that supports both sides of the transaction. With many people around the country already having a smartphone, accessibility would be incredibly easy to reach the most amount of people.
As a hardware hack, I'm most proud that I was able to create a physical solution to an actual problem. Many brick-and-mortar stores are unaccustomed to using software to facilitate their purchase orders, so it was very important for me to find a hardware solution to COVID-19. The pandemic proved to separate small businesses from corporate monstrosities because many of the small businesses could not survive to adapt to the changing technological environment with innovations like mobile order and drive-by pickups. While it may seem like a simple solution, it creates an enormous impact on businesses around the world.
Challenges
As mentioned before, I'm currently a sophomore sociology student. Without much coding experience, it was a really steep learning curve to learn C++. Compared to languages like Python and Java, the syntax proved to be incredibly difficult to master. Learning C++ was a mess, and I struggled with a million errors. Thanks to the mentors, I was able to bridge this gap in knowledge and implement most of the functionality that I needed. Afterward, I was able to quickly pick up the logic that I wanted to use and learned the syntax to code for it.
Another issue that I had was using an ultrasonic sensor to measure distance. It was the only sensor I had on hand, but incredibly sub-optimal for an application like this. The speed of sound is incredibly inconsistent and is affected by external factors like temperature, humidity, atmosphere, and others. I had to devise ways to filter out noise in the measurements to avoid the sensor from reacting to inaccurate data. A better alternative would be utilizing an ESP-32CAM to simply detect the frame of the person. This would create a much simpler process where I don't have to measure the reflection of sound waves. Instead, it would simply tell us how many people were there, and which direction the object is heading.
Foolproofing the sensors was also a challenge because I hadn't used averaging functions much in the past. After applying this to the sensory data, I was able to filter out external noise that might disrupt the detection. Nonetheless, it would've been less complicated to use something like an ESP-32CAM with object detection, but I didn't have those materials on hand. However, I'm proud that I was able to learn more about manipulating functions in order to solve problems despite lacking the resources. I think that this experience was much more valuable than having all of the perfect resources since I learned to code on the spot and adapt to difficult circumstances.
Key Takeaway
I learned that hardware is actually pretty fun! Before this, I used to be totally obsessed with the idea of software development and hard-coding apps. However, it's much more fun using hardware and seeing parts actually move. I think that the only way I was able to sustain myself through the day into the night was because seeing the parts move always got me super excited. I would always laugh or giggle if something worked, and I could test out the problems that I ran into. Instead of reading lines of code every single hour, I had a nice harmony with the physical aspects of this project.
I also learned that despite being a sociology major, I could still produce meaningful impact. I'll be implementing this device in my mom's health care office so that we can make sure that there aren't too many people in the building at once. At first, I felt handicapped with the lack of knowledge in coding. However, I soon realized that being a sociology major actually gave me a different perspective in understanding the problems that society has to deal with. I was able to use my experience in research and academia to gauge the situation and study the people that I was seeking to help. Based on my findings, 78% of students would shop more if they knew the number of people in a store. To solve this problem, I implemented the new device that I programmed.
How inSite Can Replace Current Technology
One of the future applications that I want to use inSite for is its ability to count objects that pass by. In huge parking structures, many companies use pressure sensing and image detection using cameras to detect the number of cars in a facility. While accurate, these methods are incredibly expensive and ineffective for the purpose at hand. At such a high price tag, it's hard to implement around the world in areas that are less fortunate. Using inSite, we're able to count the number of vehicles coming in and out. By comparing it to the maximum capacity of the parking structure, it's much easier to determine how many parking spaces are available. This would prevent the atrocious amount of time that people spend circling around parking spots. Imagine going to the mall and every single time you arrive, there's a parking spot readily available for you. That is the future that I envision.
The sky's the limit, whatever can be dreamed of can be built. Iām beginning to realize this more and more, and thanks to this Hackathon, I dived into the deep end and learned things that reinforce my love for programming.

Log in or sign up for Devpost to join the conversation.