# Determine the average of several sensors

Hello all

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?

Greetings Jonny

Given 5 values how would you calculate their average using pencil and paper ?

no i mean how i write the code

Start with how you would do it manually then you can convert it to code

The easier you make it to read and copy the code the more likely it is that you will get help

``````
#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() {

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

divide and then multiply by 5

Try again

``````uint32_t add;
add = sensorValue0 + sensorValue1 + sensorValue2 + sensorValue3 + sensorValue4;
uint16_t divide;