Toni’s first moisture sensor

Here is my first electronic creation – moisture sensor that can make a servo move with a different speed relative with the soil moisture… device that no one can survive without!

But before to reach these high technological goals I first had to learn few more simple tricks.

My first step was to build circuit that make LED turn on. Then we learn how to use arduino and so to control the electricity and make the LED blinking with computer code. Then we programmed servo to move on its own. Finally I looked up how to make a moisture sensor circuit in Google and I hooked up the sensor to the arduino and the servo and programmed so the sensor make the servo move differently.

Here is the code you can use to build it by your self.

const int VAL_PROBE = 0; // Analog pin 0
const int MOISTURE_LEVEL = 250; // the value after the LED goes ON
#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int goup =1;

int led = 13;

int pos = 0; // variable to store the servo position
void setup() {
Serial.begin(9600);
myservo.attach(4); // attaches the servo on pin 9 to the servo object }
pinMode(led, OUTPUT);
}
void LedState(int state) {
digitalWrite(13, state);
}

void loop() {

int moisture = analogRead(VAL_PROBE);

Serial.println(moisture);
if(pos >180)
{
goup=0;
}

if(pos < 0){
goup=1;
}
if (goup==1)
{
pos = pos+1;
}
if(goup == 0)
{
pos = pos-1;
}
myservo.write(pos);
delay(moisture/10);

if (moisture < 500)
{digitalWrite(led, HIGH); }

if (moisture > 500)
{digitalWrite(led, LOW); }
}