With some help from an Arduino One, a few sensors, and a long code, we were able to build a toy that could sense when a person was in proximity, would then take a moisture reading of the soil, and provide auditory and light feedback. This was all housed inside a small plush toy.
Our final product demonstration and prototype was a short video describing the situation in which PlantBob would be used and two posters that illustrated the features and functions of our projects:
We found a variety of sources that had completed similar projects, and were able to use their examples as guides for writing our code and completing our project:
The final code used to run PlantBob can be found below:
/*
PLANT BOB 2013
- By Karin Hellman & Enrique Dominguez */
/*
# the sensor value description
# 0 ~500 in water
# 500~700 humid soil
# 700~1000 dry soil
*/
/*
SCK: pin 13
MOSI: pin 11
MISO: pin 12
CS: pin 4
*/
/*LIBS*/
#include <SD.h> // need to include the SD library for reading from the card
#define SD_ChipSelectPin 4 //using digital pin 4 on our arduino uno, can use other pins
#include "TMRpcm.h" // also need to include this library for the music playback
/*PINS*/
int motionPin = 7; //Connected to the motion sensor
int moisturePin = 0; //Connected to the moisture sensor
int moistureValue; //moisture sensor value
int motionValue; // Motion or no motion
int green = 8; //green LED on pin 8
TMRpcm tmrpcm; // create an object for use in this sketch
/*SETUP*/
void setup() {
Serial.begin(9600);
pinMode(green, OUTPUT); //make the green pin an output for lighting up our led
tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
tmrpcm.play("MidWater.wav"); //the sound file will play each time the arduino powers up, or is reset
}
/*LOOP*/
void loop() {
motionValue = digitalRead(motionPin);
moistureValue = analogRead(moisturePin);
int del = 200;
Serial.print("Moition Sensor Value: ");
Serial.println(motionValue);
Serial.print("Moisture Sensor Value: ");
Serial.println(moistureValue, DEC);
//CHECK THE PLANT's STATUS:
/* DRY*/
if (moistureValue>700){
digitalWrite(green, LOW); // turn the LED off
//If there is motion, play sound
if(motionValue == HIGH){
//play sound 1 - dry sound
Serial.println("Playing sound 1");
tmrpcm.play("LowWater.wav");
delay(5000);
}
}
/*WET*/
else if(moistureValue < 600){
digitalWrite(green, LOW); // turn the LED off
//If there is motion, play sound
if(motionValue == HIGH){
//Play sound 2 - wet sound
tmrpcm.play("HiWater.wav");
Serial.println("Playing sound 3");
delay(4000);
}
}
/*GOOD*/
else{
digitalWrite(green, HIGH); // turn the LED on (HIGH is the voltage level)
//If there is motion, play sound
if(motionValue == HIGH){
//Play sound 3 - good sound
tmrpcm.play("MidWater.wav");
Serial.println("Playing sound 2");
delay(3000);
}
}
delay(200);
}
No comments:
Post a Comment