I have built this Soil moisture sensor module – Has 8 Sensors using Analog A0 to A7 (D3 to D10 used for LEDs and D2 used for a piezo buzzer). What is happening is the LEDs are lighting up fine/ The buzzer seems to come on intermittently. is there a easier way to poll each of the sensor and only if the value is higher than the required only then light up that particular LED and give a Buzzer sound. Code is as below int led1 = 3;int led2 = 4;int led3 = 5;int led4 = 6;int led5 = 7;int led6 = 8;int led7 = 9;int led8 = 10;int BUZZER = 2; // buzzer addressed to the pin 2 void setup() {// initialize serial communication at 9600 bits per second:pinMode(led1, OUTPUT);pinMode(led2, OUTPUT);pinMode(led3, OUTPUT);pinMode(led4, OUTPUT);pinMode(led5, OUTPUT);pinMode(led6, OUTPUT);pinMode(led7, OUTPUT);pinMode(led8, OUTPUT);pinMode(BUZZER, OUTPUT);Serial.begin(9600);} void loop() {// read the input on analog pin 1:int sensorValue1 = analogRead(A0); if (sensorValue1 >=600 && sensorValue1 <=800){Serial.println(sensorValue1); digitalWrite(led1, HIGH); tone(2,392,300); //command tone that creates a sound } else {Serial.println(sensorValue1); digitalWrite(led1, LOW); } int sensorValue2 = analogRead(A1); if (sensorValue2 >=600 && sensorValue2 <=800){Serial.println(sensorValue2); digitalWrite(led2, HIGH); tone(2,392,300); //command tone that creates a sound } else {Serial.println(sensorValue2); digitalWrite(led2, LOW); } int sensorValue3 = analogRead(A2); if (sensorValue3 >=600 && sensorValue3 <=800){Serial.println(sensorValue3); digitalWrite(led3, HIGH); tone(2,392,300); //command tone that creates a sound } else {Serial.println(sensorValue3); digitalWrite(led3, LOW); } int sensorValue4 = analogRead(A3); if (sensorValue4 >=600 && sensorValue4 <=800){Serial.println(sensorValue4); digitalWrite(led4, HIGH); tone(2,392,300); //command tone that creates a sound } else {Serial.println(sensorValue4); digitalWrite(led4, LOW); } int sensorValue5 = analogRead(A4); if (sensorValue5 >=600 && sensorValue5 <=800){Serial.println(sensorValue5); digitalWrite(led5, HIGH); tone(2,392,300); //command tone that creates a sound } else {Serial.println(sensorValue5); digitalWrite(led5, LOW); } int sensorValue6 = analogRead(A5); if (sensorValue6 >=600 && sensorValue6 <=800){Serial.println(sensorValue6); digitalWrite(led6, HIGH); tone(2,392,300); //command tone that creates a sound } else {Serial.println(sensorValue6); digitalWrite(led6, LOW); } int sensorValue7 = analogRead(A6); if (sensorValue7 >=600 && sensorValue7 <=800){Serial.println(sensorValue7); digitalWrite(led7, HIGH); tone(2,392,300); //command tone that creates a sound } else {Serial.println(sensorValue7); digitalWrite(led7, LOW); } int sensorValue8 = analogRead(A7); if (sensorValue8 >=600 && sensorValue8 <=800){Serial.println(sensorValue8); digitalWrite(led8, HIGH); tone(2,392,300); //command tone that creates a sound } else {Serial.println(sensorValue8); digitalWrite(led8, LOW); } delay(1000);}
Please ignore this request, I have managed it now. The buzzer comes on only when there is a sensor not meeting the criteria. Imersing all sensors in water , cuts off all LEDs and Buzzer. Also made changes on the higer side value to 1500.
The problem with the spaces in the answers is a known problem, I’ve contacted the company that created the forum plugin and they should solve the problem with the spaces in a couple of days. Thanks for posting the code in pastebin.com Kumar!