Mr. Greenie McGreen Reacts

Since I really enjoy using servos (I like them more than LEDs), I wanted to create a stupid pet trip that would at least use more than one of them. I originally just wanted to have a LDR that would basically take into the account the light levels that the plant was getting and if there weren’t enough sunlight, the servo, acting as the eyebrows of the face on the pot, would point more downwards to depict an angry/sad face – like in the image below.

But then during the class discussion, I found two other alternatives that would be cooler 1) detect the water levels of the plant and then that would trigger the servo to move, 2) anthropomorphosise the plant and have a sound detector/microphone attached that would sense that there is sound next to it so that it’ll be happy when it hears that someone is talking to it.

I started playing around with the soil moisture sensor first because I was most unfamiliar with it. After some confusion with how to connect it, I finally got it to work and tried to actually water the plant so that the soil moisture level would change. Below is a video of the serial monitor that showed the moisture level.

The code for this is shown here:

int val = 0; //value for storing moisture value
int soilPin = A0;//Declare a variable for the soil moisture sensor
int soilPower = 7;//Variable for Soil moisture Power

//Rather than powering the sensor through the 3.3V or 5V pins,
//we’ll use a digital pin to power the sensor. This will
//prevent corrosion of the sensor as it sits in the soil.

void setup()
{
Serial.begin(9600); // open serial over USB

pinMode(soilPower, OUTPUT);//Set D7 as an OUTPUT
digitalWrite(soilPower, LOW);//Set to LOW so no power is flowing through the sensor
}

void loop()
{
Serial.print(“Soil Moisture = “);
//get soil moisture value from the function below and print it
Serial.println(readSoil());

//This 1 second timefrme is used so you can test the sensor and see it change in real-time.
//For in-plant applications, you will want to take readings much less frequently.
delay(1000);//take a reading every second
}
//This is a function used to get the soil moisture content
int readSoil()
{

digitalWrite(soilPower, HIGH);//turn D7 “On”
delay(10);//wait 10 milliseconds
val = analogRead(soilPin);//Read the SIG value form sensor
digitalWrite(soilPower, LOW);//turn D7 “Off”
return val;//send current moisture value
}

 

After making sure that I knew how to work the soil moisture sensor, I moved on to programming my servos. At this point, I realised that it would be a lot more fun if the servos could react to sound (as in cooler and more different for the final product). I, therefore, decided to move towards using the sound detector sensor. Like the soil moisture sensor, I had to figure out how to connect the wires and where to solder headers and what not.

After making sure that it works, I tried to programme the servos so that they would react to changes in the sound detector. This process took me many many hours because I couldn’t figure out why, even if there were no sound, the sound detector would detect that there is a sound and so the servo would be in a constant movement phase where there would be no time that it was not moving. Using the serial monitor, I realised that it was in a constant loop of “quiet” and “loud”.

Messing around with the code, I realised that I couldn’t tell the servo to move 0, 90, or 180 degrees or it would malfunction, I could only use numbers that were not those 3. I still don’t understand why that is, but my code worked after that. The video for that is shown before.

The code for this is shown below:

 

#define PIN_GATE_IN 2
#define IRQ_GATE_IN 0
#define PIN_LED_OUT 13
#define PIN_ANALOG_IN A1

void soundISR()
{
int pin_val;

pin_val = digitalRead(2);

}

#include <Servo.h>
int servoPin = 10;
int servoPin2 = 9;
Servo Servo1;
Servo Servo2;

void setup()
{
Servo1.attach(servoPin);
Servo2.attach(servoPin2);
Serial.begin(9600);

// configure input to interrupt
pinMode(2, INPUT);
// attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);

// Display status
Serial.println(“Initialized”);

}

void loop()
{
int value;

// Check the envelope input
value = analogRead(A5);

// Convert envelope value into a message
Serial.print(“Status: “);
if(value <=10)
{
Serial.println(“Quiet.”);
Serial.println(“In Quiet”);

Servo1.write(45);
Servo2.write(125);
delay(250);
}

else if(value >= 11)
{
Serial.println(“Loud.”);
Serial.println(“In Loud”);
Servo1.write(10);
Servo2.write(160);
delay(250);

//Servo1.write(90);

delay(100);
}

// pause for 1 second
delay(750);

}

 

It was then time for me to make the actual hardware part in order to show what I wanted to do with the eyebrows for the plant pot. After measuring where the servos would be located in the pot, I drilled 2 holes into the side of the pot where they would stick out. I realised that the “head” of the servo was too short to extend to the outside of the pot so I attached two small pieces of some plastic straws to the tip of the servo. After that, I messed around with the angles that the servos should turn in so that the eyebrows would move in the direction that I want them to move in.

Making sure that the angles were okay, I then glued two pieces of popsicle sticks to the straws so that the eyebrows would actually be attached to the servos. I then gave the pot 2 eyes and a mouth.

I put a flat layer of hard styrofoam on top of the servos and placed a real plant on the top so that the fake pot could actually do something in useful terms – have a real plant so that the whole point of the project would work.

I then decided to test the project out. The video of my final project in action is shown below:

And here’s my plant, Mr. Greenie McGreen reacting to Adele’s “Hello” because why not.

So yea, I didn’t end up using the moisture sensor- but at least I know how it works now!

Also, I originally wanted to make it so that the faces would change from a angry/sad face to a happy face but the shocked face worked out better because then it would just recognise that someone was talking to it and if someone were to swear at it *ahem Adham*, it would show a shocked face and not a happy face. So, I guess it worked out!

NOTE: I basically created the base in which you put your plant pot onto, not the plant itself.

Leave a Reply

Your email address will not be published. Required fields are marked *