76 #define NUM_READS (int)10 // Number of sensor reads for filtering
80 uint32_t SLEEP_TIME = 30000;
82 long buffer[NUM_READS];
91 const long knownResistor = 4700;
124 Serial.println (average());
125 long read1 = average();
129 Serial.println (average());
130 long read2= average();
132 long sensor1 = (read1 + read2)/2;
134 Serial.print (
"resistance bias =" );
135 Serial.println (read1-read2);
136 Serial.print (
"sensor bias compensated value = ");
137 Serial.println (sensor1);
141 send(msg.
set((int32_t)ceil(sensor1)));
146 void measure (
int phase_b,
int phase_a,
int analog_input)
151 for (i=0; i<NUM_READS; i++) {
154 digitalWrite(phase_a,
HIGH);
155 delayMicroseconds(25);
156 supplyVoltage = analogRead(analog_input);
157 delayMicroseconds(25);
158 digitalWrite(phase_a,
LOW);
161 digitalWrite(phase_b,
HIGH);
162 delayMicroseconds(25);
163 sensorVoltage = analogRead(analog_input);
164 delayMicroseconds(25);
165 digitalWrite(phase_b,
LOW);
170 long resistance = (knownResistor * (supplyVoltage - sensorVoltage ) / sensorVoltage) ;
173 addReading(resistance);
174 Serial.print (resistance);
182 void addReading(
long resistance)
184 buffer[idx] = resistance;
186 if (idx >= NUM_READS) {
194 for (
int cnt = 0; cnt < NUM_READS; cnt++) {
197 return (
long)(sum / NUM_READS);