Skip to content

Instantly share code, notes, and snippets.

@andysheen-zz
Last active August 29, 2015 14:22
Show Gist options
  • Save andysheen-zz/9246e583a0a03e12c4b4 to your computer and use it in GitHub Desktop.
Save andysheen-zz/9246e583a0a03e12c4b4 to your computer and use it in GitHub Desktop.
Thirsty Plant Water Bomb
/*TWSU Thirsty Plant Water Bomb code
Learn how to make your Thirsty Plant Water Bomb over at http://techwillsaveus.com/resources/diy-thirsty-plant-water-bomb/
created May 2015
*/
#include <Servo.h>
Servo servo;
int thresh = 300; //threshold to trigger servo
int count;
int pos = 0; // variable to store the servo position
void setup()
{
Serial.begin(9600);
servo.attach(9); // initializes the servo
delay(10000); //delay to stop servo instantly moving
}
void loop()
{
Serial.println(analogRead(0));
// thirsty plant threshold reached (when dry)
if(analogRead(0) > thresh){
for(pos = 0; pos < 30; pos += 1) // goes from 0 degrees to 20 degrees
{ // in steps of 1 degree
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(1);
}
for(pos = 30; pos>=1; pos-=1) // goes from 20 degrees to 0 degrees
{
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment