1 x red, yellow and green
1) Connect the 5.0V power to Row 1 on the breadboard.
2) Connect the GND to Row 17 on the breadboard.
3) Connect one resister to 17B pin and the other to B5.
4) Connect the cathode of the RED LED to pin 5E
5) Join a wire from the anode to pin 13 on the ARDUINO
6) Connect one resister to 17C pin and the other to 9C.
7) Connect the cathode of the GREEN LED to pin 9CE
8) Join a wire from the anode to pin 10 on the ARDUINO
9) Connect one resister to 17D pin and the other to 13D.
10) Connect the cathode of the RED LED to pin 13E
11) Join a wire from the anode to pin 8 on the ARDUINO
To test the wiring and code in TINKERCAD you will need to follow the wiring of the first illustration. when wiring up the real moisture sensor you will need to follow the second diagram. (The +VE wire and the sensor wire to the sensor are swapped on the breadboard.)
1) Connect the power from A2 to 15A
2) Connect the GND will be used as is.
3) Connect the A1 pin of the Arduino to pin16A.
4) Plug the POT into pins 15E, 16E, 17E
// C++ code
//
/*
Code for making a moisture sensor operate a
traffic light informing the user of high, medium and
low moisture levels in the soil.
*/
int sensorValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(A1, INPUT);
pinMode(13, OUTPUT);
pinMode(10, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{
Serial.available();
// You will be able to modify the values depending
// on the type of soil/plants are being grown.
// this IF section sets up for the soil being dry
// with a HIGH resistance. It will then turn on the
// RED light
if (analogRead(A1) >= 600) {
digitalWrite(13, HIGH);
digitalWrite(10, LOW);
digitalWrite(8, LOW);
} else {
// This IF command will will let you know that
// there is the right amount of moisture, with a
// MEDIUM amount of resistance. It will then turn
// on the GREEN light
if (analogRead(A1) <= 599) {
digitalWrite(13, LOW);
digitalWrite(10, HIGH);
digitalWrite(8, LOW);
}
// This IF statement will notify you if there is
// too much moisture in the soil with a very LOW
// resistance. This will turn on the YELLOW light.
if (analogRead(A1) <= 300) {
digitalWrite(13, LOW);
digitalWrite(10, LOW);
digitalWrite(8, HIGH);
}
}
delay(10); // Delay a little bit to improve simulation performance
}