Have you ever walked by the supply cabinet at work and see your fellow office mates look aimlessly into the bottomless pit of office supplies? We’ve all done it - you go there with the purpose of getting the one thing you’re looking for, but then you quickly get distracted with all the weird and fun things you find. Next thing you know, you either forget what you were looking for or think about all the other things you must have but don’t know what that is until you find it. But you know whatever it is, it’s in there, somewhere.
I’ve noticed that this has been happening a lot lately at SparkFun, so I decided to have a little fun with it.
Last week I had a day where I had no meetings or calls (which never happens), so I decided to play around with the micro:bit. I went through the Experiment Guide for the SparkFun Inventor’s Kit for micro:bit, and I decided to take experiment #3 (Reading a Photoresistor) and modify that experiment for what I wanted to do.
I wanted something that would turn on when the supply cabinet was opened and play the Jeopardy tune once they stood there for about 8 seconds.
The modifications to experiment #3 were pretty straightforward.
- on start, I paused the start program for 8 seconds. This delay gives you the time needed to place the unit, and calibrate the sensor in its final hiding spot - ie, closet with the door closed.
- I inverted the logic of the light sensor to turn on when it sensed light.
- I replaced the LED with our Qwiic MP3 Trigger.
- I added a hamburger speaker.
For reference, here's the code I used:
Here's what the final product looked like before I placed it in the supply cabinet:
After setting this up and quietly springing this on the team at SparkFun, I discovered 8 seconds might be too long of a delay. After 2 hours no one had been at the supply cabinet long enough to set off the music. Next time, I'll tweak the code to allow for a shorter delay.
For educators and beginners, this is a great example of taking an entry-level open source guide/project and making it your own. I've already discovered it can be handy for the pantry at home and I'm sure you could find a number of uses for it around the classroom.
micro:bit, programming