Hello folks, i tried to search on the internet but unfortunately i cannot find any helpful answer.
I have 0 experience in coding and electronics so be gentle.
I need to build a soil moisture monitor for 20 pots and check for them via html. The html part will be another point but that's not what i need now.
I have an Arduino Mega 2560, an Arduino Ethernet Shield, a CD74HC4067 16 channels multiplexer and 20 soil moisture capacitive sensors.
The arduino shield is connected on the Arduino Mega board.
I plugged the sensors to a 5v power supplier plugged to the wall, so the current will be stable.
I linked 15 sensors from A0 to A5 on the Arduino Shield and from A6 to A14 on the Arduino Mega.
Multiplexer:
A15 is linked to the SIGNAL of the multiplexer.
S0 -S1 -S2- S3 are linked to D0 - D1 -D2 - D3 on the Ethernet Shield.
5v and GND to the Arduino board.
C0 - C2 - C5 - C9 - C15 are the pins i used on the multiplexer, the others are empty.
The code is the following:
#include "Arduino.h"
#include <light_CD74HC4067.h>
CD74HC4067 mux(0, 1, 2, 3);
const int signal_pin = A15; // Pin Connected to Sig pin of CD74HC4067
void setup(){
Serial.begin(9600); //com enable
{
Serial.begin(9600);
pinMode(A15, INPUT); // Set as input for reading through signal pin
}
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
int sensorValue3 = analogRead(A2);
int sensorValue4 = analogRead(A3);
int sensorValue5 = analogRead(A4);
int sensorValue6 = analogRead(A5);
int sensorValue7 = analogRead(A6);
int sensorValue8 = analogRead(A7);
int sensorValue9 = analogRead(A8);
int sensorValue10 = analogRead(A9);
int sensorValue11 = analogRead(A10);
int sensorValue12 = analogRead(A11);
int sensorValue13 = analogRead(A12);
int sensorValue14 = analogRead(A13);
int sensorValue15 = analogRead(A14);
int moist1;
int moist2;
int moist3;
int moist4;
int moist5;
int moist6;
int moist7;
int moist8;
int moist9;
int moist10;
int moist11;
int moist12;
int moist13;
int moist14;
int moist15;
int moist16;
int moist17;
int moist18;
int moist19;
int moist20; //variables for calculations
}
void loop()
{int i;
int value = 0;
int numReadings = 8;
for (i = 0; i < numReadings; i++){
// Read light sensor data.
value = value + analogRead("A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15");
// 1ms pause adds more stability between reads.
delay(1);
}
for (int i = 0; i < 16; i++) {
mux.channel(i);
int val = analogRead(A15); // Read analog value
Serial.println("Vaso - "+String(i)+": "+String(val)); // Print value
delay(500);
}
delay(500);
{
int moist1 = analogRead(A0);
delay(10);
moist1 = analogRead(A0); //take reading 1
Serial.print("vaso 1 : ");
Serial.println(moist1);
delay(500); //delay to allow ADC
int moist2 = analogRead(A1);
delay(10);
moist2 = analogRead(A1); //take reading 2
Serial.print("vaso 2 : ");
Serial.println(moist2);
delay(500);
int moist3 = analogRead(A2);
delay(10);
moist3 = analogRead(A2); //take reading 3
Serial.print("vaso 3 : ");
Serial.println(moist3);
delay(500);
int moist4 = analogRead(A3);
delay(10);
moist4 = analogRead(A3); //take reading 4
Serial.print("vaso 4 : ");
Serial.println(moist4);
delay(500);
int moist5 = analogRead(A4);
delay(10);
moist5 = analogRead(A4); //take reading 5
Serial.print("vaso 5 : ");
Serial.println(moist5);
delay(500);
int moist6 = analogRead(A5);
delay(10);
moist6 = analogRead(A5); //take reading 6
Serial.print("vaso 6 : ");
Serial.println(moist6);
delay(500);
int moist7 = analogRead(A6);
delay(10);
moist7 = analogRead(A6); //take reading 7
Serial.print("vaso 7 : ");
Serial.println(moist7);
delay(500);
int moist8 = analogRead(A7);
delay(10);
moist8 = analogRead(A7); //take reading 8
Serial.print("vaso 8 : ");
Serial.println(moist8);
delay(500);
int moist9 = analogRead(A8);
delay(10);
moist9 = analogRead(A8); //take reading 9
Serial.print("vaso 9 : ");
Serial.println(moist9);
delay(500);
int moist10 = analogRead(A9);
delay(10);
moist10 = analogRead(A9); //take reading 10
Serial.print("vaso 10 : ");
Serial.println(moist10);
delay(500);
int moist11 = analogRead(A10);
delay(10);
moist11 = analogRead(A10); //take reading 11
Serial.print("vaso 11 : ");
Serial.println(moist11);
delay(500);
int moist12 = analogRead(A11);
delay(10);
moist12 = analogRead(A11); //take reading 12
Serial.print("vaso 12 : ");
Serial.println(moist12);
delay(500);
int moist13 = analogRead(A12);
delay(10);
moist13 = analogRead(A12); //take reading 13
Serial.print("vaso 13 : ");
Serial.println(moist13);
delay(500);
int moist14 = analogRead(A13);
delay(10);
moist14 = analogRead(A13); //take reading 14
Serial.print("vaso 14 : ");
Serial.println(moist14);
delay(500);
int moist15 = analogRead(A14);
delay(10);
moist15 = analogRead(A14); //take reading 15
Serial.print("vaso 15 : ");
Serial.println(moist15);
delay(500);
int moist16 = analogRead(A15);
delay(10);
moist16 = analogRead(A15); //take reading 16
Serial.print("vaso 16 : ");
Serial.println(moist16);
delay(500);
int moist17 = analogRead(A15);
delay(10);
moist17 = analogRead(A15); //take reading 17
Serial.print("vaso 17 : ");
Serial.println(moist17);
delay(500);
int moist18 = analogRead(A15);
delay(10);
moist18 = analogRead(A15); //take reading 18
Serial.print("vaso 18 : ");
Serial.println(moist18);
delay(500);
int moist19 = analogRead(A15);
delay(10);
moist19 = analogRead(A15); //take reading 19
Serial.print("vaso 19 : ");
Serial.println(moist19);
delay(500);
int moist20 = analogRead(A15);
delay(10);
moist20 = analogRead(A15); //take reading 20
Serial.print("vaso 20 : ");
Serial.println(moist20);
delay(500);
}
}
Now, the issues are:
-
few sensor displays 1023 as value, others 0 (and they're dry)
so I thought to average the value, but how? what i did doesn't seems to be correct. -
few pins on the Multiplexer gives fake values, they're not connected but they still shows 1023 as value.
-
how can i transform the values in percentage, so i know exactly how dry the soil is?
Ps: i tried many ways to draw the schematic but i couldn't, hope you can get it anyway..