My handy Arduino reminder
A while ago I got my first Arduino kit as a backer for an Indiegogo Campaign.
It was a reward for backing with only 9 USD and it came fully equipped with an Arduino Leonardo, a small breadboard, some prototyping wires, LEDs, resistors and some other stuff. It was a pretty good deal for its price, even though the author of the campaign doesn’t seem to have put up an online store where I could purchase additional kits.
The kit was sitting around for a while until I decided to give it a try. After downloading the Arduino Software and following some of the tutorials, I had my first blinky (the Hello World of this new Electronics Universe).
Then I decided to take it to the next step, and put my new learnings to a good use.
Those who know me, know that I’m a very forgetful person. If it wasn’t for constant reminders on my smartphone I might as well forget to breathe. And this has a big toll on those around me (especially my cats, since I’m constantly forgetting to clean the litter box)
I even caught Accio The Cat trying to code a reminder routine so it wouldn’t happen again
The idea
I ended up working on something that would work like this:
- When a Green LED is lit, all is good (box is clean)
- After 24h, the Yellow LED is lit (dude, pay attention)
- After 24h, the Red LED starts to blink (critical!!)
- After I clean the box, I press a button and the Green LED is back.
The code
The code is available on this Gist
// pin numbers: | |
const int button = 2; | |
const int green = 9; | |
const int yellow = 10; | |
const int red = 11; | |
// constants | |
#define SECS_PER_HOUR (3600UL) | |
#define SECS_PER_DAY (SECS_PER_HOUR * 24L) | |
#define MILLIS_PER_DAY (SECS_PER_DAY * 1000L); | |
//#define MILLIS_PER_DAY 1000L; //for debugging | |
// variables: | |
unsigned long lastClean = 0; | |
void setup() { | |
// initialize the LED pins as an output: | |
pinMode(green, OUTPUT); | |
pinMode(yellow, OUTPUT); | |
pinMode(red, OUTPUT); | |
// initialize the pushbutton pin as an input: | |
pinMode(button, INPUT); | |
Serial.begin(9600); | |
} | |
void loop(){ | |
unsigned long currentTime = millis(); | |
if (digitalRead(button)) | |
{ | |
lastClean = currentTime; | |
} | |
int daysSinceLastClean = elapsedDays(currentTime - lastClean); | |
if (daysSinceLastClean < 1) | |
{ | |
greenLed(); | |
} | |
else if (daysSinceLastClean < 2) | |
{ | |
yellowLed(); | |
} | |
else | |
{ | |
redLed(currentTime); | |
} | |
} | |
int elapsedDays(unsigned long time) | |
{ | |
return time / MILLIS_PER_DAY; | |
} | |
void greenLed() | |
{ | |
digitalWrite(green, HIGH); | |
digitalWrite(yellow, LOW); | |
digitalWrite(red, LOW); | |
} | |
void yellowLed() | |
{ | |
digitalWrite(green, LOW); | |
digitalWrite(yellow, HIGH); | |
digitalWrite(red, LOW); | |
} | |
// | |
// RED LED | |
// | |
const int STEP = 1; | |
const int blinkSpeed = 40; | |
int brightness = 0; | |
int brightnessStep = STEP; | |
void redLed(unsigned long time) | |
{ | |
digitalWrite(green, LOW); | |
digitalWrite(yellow, LOW); | |
if ((time % blinkSpeed) == 0) | |
{ | |
if (brightness >= 254) | |
{ | |
brightnessStep = -STEP; | |
} | |
else if (brightness <= STEP) | |
{ | |
brightnessStep = STEP; | |
} | |
brightness += brightnessStep; | |
} | |
analogWrite(red, brightness); | |
} |
###Results
I have to say that in general, not only the litter box is a lot cleaner after I started using the reminder, I have outsourced my wife’s job of having to remind me everyday (she loved it!). And the daily repetition and reminder also helped me to develop a habit in which I barely need to look at the reminder now, to keep the box clean.
Comments