Ignore an input?

Hi, I just connected an ultrasonic range sensor to my arduino and it works pretty well. However, when im changing from a flat surface to an uneven survace, a value of 3200 cm appears once (which is a false reading). My question is: Is there a function like read.ignore(3200) or does it only work with if...else . I have searched and not found an answer and im asking because I need to optimize the code and make it simpler.

Thank you

No there is no function like that, but it is extremely simple for you to just compare the value you got and treat it differently if it is outside the range of expected values.

I know, I just wanted to know if there was a better way :).

you might try averaging several readings and when you get one that seems to be out of range you would ignore it and decide whether to average it in. Or you might have to running averages, one that does not average the outliers and one that does, and if the outlier average its tracking with you readings then you update the main running average with the secondary running average.

there would be some lag in the response when there is a large step change, but if this is not a normal condition, it gives you an automatic way of handling them.

Theelectronicguy:
I know, I just wanted to know if there was a better way :).

There is no better way, but there's no need for one - what you're describing can be implemented very simply and easily.

I found what I was looking for!!! I was reading an ebook on arduino programming and the constrain() function is what I needed.

Check it out:

So basically you write constrain(integer,minimum,maximum)

No you want to totally ignore the outrider data, not limit it to a maximum.

Euh... Not sure I follow, if my sensor has "normal" values between 0-100 and a random value of 350 appears once in a while, wont the constrain function ignore it?

No if the number is greater than the maximum it will return the maximum.

Theelectronicguy:
Euh... Not sure I follow, if my sensor has "normal" values between 0-100 and a random value of 350 appears once in a while, wont the constrain function ignore it?

Hmmm... not sure what you mean by "ignore" in this context ?

Well, it shoulndt really matter in my case as the value only appears for a split second. I am trying(or will be trying) to make my quadcopter auto-land.

Ah, ok. Anyway, I think we can say is that "ignoring" an input is not something that you look a function for. It's a matter of how your algorithm(s) deal with certain input values. IMHO, obviously :slight_smile:

Theelectronicguy:
Well, it shoulndt really matter in my case as the value only appears for a split second. I am trying(or will be trying) to make my quadcopter auto-land.

That may be a problem mate... Don't ignore something so simple to solve that can destroy your project! :confused: