77 #define NUM_READS (int)10 // Number of sensor reads for filtering
81 uint32_t SLEEP_TIME = 30000;
83 long buffer[NUM_READS];
92 const long knownResistor = 4700;
125 Serial.println (average());
126 long read1 = average();
130 Serial.println (average());
131 long read2= average();
133 long sensor1 = (read1 + read2)/2;
135 Serial.print (
"resistance bias =" );
136 Serial.println (read1-read2);
137 Serial.print (
"sensor bias compensated value = ");
138 Serial.println (sensor1);
142 send(msg.
set((int32_t)ceil(sensor1)));
147 void measure (
int phase_b,
int phase_a,
int analog_input)
152 for (i=0; i<NUM_READS; i++) {
155 digitalWrite(phase_a,
HIGH);
156 delayMicroseconds(25);
157 supplyVoltage = analogRead(analog_input);
158 delayMicroseconds(25);
159 digitalWrite(phase_a,
LOW);
162 digitalWrite(phase_b,
HIGH);
163 delayMicroseconds(25);
164 sensorVoltage = analogRead(analog_input);
165 delayMicroseconds(25);
166 digitalWrite(phase_b,
LOW);
171 long resistance = (knownResistor * (supplyVoltage - sensorVoltage ) / sensorVoltage) ;
174 addReading(resistance);
175 Serial.print (resistance);
183 void addReading(
long resistance)
185 buffer[idx] = resistance;
187 if (idx >= NUM_READS) {
195 for (
int cnt = 0; cnt < NUM_READS; cnt++) {
198 return (
long)(sum / NUM_READS);