is there anyway calculate an average of an int analogRead values from a sensor and store in another int ?
For example: 6 readings
10, 12, 11, 12, 35, 11
and average them?
thank you guys
is there anyway calculate an average of an int analogRead values from a sensor and store in another int ?
For example: 6 readings
10, 12, 11, 12, 35, 11
and average them?
thank you guys
Seriously?
is there anyway calculate an average of an int analogRead values from a sensor and store in another int ?
How would you do it using a pencil and paper ?
Hello guys, I have two Sharp IR sensor and my program is compering the two analog reading but the other sensor is spiking a lot, and is there a way to average my analog reading by numReading = 6; here is the link in the arduino website, i just dont understand it.
thank you guys
//collects data from an analog sensor
int sensorpin = A0; // analog pin used to connect the sharp sensor
int val = 0; // variable to store the values from sensor(initially zero)
int sensorpin1 = A1;
int val1 = 0;
#include <SoftwareSerial.h>
SoftwareSerial SIM900A(6,7);
void setup()
{
Serial.begin(9600); // starts the serial monitor
SIM900A.begin(9600);
}
void loop()
{
val = analogRead(sensorpin); // reads the value of the sharp sensor
Serial.println(val); // prints the value of the sensor to the serial monitor
delay(600); // wait for this much time before printing next value
val1 = analogRead(sensorpin1);
Serial.println(val1);
delay(800);
if (val > val1);
IRtxt1();
if (val = val1);
IRtxt2();
if (val1 < val);
IRtxt3();
}
void normal(){
SIM900A.println("AT+CMGF=1");
delay(500);
SIM900A.println("AT+CMGS="+639359753016"\r");
delay(500);
SIM900A.println("Water Level: NORMAL");
delay(500);
SIM900A.println((char)26);
delay(4500);
}
void IRtxt1(){
SIM900A.println("AT+CMGF=1");
delay(500);
SIM900A.println("AT+CMGS="+639359753016"\r");
delay(500);
SIM900A.println("WARNING! Water overflow );
delay(500);
SIM900A.println((char)26);
delay(5000);
}
void IRtxt2(){
SIM900A.println("AT+CMGF=1");
delay(500);
SIM900A.println("AT+CMGS="+639359753016"\r");
delay(500);
SIM900A.println("Normal");
delay(500);
SIM900A.println((char)26);
delay(5000);
}
void IRtxt3(){
SIM900A.println("AT+CMGF=1");
delay(500);
SIM900A.println("AT+CMGS="+639359753016"\r");
delay(500);
SIM900A.println("yes");
delay(500);
SIM900A.println((char)26);
delay(5000);
Khael123:
Hello guys, I have two Sharp IR sensor and my program is compering the two analog reading but the other sensor is spiking a lot, and is there a way to average my analog reading by numReading = 6; here is the link in the arduino website, i just dont understand it.https://www.arduino.cc/en/Tutorial/Smoothing
thank you guys
Since the Arduino has only A/D converter, I have seen answers recommending reading each pin twice and using only the second value.
Paul
if (val = val1);
= for assignment
== for comparison
and delete the semicolons from the end of your if lines