Friday, 23 October 2015

Multiple soil moisture sensor at once in Arduino


In this post I will share a sketch which can control many soil moisture sensors at once. As you can see in picture above, I have used 2 soil moisture sensors to turn on and off 2 leds. I would have used more sensors if I had but that's all I had so I have used them all. Don't worry you can add more sensors if your Arduino board has too many pins control the thing you want.
Ad

The sketch:
int led1 = 4;
int led2 = 5;

void setup() {
// initialize serial communication at 9600 bits per second:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
Serial.begin(9600);
}


void loop() {
// read the input on analog pin 1:
int sensorValue1 = analogRead(A1);

if (sensorValue1 >=600 && sensorValue1 <=800){
Serial.println(sensorValue1);
    digitalWrite(led1, HIGH);
  }
  else {
Serial.println(sensorValue1);
    digitalWrite(led1, LOW);
  }
 
int sensorValue2 = analogRead(A2);

if (sensorValue2 >=600 && sensorValue2 <=800){
Serial.println(sensorValue2);
    digitalWrite(led2, HIGH);
  }
  else {
Serial.println(sensorValue2);
    digitalWrite(led2, LOW);
  } 
delay(1000);
}

Places to edit:
int led1 = 4; // you can change it to what ever digital pin you like.
int led2 = 5; // you can change it to what ever digital pin you like.

int sensorValue1 = analogRead(A1); // I have  made A1 (analog pin number 1) for the first soil moisture sensor and A2 (analog pin number 2) for second sensor.

if (sensorValue1 >=600 && sensorValue1 <=800){ // Here the >=600 means if the value is over 600 and under 800  <=800 then it will turn on the first LED, and if the value is under 600 and over 800 the the LED will be turned off. You can change the number as you wish, but keep in mind that less value numbers means the soil is more wet and more value numbers means the soil is less wet.

What do you need:
  • 2x LEDs. What ever color you like.
  • 2x Soil Moisture Sensors.
  • 2x 10k ohm resistor. You can leave it if you want, I've used it just to make the leds dimmer.
  • One Arduino board. In this case I've used Arduino nano.
  • Few jumper wires
That's all for this post I hope this will help you. :)


Tags:
Multiple soil sensor Arduino

Ad



No comments:

Post a Comment