Skip to main content
  1. Open the Arduino application and begin running your sensor so that you are getting data values. Open your serial monitor to view the data.
    • Open the Arduino application and begin running your sensor so that you are getting data values.

    • Open your serial monitor to view the data.

  2. Begin a for loop by typing "for(".
    • Begin a for loop by typing "for(".

    • The for loop is divided into 3 sections by semi colons. In the first section the variable being altered is established. The second is, the conditions for which the loop will be used under. The third section is what will be done when the conditions of the loop are met.

    • A for loop works by repeating an action continuously until the conditions of the loop are no longer applicable.

    • For example, if you want to get 20 different numbers from your sensors to be averaged you would set it up like this: for(int avg = 0; avg < 20;avg++.

    • ++ is the same as add one to the previous number.

    • So for(int avg = 0; avg < 20;avg++, essentially means the integer avg starts at 0 and for each round of the for loop 1 is added to the previous integer value of avg until it reaches 20.

    • So it will run, in this case, 20 times.

  3. Within your for loop you should first put the commands you use to acquire data from your sensor(s).
    • Within your for loop you should first put the commands you use to acquire data from your sensor(s).

    • In this case we want to average our values. One way to accomplish this is to first get data from your sensor(s) and set it to a "oldvaluex". Then begin a for loop and get values again within your for loop and name these new numbers "newvaluex".

    • After getting new values set "oldvaluex" = (oldvaluex + newvaluex)/2. This resets your oldvaluex to a averaged number and re-inputs that value into the for loop.

    • This averaging will continue until the for loop has finished running.

    • The result will be an "oldvalue" number for your data that is averaged 20 times.

  4. Here is a link to code used to average values outputted by the Arduino MPU 6050, but the principles of the code can be extrapolated and replicated to function for a different sensor.
    • Here is a link to code used to average values outputted by the Arduino MPU 6050, but the principles of the code can be extrapolated and replicated to function for a different sensor.

    • Code: https://github.com/AidenKunkler-Peck/Com...

Finish Line

One other person completed this guide.

Aiden Kunkler-Peck

Member since: 07/05/2018

229 Reputation

4 Guides authored

0 Comments

Add Comment

View Statistics:

Past 24 Hours: 0

Past 7 Days: 1

Past 30 Days: 1

All Time: 28