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
Blog Arduino: Find the greatest value
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 10 Feb 2014 1:08 AM Date Created
  • Views 615 views
  • Likes 0 likes
  • Comments 4 comments
  • help
  • photo
  • resistor
  • arduino
Related
Recommended

Arduino: Find the greatest value

Former Member
Former Member
10 Feb 2014

Dear element14 members,

 

     I am doing a science fair project where I am taking 10 readings from a photo-resistor and trying to take the greatest value to do something else. Is there a simpler code than making a lot of  if statements? .....or maybe an IC or something?

 

Thanks In Advance,

 

Blockman301

  • Sign in to reply
  • dougw
    dougw over 11 years ago in reply to Former Member

    Hi Nehemiah,

    For this, you don't need to store all 10 readings, just create 2 variables - one to store the maximum sensor READING and one for the corresponding servo POSITION, then as you take each reading, decide if the new sensor reading is larger than your previous maximum. If the new reading is larger than the old maximum READING, store the new reading as your maximum READING and store its position as your maximal POSITION. After the 10th reading simply send your second servo to the maximal servo POSITION.

    Doug

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 11 years ago

    Here is what I am doing. I have a photo resistor on a servo. Every 5 minutes I want the servo to move to 10 different positions and take 10 readings. Then I want it to take the greatest of the readings and move a different servo to the positions of the greatest reading.

     

    Thanks in advance,

    Nehemiah Branson

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 11 years ago

    Hi Nehemiah,

    For a software solution you could use a "For" loop.

    Cycle through all 10 readings - if the next reading is greater than the max reading, replace the max reading with this new value.

    Doug

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 11 years ago

    Hi Nehemiah,

    What is the timing of your 10 readings?

    You might be able to use a "peak-hold" circuit to retain the maximum analog voltage and just sample it once.

    There are lots of example circuits on the net - the simplest uses just a diode and capacitor and maybe a resistor.

    For higher accuracy you can add a dual op-amp to eliminate the voltage drop across the diode.

    If you describe the requirement in more detail, the optimal solution description can also be more detailed.

    Doug

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • 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