sawell
April 29, 2021, 1:51pm
1
Hello all
I need help or your advice for my project
I want to build an automatic irrigation system for my greenhouse. I want to determine the moisture of the soil with 5 soil moisture sensors and combine these values to an average value.
Can someone explain to me how I can now get these values from the 5 sensors to an average value?
Thanks in advance
Greetings Jonny
Given 5 values how would you calculate their average using pencil and paper ?
sawell
April 29, 2021, 2:18pm
3
no i mean how i write the code
Start with how you would do it manually then you can convert it to code
Please post your code that gets the 5 values
The easier you make it to read and copy the code the more likely it is that you will get help
Please follow the advice given in the link below when posting code
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
sawell
April 29, 2021, 2:26pm
5
#define ventil 2
#define SENSOR_PIN0 A0
#define SENSOR_PIN1 A1
#define SENSOR_PIN2 A2
#define SENSOR_PIN3 A3
#define SENSOR_PIN4 A4
int sensorValue0 = 0;
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;
void setup() {
Serial.begin(9600);
pinMode(ventil, OUTPUT);
}
void loop() {
int sensorValue0 = analogRead(A0);
int sensorValue1 = analogRead(A1);
int sensorValue2 = analogRead(A2);
int sensorValue3 = analogRead(A3);
int sensorValue4 = analogRead(A4);
Serial.println(sensorValue0);
delay(500);
Serial.println(sensorValue1);
delay(500);
Serial.println(sensorValue2);
delay(500);
Serial.println(sensorValue3);
delay(500);
Serial.println(sensorValue4);
delay(500);
}
If I told you that
sensorValue0 = 20
sensorValue1 = 25
sensorValue2 = 30
sensorValue3 = 10
sensorValue4 = 18
Show how you would work out the avarage on paper
sawell
April 29, 2021, 2:37pm
7
divide and then multiply by 5
sawell
April 29, 2021, 2:45pm
9
uint32_t add;
add = sensorValue0 + sensorValue1 + sensorValue2 + sensorValue3 + sensorValue4;
uint16_t divide;
divide = add / 5;
Serial.println(divide);
like so
Why don't you try it ?
There is a neater way of doing it but get it working the simple way first