-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensors.c
37 lines (32 loc) · 958 Bytes
/
sensors.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "sensors.h"
#include "analog_util.h"
float measure(adc_t line)
{
float measurements = 0.0;
//first measurement is erronious
adc_sample(line, ADC_RES);
for (int i = 0; i < ADC_SAMPLES; i++)
{
int32_t sample = adc_sample(line, ADC_RES);
measurements += adc_util_mapf(sample, ADC_RES, 0.0, ADC_VREF);
}
return measurements / ADC_SAMPLES;
}
float measureSoilHumidity(adc_t line)
{
float normalizedSoilHumidity = ((measure(line) * 50.0) / 3.0);
return normalizedSoilHumidity;
}
float measureVbatt(adc_t line)
{
// R3= 980k; R4=1.3m -> u0= (sample * (R3+R4))/R4);
float normalizedVoltage = ((measure(line) * 2.28) / 1.3);
//printf("Converted %f\n", normalizedVoltage);
return normalizedVoltage;
}
float measureSoilTemperature(adc_t line)
{
//printf("Converted %f\n", measure(line));
float normalizedHumidity = (measure(line) - 0.541) * 100;
return normalizedHumidity;
}