49713 Designing for the Internet of Things
· 16 members
A hands-on introductory course exploring the Internet of Things and connected product experiences.
These garden fairies can help make sure your plant grows smoothly by watching over how much light it's receiving and whether or not it has started to wilt!
These little garden fairies live by your flowers and help make sure they are standing upright and receiving all the light they need.
The fairies wake up at 7am and start caring for your flower until 6 pm, which is when they head to bed. During the day, the fairies will monitor how upright your flower is using a flex sensor. If your flower starts to wilt, the fairies will then send you a warning via Slack. As the flower continues to wilt, the messages will start to sound more urgent, meaning you should really check on your flower to check on it or water it.
During the day, the fairies also monitor how much light your flowers are receiving with a photoresistor. When it gets too dark, the fairies will play a short fairy tune and shine a magical (LED) light on your flowers to give them all the brightness they need throughout the day. If the surroundings get bright again, the fairies will turn off their magical light.
At 6pm, the fairies will retire to bed and will stop sending you any alerts about how upright your flower is or how much light it’s receiving. That is until 7 am, when the new day begins…
The approach to this device was inspired by the story of The Lorax (by Dr. Suess). The same way the Lorax is the guardian of the forest, looking over the trees, these garden fairies are small accessories that could be placed near your plant to look over and care for it. They bring magic into your house with their lights and tunes. Unlike plant-monitoring pots, these creatures are small and, along with their light, can be moved around to other plants very easily. They create a mystical and fun atmosphere around your plant and can act as ornaments too!
The approach uses two fairies. The first fairy sits by your plant, leaning back on its stem. Its wings are embedded with flex sensors that are able to detect when your plant begins to wilt. The second fairy hangs out by the magical light, looking down at the plant, making sure that it is getting enough light. This fairy has a photoresistor in its hat that can measure the brightness around your plant.
If you believe (and I mean really
believe), these garden fairies will turn your home into a magical forest of
mystical creatures
I started off this project with a photoresistor and flex sensor to record light and water levels through wilting. I set up my circuit and code to record sensor inputs from both the photoresistor and flex sensor and convert them into outputs measured through LED lights. I then attached a piezo buzzer to create a sound output for when the photoresistor reaches a low (dark) value. In order to link the flex sensor to an alert system, I created an applet in IFTTT that linked Particle to Slack. Whenever the flex sensor reaches a dangerously low value, it sends an alert to Slack.
While setting up the piezo buzzer, I struggled to make it only buzz once whenever the brightness changed rather than continuously. I eventually was able to do this using Boolean values that I attached to my if statements.
After I set up my circuit and code, I decided to incorporate the time of day into my code. I initially struggled with this because the Particle website doesn’t indicate how to call the ‘Time’ function. I was able to find a code with the help of Particle community conversations, which allowed me to use Time. --> #include "application.h"
//This allows the use of Time (throughout the day)
#include "application.h"
// Define a pin to place the photoresistor on
int photoCellPin = A0;
// Create a variable to hold the light reading
int photoCellReading = 0;
// Define a pin to place an LED on
int ledPin1 = D2;
// Create a variable to store the LED brightness.
int ledBrightness1 = 0;
// Create a variable to store the photoresistor reading
int brightnessReading = 0;
// Define a pin to place the FSR on
int flexPin = A1;
// Create a variable to hold the FSR reading
int flexReading = 0;
// Create a variable to store the LED brightness.
int ledBrightness2 = 0;
// Create a vairable for speaker
int speakerPin = D4;
// Create boolean variables to define if brightness has changed for the first time or has been consistently dark/bright
bool brightFrequency = false;
bool songPlaying = false;
//Define notes for melody
const int NOTE_C4 = 262;
const int NOTE_G4 = 392;
const int NOTE_A4 = 440;
// Define melody
int melody[] = {
NOTE_C4, NOTE_G4, NOTE_A4 };
//Define note durations
int noteDurations[] = {
2, 2, 1};
void setup()
{
// Set up the LED for output
pinMode(ledPin1, OUTPUT);
// Create a cloud variable of type integer
// called 'light' mapped to photoCellReading
Particle.variable("light", &photoCellReading, INT);
// Create a cloud variable of type integer
// called 'force' mapped to flexReading
Particle.variable("force", &flexReading, INT);
pinMode( speakerPin, OUTPUT );
}
void loop()
{
// Use analogRead to read the photo cell reading
// This gives a value from 0 to 4095
photoCellReading = analogRead(photoCellPin);
// Map this value into the PWM range (0-255)
// and store as the led brightness
brightnessReading = map(photoCellReading, 0, 4095, 0, 255);
ledBrightness1 = 0;
//Set time zone to Eastern USA daylight saving time
Time.zone(-4);
if (Time.hour() > 2 and Time.hour() < 18){
//Make LED turn on if there is no sufficient light between 7:00 am and 5:59 pm
//Make it turn off if there is sufficient light
//Turn it off otherwise, between 6:00 pm and 6:59 am
if( brightnessReading > 0 and brightnessReading <= 127.5){
ledBrightness1 = 255;
} else if (brightnessReading > 127.5 and brightnessReading >= 255){
ledBrightness1 = 0;
}
}
// fade the LED to the desired brightness
analogWrite(ledPin1, ledBrightness1);
if (Time.hour() > 2 and Time.hour() < 18){
//during 7 am and 6 pm: if there is no sufficient light, turn on light melody (ONCE)
// if there is sufficient light turn on dark melody (ONCE)
if(brightFrequency== false and brightnessReading <= 127.5){
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
songPlaying = true;
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(speakerPin, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 0.5;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(speakerPin);
}
//set variables as true/false when room is consistently dark
songPlaying = false;
brightFrequency = true;
}else if (brightnessReading > 127.5){
// reset variable when the room gets dark
brightFrequency = false;
}
}
// wait 1 second and then loop
delay(1000);
// Use analogRead to read from the sensor
// This gives a value from 0 to 4095
flexReading = analogRead(flexPin);
plant_status();
}
// send notification when plant starts to wilt
void plant_status(){
// if flex sensor bends slightly then send message warning
if( flexReading >500 and flexReading <= 800){
Particle.publish("plant_status", "Uh oh! It looks like the plant is starting to wilt.");
}
// if flex sensor bends more, send another more urgent warning
else if( flexReading > 300 and flexReading <= 500){
Particle.publish("plant_status", "Oh no! We need help! The plant is wilting");
}
// if flex sensor bends drasticaly, send warning that plant stem has broken off
else if(flexReading > 0 and flexReading <= 300){
Particle.publish("plant_status", ":O It's too late! The plant stem has broken off!");
}
}
Click to Expand
Taking this project forward, I would try to refine how often the flex sensor reading creates an alert. I would like to have it alert the plant owner once a day if the plant starts to wilt rather than every time the sensor records it as wilting. I would also refine the brightness of the LED according to the brightness in the room. Currently, it either fully turns on or fully turns off; however, in varying brightness conditions, the LED may not need to be at maximum brightness. Thus, adjusting the sensitivity of the photoresistor and LED would be a next step.
There could be ways to allow the plant owner to further engage with the fairies or use them for other purposes. This would be something I could further explore.
The process as a whole was smooth due to the many instructions provided along the way. It was a very fun project! Due to my limited coding knowledge, I did encounter some struggles understanding what certain lines of the code meant and how to write my own lines. Overall, I was able to seek help from people, online tools, and the Particle community conversations to better understand how to code in Particle.
A hands-on introductory course exploring the Internet of Things and connected product experiences.
These garden fairies can help make sure your plant grows smoothly by watching over how much light it's receiving and whether or not it has started to wilt!
November 7th, 2019