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 2947 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
  • e14 Contributor
    0 e14 Contributor over 13 years ago

    Just paste the sketch into www.pastebin.com and return the link. Its makes it clean for looking at. If you want to get real fancy, select c++ highlighting.

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

    Hi,

    I have joined Pastebin and pasted the code but how do you save it?

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

    Gordon

    You can just paste it here

    There are various options if you click the Advanced Editor in top right, and then select the double chevron

    However none of them do much except the quote.

     

    image

     

    Most people just dump it here, but he developers are meant to be working on a more eligant method.

     

     

    Mark

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

     

    #include <SD.h>

    int CS_pin = 10;
    int pow_pin = 8;
    const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
    float sensorValue = 0;       // value read from the pot
    int switchState = 0;         // Dat enter push button.
    int led = 9;                // Data transfered LED
    const int buttonPin = 3;     /// the number of the Tare/Zero pushbutton pin
    int buttonState = 0;         /// variable for reading the pushbutton status
    int TareValue;
    int FinalWt;

    void setup() {
        // initialize serial communications at 9600 bps:
      Serial.begin(9600);
      Serial.println("Initializing Card");
      //CS Pin is an output
      pinMode(CS_pin, OUTPUT);
     
      //Card will draw power from Pin 8, so set High
      pinMode(pow_pin, OUTPUT);
      digitalWrite(pow_pin, HIGH);
     
      //Check card is ready
      if(SD.begin(CS_pin))
    {
      Serial.println("Card Failed");
      return;
    }
    Serial.println("Card Ready");

    }
    void loop() {
    // read the Tare input pin:
      buttonState = digitalRead(buttonPin);
      if (buttonState == HIGH){
      int TareValue = analogRead(A0);
      Serial.println (TareValue);
      }
    {
      String dataString = "Results";
     
      //Open a file to write to, only one at a time.
      File dataFile = SD.open("DATAFILE.TXT", FILE_WRITE);
      if(dataFile)
     
      {
        dataFile.println(dataString);
        dataFile.close();
        Serial.println(dataString);
      }
      //else
      {
        // Serial.println("Couldn't access file");
      }
      delay(1000);
      //pinMode(buttonPin, INPUT);
      //int TareValue = analogRead(A0);
      //int FinalWt = sensorValue - TareValue;

      // read the analog in value:
      sensorValue = analogRead(0) / 4.26;(analogInPin);
      sensorValue = sensorValue / 16;
      //sensorValue = analogRead(0) / 0.1024;(analogInPin);
      //sensorValue = sensorValue / 1000;
      pinMode(led, OUTPUT);
     
      switchState = digitalRead(2);
     
      if (switchState == HIGH){
     
      FinalWt = (analogRead(0) - TareValue);
      //int FinalWt = 100 - 25;
      // print the results to the serial monitor:
      Serial.println(FinalWt);
      Serial.print(analogRead(0));
      Serial.print(" weight = " ); 
      Serial.print(sensorValue);
      Serial.print(" lbs/oz");
      ///Serial.print(" K/g");
      Serial.println ();
      digitalWrite(led, HIGH);
      delay(100);               // wait for a 100ms
      digitalWrite(led, LOW);

      // wait 400ms before the next loop
      // for the analog-to-digital converter to settle
      // after the last reading:
      delay(400);                    
      }
      }
    }

    • 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 mcb1

     

    #include <SD.h>

    int CS_pin = 10;
    int pow_pin = 8;
    const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
    float sensorValue = 0;       // value read from the pot
    int switchState = 0;         // Dat enter push button.
    int led = 9;                // Data transfered LED
    const int buttonPin = 3;     /// the number of the Tare/Zero pushbutton pin
    int buttonState = 0;         /// variable for reading the pushbutton status
    int TareValue;
    int FinalWt;

    void setup() {
        // initialize serial communications at 9600 bps:
      Serial.begin(9600);
      Serial.println("Initializing Card");
      //CS Pin is an output
      pinMode(CS_pin, OUTPUT);
     
      //Card will draw power from Pin 8, so set High
      pinMode(pow_pin, OUTPUT);
      digitalWrite(pow_pin, HIGH);
     
      //Check card is ready
      if(SD.begin(CS_pin))
    {
      Serial.println("Card Failed");
      return;
    }
    Serial.println("Card Ready");

    }
    void loop() {
    // read the Tare input pin:
      buttonState = digitalRead(buttonPin);
      if (buttonState == HIGH){
      int TareValue = analogRead(A0);
      Serial.println (TareValue);
      }
    {
      String dataString = "Results";
     
      //Open a file to write to, only one at a time.
      File dataFile = SD.open("DATAFILE.TXT", FILE_WRITE);
      if(dataFile)
     
      {
        dataFile.println(dataString);
        dataFile.close();
        Serial.println(dataString);
      }
      //else
      {
        // Serial.println("Couldn't access file");
      }
      delay(1000);
      //pinMode(buttonPin, INPUT);
      //int TareValue = analogRead(A0);
      //int FinalWt = sensorValue - TareValue;

      // read the analog in value:
      sensorValue = analogRead(0) / 4.26;(analogInPin);
      sensorValue = sensorValue / 16;
      //sensorValue = analogRead(0) / 0.1024;(analogInPin);
      //sensorValue = sensorValue / 1000;
      pinMode(led, OUTPUT);
     
      switchState = digitalRead(2);
     
      if (switchState == HIGH){
     
      FinalWt = (analogRead(0) - TareValue);
      //int FinalWt = 100 - 25;
      // print the results to the serial monitor:
      Serial.println(FinalWt);
      Serial.print(analogRead(0));
      Serial.print(" weight = " ); 
      Serial.print(sensorValue);
      Serial.print(" lbs/oz");
      ///Serial.print(" K/g");
      Serial.println ();
      digitalWrite(led, HIGH);
      delay(100);               // wait for a 100ms
      digitalWrite(led, LOW);

      // wait 400ms before the next loop
      // for the analog-to-digital converter to settle
      // after the last reading:
      delay(400);                    
      }
      }
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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