1. Initiative

So, as a freshman(March ~ December, 2016) in high school, I was pretty frustrated at our school’s cafeteria situation.

*For a shorter summary, see my instructables post: LINK.

*Here’s a link to my code if you are interested: Link.

1-1. Problem #1. Excessively long waiting line

What was the problem I observed? This:

So that was the first problem.

Too many students lined up, and they had to wait for a long time (5 ~ 10 minutes).

But of course, this is a common problem, and also it’s fair for everyone. Later you come, later you’ll be served. So that’s an understandable problem.

1-2. Problem #2. Inequality in the waiting line

But, of course I observed an even bigger problem. The problem that ultimately made me decide that I need to step up to solve it.

Seniors (basically everyone with a higher grade, including teachers), were cutting the lines Short.

Yes, and as a freshman / sophomore, you really can’t say much to them. And our school actually had a pretty strict relationship between each grade members.

So as a freshman, I would get to the cafeteria first with my friends, and as we’re just about to get our meal, sophomore / seniors / teachers would come and literally block us, (some kind seniors allowed us to get in line) and we would have to wait another 15 ~ 20 minutes, even though we came there first.

Especially, Lunch time was the worst. Because everyone (students and teachers and faculty) came rushing in, so as a freshman, we were having a bad time each lunchtime 😦

1-3. How low-graders tried to bypass this problem

Being a freshman, having not much choice, there were 2 methods that we used to ‘decrease’ the chance of getting our lines cut short.

we would go to the cafeteria really early (literally getting there before the meal is even ready) we would intentionally spend time playing ping-pong or basketball, and go to the cafeteria really late (about 20 minutes after the lunch-time starts).

So, that partly worked. But honestly, nobody wants to run as fast as they can just to get a meal, or eat a cooled-down, left-over food by getting to the cafeteria so late.

We (freshman / sophomore), needed a solution that could tell us when the cafeteria was not congested.

1-4. How can we predict the congestion accurately?

It would’ve been great if there was a fortune-teller who could predict the future, and tell us exactly at what time we could go and have a meal without waiting so much.

But the problem was it varied day to day. There was no analytical way to figure out the perfect time to go. Without physically going there(Which, could be hundreds of meters away depending on where you are at), there was no way for us to know the situation at the cafeteria.

Even if you went there and saw the long line, going back to where you were and coming back would take a lot of time too.

So the whole situation really sucked for low-graders, we had no choice.

1-5. Aha- moment of Cafeteria Monitoring System

Suddenly, during my 2nd semester as a sophomore (2017), I thought to myself: “What if I can create a system that can show in real time, current waiting line length (a.k.a Congestion)?”

If I could make that work, I could imagine the freshman students just casually checking their phone to see the real time congestion data, and decide for themselves, whether they want to go now or not.

So actually, this was solving an inequality in information. Giving a power for low-graders to decide for ‘themselves’, what they want to do. Either go wait in the line (if it’s short enough) or utilize their time more effectively doing something else, and choose the timing they want to go.

Thinking about this, I got excited.

2. Idea of Cafeteria Monitoring System was born

2-1. Initial Concept (September, 2017)

So back at September 2017, since I had a ‘Object Oriented Program’ class project to do, I decided to propose and build this system as a project for that class.

2-2. Hardware Selection (October, 2017)

So I just ordered 50 membrane switches and a ESP8266 based ‘Wemos D1 mini‘ board, and some terminal connectors that will connect with enamel-wires.

2-3. Prototype Build & Programming (October, 2017)

Starting from the breadboard, I built a prototype circuitry to test.

And because of the material constraint, I only used 5 foot-pad configuration.

2-3-1. Software Part

My Objective with the program (C++) was:

Run continuously, and only send the data only during the Meal time (Breakfast, Lunch, Dinner, Snack). Sense the line / congestion situation with enough frequency (ex. 10Hz) that the data can later be used for a machine-learning model. Send the data to the server efficiently (low packet size), with a short time interval.

And to do that, I needed to:

Use RTC (Real Time Clock) Module to check current time continuously, and detect meal time appropriately. Make use of crude-compression, to encode 5 foot-pad’s state into a single character. By considering data as 5-bit binary, I added that value to ascii character ‘A’, and that single character would represent a data-point. Use ThingSpeak (IoT Analytics / Online-grapher) API, with HTTP POST requests.

And of course, there were bugs like:

Me not knowing that sizeof( ) for char * object returns 4 , not that string’s length (because it’s not an array, hence compiler doesn’t calculate length), was puzzled why my HTTP requests only contained 4-characters of the URL!

for object , not that string’s length (because it’s not an array, hence compiler doesn’t calculate length), was puzzled why my HTTP requests only contained 4-characters of the URL! Not putting ( ) – brackets at #define stage, produced unexpected results.

For example:

#define _A 2 * 5

int a = _A / 3;

Here, you’d expect ‘a’ to be 3 (10 / 3 = 3), but it actually gets calculated as: 2 ( 2 * 5/ 3 = 2).

And one more notorious bug I encountered was: “Watch Dog Timer Reset“.

This problem bugged me for so long. I later found out that I incorrectly accessed low-level registry of the ESP8266 chip (By mistake, setting the value of a struct pointer to NULL).

2-3-2. Hardware Part (Foot-pads)

I set myself these conditions for the foot-pads to survive the harsh cafeteria’s condition:

Should be durable enough to sustain continuous stepping from humans. Should be thin enough to not become an ‘obstacle’ for people in the line. Should guarantee the closing of switch , when a person steps on it. Should be water-resistant . Because cafeteria’s got a lot of water 🙂

So to do that, I settled on a design that used double-layered configuration, with laser-cut Acryl for top and base plate, and cork material as a covering layer.

I used AutoCAD to design the plate, with a dimension of 400 x 400 [mm].

By the way, the design on the right was ditched because with that latching design, distance between foot-pads would essentially be 40 [cm], and that was too short for the needed coverage of 10+ [m].

I used Enamel-wire to connect up all the switches, totaling at about 70 [m] length of wires! And on each foot-pad, I placed a membrane-switch in the center. So the side slot of the pad had two terminals peeking out. One for each side of the switch.

Oh, for the water-resistant thing, I used tapes, lots of them 🙂

3. After all that, it started working!

3-1. From November 5th ~ December 12th

Starting on “November 5th 8.am” (Breakfast), the system started recording live activity in the cafeteria.

It was kind of unreal to me. Because just 2 months ago, I was sketching up the conceptual design wearing pajamas, and here it was, the whole system working flawlessly (kind of :P).

3-2. Software Problems I encountered during Testing

Of course, there were bugs in the system. And here are some memorable ones:

The program didn’t check for Wifi connectivity when trying to connect Client object to Thingspeak API. To remove that error, I added a WiFi connectivity checking step. In the setup function, I continuously called “WiFi.begin” while unconnected. But later I learned that the actual connection is done by ESP8266 core firmware, and that begin function is used just for setting up the WiFi. To solve this, I only called the function once in the setup. I found out that the CLI (Command Line Interface) I made (that could set clock’s time, change WiFi info), didn’t work when it was in Idle-state (not meal time). And found out that when not logging, it’s internal loop was so fast, hence the Serial data was getting read too fast. Which led my commands being invalid. So I gave it a delay to wait for extra commands to flow in when expected.

3-2-1. Watch Dog Timer Reset needs some special praise!

Oh, and about the Watch Dog Timer Reset problem that I mentioned above, I actually figured out the cause during the field-testing.

I was literally thinking about that bug every second for 4 days.

I would like run to the cafeteria during break-time (10 minutes), just to test the new version of the code. And during the meal time, I would sit at the cafeteria floor for 1 hour straight, trying to debug the cause, and not even caring about the lunch!

So for giving me such a hard time, thank you ESP8266 watchdog-timer!

How I debugged the WDT bug :

I found a program / Arduino-Extension that could analyze the Stack of the program when Wdt-reset occurs. By using the compiled code’s ELF file (Correlation between functions and pointers). And using that, the above stack error could be debugged as:

Dang! I didn’t know that debugging a real-time system would be so difficult!

Anyways, so I fixed that bug, which was a stupid bug. As a software newbie, I had programmed a while-loop that could access an index out of the array. Phew! (Differentiate index++ and ++index !)

3-3. Hardware Problems during testing

Obviously, my hardware / foot-pad wasn’t perfect.

So as expected, switch got stuck.

Above is the live graph capture from the web (Thingspeak online grapher page). You can see that after an event at around 12:25 PM, the pad number 3 got stuck. So the line length was detected as 3 (value = 3 * 100), even with the line shorter than 3-pad length.

To fix it, I just added more padding (more Tape :P) to the under side of the plate. To give more clearance to the switch / foot-pad space.

Also, my system sometimes got ripped out (literally), by a power cord getting stuck under the door.

The cart / packages get delivered to the cafeteria through that door in the photo. So whenever the power cord got stuck under it, as the door closed, the whole power system got ripped out :P.

In those situations, I would see a sudden data drop on the graph, and that usually meant the power failure case like above.

3-4. Some photos of the system getting used

3-4-1. Promoting the System to School Members

So as I mentioned above, I used the Thingspeak API, and the website conveniently provided a graph visualizer. So I basically provided all the students that URL through a Facebook Group Post (I searched for like 30 minutes, but couldn’t find the original post. Hmm weird..).

But I found my Band (School community) post! (2017 / November 5th)

3-4-2. Sharing the Graph to the school Members via SNS

I shared the posts to trigger some interest in the system. And actually, analyzing them is pretty fun.

For example, you can see that the line for the dinner faded away quickly after 6:10 PM, and peaked at 6:02 PM.

3-4-3. Some more graphs

Attached above, are some graphs from Lunch and Snack time. It is interesting to see that 12:25 PM was almost always the peak (Almost 5 foot-pad length) time for lunch. And snack time isn’t really congested as much (At max 1 foot-pad length).

3-4-4. Memories

One funny thing is that the site is still alive! https://thingspeak.com/channels/346781

When I logged in with the account I used in the past, I saw this :

In the above graph, you might find that ‘December 3rd‘ is noticeably less-peaking. That is because it was Sunday. On Sunday most of the students went out of the school! Because Sunday is in most cases, the only time you can go outside the school during the week. So no wonder students were almost non-existent at Cafeteria on Sundays 🙂

4. How I ended up receiving a First prize from ‘Ministry of Education department of Korea’ with this project.

As you would’ve seen until now, I didn’t do this project to get any prize or recognition. I just wanted to solve the persistent problem in my school with the skills I had.

4-1. Learning about the contest

But our school cafeteria’s Nutritionist: Ms.Oh, who I got really close with during the period of planning / executing this project, asked me one day if I knew about this “School Cafeteria Idea Contest“.

I thought that it was such a weird contest. An Idea contest for School’s cafeteria? But I read the paper describing it, and learned that it was due November 24th! Oh man, so I just prepared the Idea, data, graphs and sent my application.

4-1-1. Slight modification to the original Idea, for proposal

By the way, the Idea I proposed is a little bit different from this Idea. I basically adapted this method (Real time Line length monitoring system) for a much bigger schools in Korea. For comparison, our school had total of 300 students, but for other schools could have that amount of students per grade! So I needed an Idea for scaling up this method.

Therefore, I proposed more ‘manual‘ way of doing line management. Because current high-schools in korea already have a strict meal order for each classes, I came up with ‘cue and react‘ framework. So that when the group ahead of you reach certain threshold in the line (getting shorter), they would manually give a cue to your classroom by pressing a button / transmitter on the wall. Which would be signaled via TV screen or LED lighting.

I just really wanted to solve this problem that was persistent nation-wide. Also, hearing a story from Ms.Oh motivated me a lot. Which I describe below.

I learned that in some big schools, students line up 20 ~ 30 meters OUTSIDE the cafeteria during the Winter, because there isn’t a good way to manage the whole timing.

And sometimes, groups won’t arrive for a several minutes, which is a problem, because in big schools with a lot of students, cafeteria can barely provide food to all students if every minute of the lunch time is utilized. And so students in the last batch (usually 1st graders) then don’t even have enough time to finish their meal.

So although I prepared my application in a short time, I thoroughly thought about how I could improve the current system, for more general use.

4-2. I got an email saying that I had won 1st prize!

Long story short, I was invited to come and present my system to government officials on December 21st. So I quickly utilized my Power-point skills, and went there, and presented!

It was an interesting experience. I just happened to do something about Cafeteria’s Problem, and I somehow got selected for the 1st prize. Even during my presentation, I thought: “Hmm, how did I get here?”

And in the end, it became a really good project for me. Because I learned more about embedded systems programming, and real-life projects, but also got a prize!

5. Conclusion

5-1. Opportunities can come naturally

It’s such an irony. Because all the ‘competitions’ and ‘science-fairs’ I attended intentionally in the past, I didn’t get a good result. But instead, in this case, the opportunity just came to me, and I got a good result out of it.

It made me think about the ‘reason‘ I do projects.

Am I doing it for the sake of ‘competition’ or am I really trying to solve a real world problem? If you are the latter, I especially encourage you to continue. Because with that mindset, unexpected opportunities could arise and because you won’t be stressed about winning, your passion, which is the biggest weapon, will drive your actions.

More importantly, if you end up coming up with a good enough solution, you could start applying it to the real world. In my case it was my school, and as you get more experience, who knows, your system could get used by a State, a Country, the whole World!

5-2. Projects are awesome

Whenever I think back at this project, I sort of become proud of myself. I can’t really explain why, but I just liked the process of this project, and the prize it brought was an extra bonus. Also, I loved the fact that I could help students on the daily problem they face.

When one of the students came up to me and said: “Your system is really useful”, I became so happy.

And I think even without the prize, I would’ve been proud of this project just for that. Maybe it was helping others, that made me so fulfilled, but anyways, I love projects.

5-3. What I hope I’ve provided you with

I hope that through this post, you got some inspiration to do something meaningful for the community, even for yourself! I encourage you to use the skills you have (programming is definitely a great skill, but others too!) to improve the situation to the better.

I can guarantee you that the experience you get out of that project will be priceless.

And like in my case, it could bring you an unexpected opportunities. So please go do what you love, and impact the world! Your small voice, when repeatedly echoed, has a potential to shake up the whole world. Believe in yourself, and remember that you are amazing!

5-3. Some links regarding this project

Instructables I wrote about this project : Link

I wrote about this project : Link Code I wrote for this project : Link

I wrote for this project : Link Actual graph (last 15 days) from this project ( Better ) : Link

from this project ( ) : Link The graph-page I provided, back in 2017 ( Outdated ) : Link

I provided, back in 2017 ( ) : Link Media coverage on the contest / my project : 대구경북, 중앙일보, 경북신문

Thank you for reading this Post! 🙂

(I doubt anyone will read the whole thing)!

p.s. Wow I wrote more than 2500 words on this post. And since I started writing at around 9pm and it’s past 3am now, wow I devoted 6 hours into this post, crazy. I probably should do something more meaningful lol.

Edit) So it’s right now December 20th, 9:22pm (about 18 hrs after I posted this), and this post became a top #3 post in “r/programming” sub-reddit (link).

Reddit post has 411 up-votes, 73 comments. And this post itself got viewed over 3,800 times! I’m really thankful for everyone encouraging me to continue sharing projects like this.

It took me 2 years to finally create & share a detailed post about this project. And I’m really glad I did it. So many eye-opening comments & stories, what an unexpected joy!