A friend of mine has been finding himself losing track of time at work and thus working way more than his 40 hours a week. This projects aim is to create a standalone box that will actively track his time at work each week.
- Raspberry Pi
- LED Matrix
- Magnetic Sensor
- 3D Printing
The design requirements for the device was to be a standalone box that required no fancy or cumbersome device to activate or require him(The user) to do an action that was overtly complicated or easily forgettable. So I designed a raspberry pi box that would simply check if a switched was closed every minute, and tally up those minutes throughout a week. And every weekend the counter would reset. It is important to note that this project was designed to not require any internet connection due to restrictions of an unregistered device on his work network.
The hardware side is pretty straight forward;
Sensor/trigger is a custom array of simple reed switches and a neodymium key chain magnet. For the array I used simple reed switches which are bare wires in a glass capsule. The wires are setup in parallel with a small overlapping section and are made out of a para-magnetic metal (most likely steel). This allows for the switching action to be triggered which is accomplished by moving a strong enough magnetic or magnetic field to apply enough bending force to allow for the two wires to touch. When testing the reed switch I found that there is a high likely hood that the magnet when placed near the reed switch will not always trigger a single reed switch, this is due to the field not aligning properly with the reed switch. To reduce the likely hood of this happening I designed and printed a holder for 4 reed switches which I wired in parallel to one another. Another component to this 3D printed part was a small steel disk epoxied to the top center of the part whose purpose was to both attract the magnet to a central spot on the sensor array as well as firmly keep the magnet attached to the sensor. Due to this sensor setup, I ultimately reduced any chance for a false reading to zero based on a fixed plane and location for the magnet to be set.
A custom replacement project box top, LED/LED panel mounting bracket, and project label, which were all designed in solidworks then simply printed it in ABS plastic. These were to improve the aesthetic nature of the project due to its high visibility of the project on my friends desk as to reduce concern due to box having a simple red LED and a clock that counts. As silly as it is, I have found it is important to not underestimate what people will report to the authorities as a bomb.
And finally the raspberry Pi is being powered by a simple 5V-2Amp USB-Wall Power supply.
Software side is again, quite straight forward:
Raspberry Pi is just a standard off the shelf component, but due to the projects zero-network connection requirement it required an off-board RTC(Real Time Clock) component. The RTC is a simple IC and battery on a circuit board, the intended purpose is to add a real time clock to a project that needs to keep track of time without any access to a Network Time Protocol server (NTP Server). So to set this up you simply connect it to the raspberry pi gpio pins, updating the RTC to display the actual time, and configuring the Raspberry Pi to reference the RTC off the GPIO pins during startup instead of the NTP server. There are various RTC for the Raspberry Pi, but from a cursory glance they are all quite similar in how they are designed and setup.
The code the Raspberry Pi is running is a few simple python scripts that are executed using some CRON jobs that are executed every minute. One of the more interesting things about my python scripts is how I approached the case where the Rasp berryPi has lost power, mainly for tracking the current “Hours worked this week” value. When the raspberry pi loses power and then regains power, the pi it will simply boot up linux and the few CRON jobs I have setup to start at startup. First the Pi will check the RTC for the time, next the CRON-Job will reinitialize the tracking scripts and checking for errors, and finally it will allow for the cycle to continue. The way the value of hours is held is by using a python pickle which is a way to store and transfer binary data, in this case a basic counter and the current state of the switched (on/off). This allows the scripts to be generally crash proof, the only issue is if the power goes out for more than a few hours during the work day. When this happens and if the user has left for the day before the power comes back, it will tally up to that time as time ‘worked. But due to the nature of the facility my friend works, I determined that their backup generators will kick on during a sustained black out and this eventuality is highly unlikely, so no need to code a more complicated method to deal with it. This is an important rule I have when coding anything, keeping a program simple allows for it to be more robust when dealing with issues. The prime example of this is MITERS Door tracker Raspberry Pi setup that I have created [link] which has stayed active without intervention since its implementation in early 2016.