Olá meu caros,
Para não criar outro tópico resolvi utilizar esse pois meu problema é similar.
Estou trabalhando com dois sensores, no arduino, de saída de 1 a 5V e precisava suavizar a saída deles. A questão é que não consigo fazer o arduino ler os dois sensores simultaneamente, apenas um. Alguém poderia me dar uma bola?
Segue o meu código funcionando para um sensor apenas:
const int numReadingsP = 10;
int readingsP[numReadingsP]; // the readings from the analog input
int indexP = 0; // the index of the current reading
int totalP = 0; // the running total
int averageP = 0; // the average
int inputPinP = A0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadingsP; thisReading++)
readingsP[thisReading] = 0;
}
void loop() {
// subtract the last reading:
totalP= totalP - readingsP[indexP];
// read from the sensor:
readingsP[indexP] = analogRead(inputPinP);
// add the reading to the total:
totalP= totalP + readingsP[indexP];
// advance to the next position in the array:
indexP = indexP + 1;
// if we're at the end of the array...
if (indexP >= numReadingsP)
// ...wrap around to the beginning:
indexP = 0;
// calculate the average:
averageP = totalP / numReadingsP;
float voltagemP = averageP * (5.0 / 1023.0);
float milimetrosP = (voltagemP * 63.69) - 63.7;
lcd.setCursor(0, 0);
lcd.print("D.P: ");
lcd.print(milimetrosP);
lcd.print("mm/H2O ");
delay(300); // delay in between reads for stability
Obrigado galera!!!!