• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Arduino – Soil Moisture Sensor with a Buzzer

Q&A Forum › Category: Arduino › Arduino – Soil Moisture Sensor with a Buzzer
0 Vote Up Vote Down
Kumar Krishnamurthi asked 9 years ago

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);}    

Question Tags: Arduino, Piezo Buzzer, Soil Moisture Sensor
5 Answers
0 Vote Up Vote Down
Kumar Krishnamurthi answered 9 years ago

Sorry will paste the code in pastebin for readability  

0 Vote Up Vote Down
Kumar Krishnamurthi answered 9 years ago

http://pastebin.com/RumZ6YJu

0 Vote Up Vote Down
Kumar Krishnamurthi answered 9 years ago

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.

0 Vote Up Vote Down
Rui Santos Staff answered 9 years ago

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!

0 Vote Up Vote Down
Rui Santos Staff answered 9 years ago

I’m glad you solved the problem with the code:)

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.