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
    About the element14 Community
  • 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 Analog input 'Tare/Zero' Weight Function
  • 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 Suggested Answer
  • Replies 17 replies
  • Answers 2 answers
  • Subscribers 418 subscribers
  • Views 2956 views
  • Users 0 members are here
Related

Analog input 'Tare/Zero' Weight Function

e14 Contributor
e14 Contributor over 13 years ago

Hi, I am currently working with a load cell amplifier, the output I have taken to Anal Input A0, I need to 'Tare/Zero' the low weight input value, and subtract that value from further

weighed values.

 

I would like to carry out the 'Tare/Zero' via a push button (one shot) which would store the zero value until the power supply is removed.

 

I would also like to display the zero weight via the 'Monitor' function, in order to proove the 'Tare' function is working every time.

 

I have completed the weighing code of the project. but I am completely stumped on the 'Tare/Zero' stage, I can't find an example of storing or one shot code.

 

I hope you can help to enable me to go forward with the project.

 

Regards,

 

Gordon

  • Sign in to reply
  • Cancel

Top Replies

  • mcb1
    mcb1 over 13 years ago in reply to e14 Contributor +1
    Gordon That result is a different problem than the impression you gave from you first post..... To prove the loadcell is working, try loading and running the example AnalogInOutSerial. This should prove…
  • e14 Contributor
    e14 Contributor over 13 years ago in reply to mcb1 +1
    Hi Mark, Hurray, I have found the problem!! I needed to create a new register 'int ZeroVal' as shown. then later the subtraction worked! I have improved the HMI monitor layout and it looks great, all I…
Parents
  • mcb1
    0 mcb1 over 13 years ago

    Gordon

    Without seeing your code I can't offer the exact code but something along these lines should work.

     

    Detect 'zero' button

    Read analog and store in a variable (ie int ZeroValue = 0; // value to store zero reading)

     

    Whenever you read the load cell, you subtract the ZeroValue from the reading

     

    Detect the 'monitor' button

    display or print the ZeroValue rather than the load cell reading

     

    This will remain until the micro is reset, either by power, reset button or upload.

     

    Good luck

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to mcb1

    Hi Mark,

     

    Thank you for your early feedback, you described it exactly how I would do it in PLC terms, I am new to Arduino so I am struggling with the code structure, I feel your suggestion will work, I will need to trial a few sketches and then import the working code into my current project.

     

    Best wishes,

     

    Gordon

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    int loadCellPin = 1;

    int tareButtonPin = 8;

    int currentWeight = 0;

    int taredWeight = 0;

     

    void loop() {

      //do some math to convert anaglogRead(loadCellPin) to a weight

      currentWeight = //results of that math;

     

      //check if the tare button is pushed, to see if it needs to store a value.

      if (digitalRead(tareButtonPin) == HIGH) {

        taredAmt = anaglogRead(loadCellPin);

      }

     

      //do the math to convert taredWeight from 0-1023 to a weight

     

      //i assume you'll have some sort of lcd code setup

      lcd.print("Weight: ");

      lcd.print(currentWeight - taredWeight);

    }

     

    This is what you need on a very basic level, but without any specifics I cant help too much more.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    int loadCellPin = 1;

    int tareButtonPin = 8;

    int currentWeight = 0;

    int taredWeight = 0;

     

    void loop() {

      //do some math to convert anaglogRead(loadCellPin) to a weight

      currentWeight = //results of that math;

     

      //check if the tare button is pushed, to see if it needs to store a value.

      if (digitalRead(tareButtonPin) == HIGH) {

        taredAmt = anaglogRead(loadCellPin);

      }

     

      //do the math to convert taredWeight from 0-1023 to a weight

     

      //i assume you'll have some sort of lcd code setup

      lcd.print("Weight: ");

      lcd.print(currentWeight - taredWeight);

    }

     

    This is what you need on a very basic level, but without any specifics I cant help too much more.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Hi,

     

    Thanks for the assistance, I would like to send my code to you to check it over, I am only a beginner and it has been trial and error so far.

     

    Basically I want to store a weight to an SD card shield which I have setup ok, but the tare function has stumped me!

    I have 2 buttons, button 1 is the Tare/Zero, Button 2 is the 'take weigh sample' button.

     

    I have setup to write to monitor and I can display the Tare weight when button 1 is pressed, when Button 2 is pressed it displays a scaled value in Pounds/Ounces, my problem is I cant get the subtraction of the Tare weight to work.

     

    I would appreciate any help you could give me.

     

    How can I send you the code?

     

    Regards,

     

    Gordon

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify 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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube