Hello folks how do I loop over a1-a8 each represent a soil moisture
I have been looking around on various topics
this is my atempt
#define AOUT_PIN0 A0 // Arduino pin that connects to AOUT pin of moisture sensor
#define AOUT_PIN1 A1 // Arduino pin that connects to AOUT pin of moisture sensor
void setup() {
Serial.begin(9600);
}
void loop() {
int value1 = analogRead(AOUT_PIN0); // read the analog value from sensor
int value2 = analogRead(AOUT_PIN1); // read the analog value from sensor
Serial.print("Moisture 0: ");
Serial.println(value1);
Serial.print("----");
Serial.print("Moisture 1: ");
Serial.println(value2);
delay(500);
}
Basically you can go on this way. Ready in 10 minutes, but bulky code.
You could have a look at arrays and for loops.
No copying needed and only around 10 lines of code needed.
float volt;
unsigned long val = 0;
unsigned long real = 0;
void setup()
{
Serial.begin(9600);// put your setup code here, to run once:
pinMode(A0, INPUT);
}
void loop()
{
for(int i = 0; i < 8; i++)
{
val += analogRead(A0);
delay(10);
}
real = val / 100;
volt = real * 5.0 / 1023.0;
Serial.println(volt, 4);
Serial.println(real, DEC);
Serial.println();
delay(2000);
}
//Example Sketch using multiple analog sensors into one analog input pin
//Tutorials and more at http://www.cabuu.com
int Value_A0;
int Value_A1;
int Pin_A0 = A0;
int Pin_A1 = A1;
void setup() {
Serial.begin(9600); //Start serial monitor
pinMode(Pin_A0,OUTPUT);
pinMode(Pin_A1,OUTPUT);
pinMode(A0,INPUT);
}
void loop() {
digitalWrite(Pin_A0, HIGH); //Turn D7 On
delay(100); //Wait for sensor
Value_A0 = analogRead(0); //Read Analog pin as D7
digitalWrite(Pin_A0, LOW); //Turn D7 Off
//Repeat for D8
digitalWrite(Pin_A1, HIGH); //Turn D8 On
delay(100); //Wait for sensor
Value_A1 = analogRead(0); //Read Analog pin as D8
digitalWrite(Pin_A1, LOW); //Turn D8 Off
delay(100); //Wait for sensor
//Print the results to the serial monitor
Serial.print("A0 = ");
Serial.print(Value_A0);
Serial.print(" / A1 = ");
Serial.println(Value_A1);
}
When I use those things I calibrate them first. I hold the sensor in the air, wipe clean with a paper towel, and take the average of a few readings to get the sensors dry output. Then I put the sensor into water to get the sensors 100% readings. At that point the map() function can be used to determine percent of moisture.
That line will work on a Mega, but I don't see why you're doing this.
You should only read the voltage coming from the sensor, like in post#1.
Do watch that youtube video, because most of those sensors are badly made.
Some can be fixed by simply adding a 1Megohm resistor.
Others need to be returned.
Leo..
If I would use a Mega for these sensors, I would use the internal 2.56volt reference.
Try this (untested) example sketch. Should work, assuming you have 'fixed' any bad sensor.
Leo..
If you have a DMM, then measure the resistance between sensor output and sensor ground, with the sensor disconnected from the Arduino. You should measure about 1Megohm.
If you don't measure 1Megohm, then you can add a 1Megohm resistor externally.
Post a clear picture of the sensor anyway.
Include a link where you got them from.
Leo..