element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Reading analog values Arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 11 replies
  • Answers 2 answers
  • Subscribers 402 subscribers
  • Views 1935 views
  • Users 0 members are here
  • arduino
  • analog
  • sensor
Related

Reading analog values Arduino

Former Member
Former Member over 12 years ago

Hello everyone,

 

Currently I am working a project..I have 8x8  piezoresistive sensor matrix (i simply used 2 muxs) and I have only 1 analog output that gives me 64 different voltage values (changes depending on the pressure,and its between 2.5 V -5V) for each scan..so what i want to do is,to scan the matrix 10 times and get the averaged values of each cell of the matrix called smoothing..I do know how to do it for single readings but as i mentioned above I get 64 values..so somehow for each loop i have to store 64 values each time and smooth the data..Here what I have wrote..

 


const int numReadings = 64;           // Number of readings for each scan
const int numLoop=10;                   //Number of loops for each scan
float readings[numReadings];         // the readings from the analog input after each scan
float totReadings[numLoop];         //total readings from the analog input  scan
int   index_readings = 0;              // the index of the current reading
int   index_loop=0;                      // the index of the current loop

float average[numReadings];       //Averaged value

int   total[numReadings][numLoop];

 

int inputPin = A0;                     //Determine the pin

void setup()
{
   Serial.begin(9600);                  
  // initialize all the readings
  for (int i = 0; i < numReadings; i++)
  readings[i] = 0; 
  // initialize all the loops
  for(int j=0; j<numLoop;j++)
  totReadings[j]=0;
}
void loop() {
 
  // read from the sensor: 


  totReadings[numLoop]=totReadings[numLoop]+readings[index_readings];

 

  readings[index_readings] = analogRead(inputPin);  //Read the data from sensor (64 values)
 
  // advance to the next position in the array: 
  index_readings = index_readings + 1;

 

  index_loop = index_loop + 1;   
 
  // if we're at the end of the array...
  if (index_readings >= numReadings)             
    // ...wrap around to the beginning:
    index_readings = 0;  
   
  if (index_loop >= numLoop)             
    // ...wrap around to the beginning:
  index_loop = 0;
 
  //Take the average value
  average[numReadings]=totReadings[numLoop]/numLoop;  //Averaged value divided by 10(number of loops)

  Serial.println(average[numReadings]);                              //Print the averaged value 64x1
  delay(100);

 

}
  }
    }

 

image

I havent tested it yet but I do not feel satisfied though..I would be grateful to you if you can give me some ideas for improvement..Thanks a lot in advance..

  • Sign in to reply
  • Cancel

Top Replies

  • billabott
    billabott over 12 years ago +1
    The ADC is 10 bits of resolution. 2^10=1024. You have thrown away half of your range: 0 to 2.5 volts. Consider doing something to correct that. At some point you will divide by 10 > 8 =2^3. So, the lower…
Parents
  • Former Member
    0 Former Member over 12 years ago

    Hello everyone again;)

     

    So any other recommendation or ideas?

     

    Thanks..

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to Former Member

    Are you wanting to do the computed average for samples sets 1..10 and then a separate computed average for sample sets 11..20, etc?    Or are looking to have a sliding window on the data input stream so you can compute the average for arbitrary sample sets x..x+9?   

     

    Can you add more comments to you code?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • billabott
    0 billabott over 12 years ago in reply to Former Member

    Are you wanting to do the computed average for samples sets 1..10 and then a separate computed average for sample sets 11..20, etc?    Or are looking to have a sliding window on the data input stream so you can compute the average for arbitrary sample sets x..x+9?   

     

    Can you add more comments to you code?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Former Member
    0 Former Member over 12 years ago in reply to billabott

    actually not..let me make it clearer.--my sensor output gives 64 different voltage values for each loop. [its a sensor matrix 8*8 , 8 rows and 8 columns..i used 2 counter with different speed so that i can scan the whole matrix--after 1 scan i will get 64 different values 64x1] ..I want to make 10 loops[ 10 scans] and show the averaged value at the end..I have put the image in the previous answer..

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube