Chapter 26 – Experiment 18 – SMOOTHING WHEN READING DATA

The smoothing of the data is use normally when an input has a fast and huge variation of values trying to keep a quite stable value. Imagine like a wave where you need to read the highest point in a specific position. The value probably if the weather is bad is changing quite fast.

You can consider the smoothing like a simple filter that given a specific number of readings is returning the average value.

For the breadboard and schema is possible to use the ones on experiment 04, experiment 20 and experiment 21.

The code is here:
int sensVal; // for raw sensor values
float filterVal; // this determines smoothness – .0001 is max 1 is off (no smoothing)
float smoothedVal; // this holds the last loop value just use a unique variable for every                                           different sensor that needs smoothing

float smoothedVal2; // this would be the buffer value for another sensor if you needed to                                         smooth two different sensors – not used in this sketch

int i, j; // loop counters or demo

void setup()

Serial.println(“start “);

/* the main loop is a test of the smooth function. It generates a simulated square wave and then
switches in four different smoothing values. Watch the numbers scroll by as the filter value
slows down the response. */

void loop()
for (i = 0; i < 7; i++){ // substitute some different filter values
filterVal = i * .15;

for (j = 0; j< 60; j++){

if (j < 30){ // generate a simulated square wave

sensVal = 1023;


sensVal = 0;

// sensVal = analogRead(0); this is what one would do normally
smoothedVal = smooth(sensVal, filterVal, smoothedVal); // second parameter                                                            determines smoothness – 0 is off, .9999 is max smooth

Serial.print(” “);
Serial.print(smoothedVal, DEC);
Serial.print(” “);
Serial.print(“filterValue * 100 = “); // print doesn’t work with floats
Serial.println(filterVal * 100, DEC);

int smooth(int data, float filterVal, float smoothedVal){

if (filterVal > 1){ // check to make sure param’s are within range
filterVal = .99;
else if (filterVal <= 0){
filterVal = 0;

smoothedVal = (data * (1 – filterVal)) + (smoothedVal * filterVal);

return (int)smoothedVal;


  1. I like the valuable information you provide to your articles. I will bookmark your blog and take a look at once more here regularly. I am moderately sure I will learn plenty of new stuff right here! Good luck for the following!

  2. Currently it looks like Drupal is the preferred blogging
    platform out there right now. (from what I’ve read) Is
    that what you are using on your blog?

  3. Más de dos años jugando nonstop.

  4. First launched in 2009, the PX21 ranks as the #4 greatest-selling third-party
    gaming headset of all time based on the NPD Group.

  5. Give Dermefface FX7 three to 4 months for light or small scars,
    and not less than six months for deep scars and people from harm or surgery.

  6. When interest rates are high, it’s possible for the cost of
    the loan to exceed the actual value of the vehicle being
    covered. Is there any reason why any company should offer a car loan to anybody with a poor credit record.
    Some car loan lenders have strict standards and only grant
    financing to people with good or excellent credit.

    my blog – web page (Michell)

  7. I dⲟ not ᥱven know how I ended up here, but I thought thіs post was great.
    I Ԁo not know who you are but certainly you arе going to
    a famous blogger if you aren’t alrеady ;) Cheers!

  8. Goⲟd day I am so haрpy I found yoᥙr Ьloɡ page, I reallʏ found
    you by accident, while I was researchіng on Bing for something else, Regardless I am һere now and would just likᥱ to say
    kudos for a tremеndoսѕ post and a all round exciting blog (I also love thе theme/ԁesign), I
    don’t haѵe time to read throսgh it all at the moment bսt I haѵe
    bookmarked іt and also included your RSS feeds, so when I have time I will be
    back to read more, Please do keep up the superb jo.

  9. Thanks fоr the good writeup. It in truth was a entertаinment account it.
    Glance comрlex to far delivered agreeable from you! Hoᴡeѵer, how could ԝe be in contact?

  10. Howɗy! Do you ҝnow if they make any pⅼugins to protect against hackers?
    I’m kinda paгanoid about losing everything Ӏ’ve worked һard on. Any recommendations?

Leave a Reply to Dacia Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

istanbul evden eve nakliyat istanbul evden eve nakliyat istanbul evden eve nakliyat sarıyer evden eve nakliyat beylikdüzü evden eve nakliyat şişli evden eve nakliyat