const int PROBE = A1; // Analoge pin 7 const int ALARM_LEVEL_1 = 500; // the value after the RED LED goes ON const int ALARM_LEVEL_2 = 250; // the value after the LED goes ON int ledPinGreen = 3; // LED connected to pin 2. int ledPinYellow = 4; // LED connected to pin 3. int ledPinRed = 1; // LED connected to pin 6. void setup() { // put your setup code here, to run once: pinMode(ledPinGreen, OUTPUT); // sets the digital pin as output pinMode(ledPinYellow, OUTPUT); // sets the digital pin as output pinMode(ledPinRed, OUTPUT); // sets the digital pin as output pinMode(PROBE, INPUT); // sets the analoge pin as input } void loop() { int moisture = analogRead(PROBE); // read sensor value int red = 0; int yellow = 0; int green = 0; if(moisture > ALARM_LEVEL_1) { red = 1; // turn on red light } else if(moisture > ALARM_LEVEL_2) { yellow = 1; // turn on yellow light } else { green = 1; // turn on green light } // turn on the LEDs digitalWrite(ledPinRed, red); digitalWrite(ledPinYellow, yellow); digitalWrite(ledPinGreen, green); delay(1000); }