It’s almost a new year, which means many people are going to come up with something they would like to do or change, such as going to the gym more or keeping the house clean. These resolutions are great things, but most likely, they will be broken a mere two to four weeks into the year.
Behavior modification is a way to cause new habits to form by either giving a reward for exhibiting the correct behavior (positive reinforcement) or a punishment for incorrect behavior (negative reinforcement). People use these techniques all the time, such as giving a treat to a dog for doing a trick or paying your kid a dollar for cleaning the bathroom. Since people usually don’t want to willingly subject themselves to pain and/or discomfort, I decided to build a machine that can give a reward of the user’s choosing whenever a goal is reached.
Initially, the user will place an object that they like to receive, such as money or food. Then, they can enter in a goal on a webpage, which sends it to the machine and displays it on a screen. The door will also close at this time and lock, preventing the user from getting what’s inside without first completing the task.
Doors come in many varieties: hinged vertically, hinged horizontally, or sliding. One of my goals in the project was to keep the box small and simple, so a sliding door would have best accomplished this.
A 3D printed door gets placed onto two aluminum guides, and a stepper motor uses a timing belt and pulley to drag the door side-to-side. A limit switch is used to “home” the machine, so the microcontroller can know exactly where the door is.
In order to make a door move, you must first have a motor. I went with a stepper motor in this case because it is able to move a precise amount, and therefore, the distance it has traveled can be tracked. It is driven by a DRV8825 bipolar stepper motor driver, which only requires two pins to operate. Goals are displayed on an ILI9341 OLED screen, which is controlled via the SPI interface.
Every time a new goal is received, its text is sent to the display. Finally, the brain of the device is a Particle Photon, which lets the machine communicate with the webserver via WiFi and get new data.
Particle Photon ProgramAt a high level, the program flows as follows: Enter new goal -> Display goal on screen -> Close and “lock” door -> Wait for button press -> Open door and allow person to retrieve prize. There is a delay between entering the goal and having the door close to allow for a treat to be placed in case it was forgotten previously. The program utilizes the mDNS library to allow users to navigate to a hostname rather than an IP address. The HTML file is hosted externally to save space on the device, and it is fetched and placed into an iframe by the client whenever the index page is loaded. When a new goal is set, a POST request is sent to the photon, where the goal string is extracted and saved to a variable. Whenever the webpage is loaded, a function is called that retrieves the current goal from the device, thus maintaining consistency between client devices.
Making Good HabitsPsychologists tend to claim that it takes around 10 times of doing something consistently for it to become a habit, so by using a metaphorical carrot on a stick, you can cause yourself to eventually perform tasks without even having to think about them.
Comments