Then when i apply the strain in up /down direction i can see that the led for up and down turns on..However I do have a small problem for the case of no strain.
In case of no strain ; average,max,min values are nearly same [+-5 acceptable].
2nd part ; I want to return the new average_offset each eg-.5 minutes is it possible? i should maybe take a look at time interrupts.
have a look at blink without delay example how you can schedule a certain action with time. However as you want to be sure that there is no strain at the moment of recalibration you should consider a user action - e.g. make a pin high - and then read the new calibration until the pin is low.
which fullfills all cases for no stain..However when I apply strain in up or down dsirection and hold it for a second the max and min values come close therefore the boths leds getting off like there is no strain..I need to find a specific condition for no strain case..
Additionally, reagarding coming back to void offsett in order to define new offset value every 5 minutes i tried this ;
int updateCounter = 0;
if (updateCounter++ >20) {
offset();
updateCounter = 0;
}
after e.g 20 loops [around ]1 minute it goes back to void offset() and defines the average_offsett again and yeap it works at least now i am able to see my max min average and average offset value..but the only problem is led condition in no strain case .
Regarding my enquiry, I have progressed a bit more now there is only one problem left!..
I am now able to read sensor,take average the sensor readings, finding max and min value of sensor readings and now i also can see the standard deviation of sensor readings..Moreover,I can also save a average_offset value from 1st reading and every 5 minutes this value is renewed in order to find the direction of strain...The only problem left : I can not determine the case for no strain!
when there is no strain ;
Sensor reading ,max,min,average_offset and average values are nearly same--standard deviation is nearly zero..
Up Direction ;
average value decreases so if (average_offset > average ) then its UP
Down Direction ;
average value increases so if (average_offset < average ) then its DOWN
but for both UP and DOWN cases when i hold it for a while; Sensor reading ,max,min, and average values are coming closer so I dont have any option to define a condition for no stain case...
...hi, i'm new to arduino and programming. i want to find the maximum reading of a sensor. i made it worked but the problem is i want to get the maximum of all the values and not only of certain number of reading. can you help?thanks in advance..
...hi again!!
sorry, i'm really new to this. isn't the "INBUF" in answer 2 represents the number of readings to be compared?
suppose i have this very simple one and i want to serial.print the maximum reading and the current reading at the same time. thank you very much!
const int ledPin = 13; // led connected to digital pin 13
const int sensorPin = A0; // the piezo is connected to analog pin 0
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(sensorPin);
Serial.println(sensorReading);
delay(100); // delay to avoid overloading the serial port buffer
}