I have set up two weighbridges using two Wheatstone bridge connections connected to an Arduino Uno as shown here: robotshop.com/blog/en/arduino-load-cell-lcd-17078. In my case I have 2 strain readings (A0 and A1) which I have managed to have them displayed on an LCD shield. However I am having problems programming a button to zero the readings.
The idea is that if the weighbridge is moved around and the readings change, I should be able to press the button to zero the readings and start my measurements. I have tried different things but none seem to work.
Any pointers or ideas would be highly appreciated.
I have attached the code which I borrowed from one of the LCD examples and modified it slightly to suit my needs:
// Include the AnalogSmooth Library:
#include <AnalogSmooth.h>
// Include the LCD library:
#include <LiquidCrystal.h>
// Include the Wheatstone library:
#include <WheatstoneBridge.h>
// Include support function header:
#include “strain_gauge_shield_and_lcd_support_functions.h”
// Initialize the library with the numbers of the interface pins. Pins for the 16x2 LCD shield. LCD:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Channel 1 is connected to A0 and channel 2 is connected to A1:
// Initialize the Wheatstone bridge object:
WheatstoneBridge wsb_strain1(A0, 256, 674, 0, 230);
WheatstoneBridge wsb_strain2(A1, 401, 674, 0, 480);
// Code to take an average reading from the arduino
// Defaults to window size 10
AnalogSmooth as = AnalogSmooth();
// Window size can range from 1 - 200
AnalogSmooth as200 = AnalogSmooth(200);
// Calibration values for each channel:
int Ch1_CalibrationValue = -0.4103-0.697;
int Ch2_CalibrationValue = -0.3433+0.1;
// Variables for mass calculations
int iMassCH1;
int iMassCH2;
int iTotal;
int iTare;
// Variables for force measurement and display:
int val1;
int valRaw1;
int val2;
int valRaw2;
// Timing management:
long display_time_step = 1000;
long display_time = 0;
// < Setup function>
void setup()
{
// put your setup code here, to run once:
// Initialise communication:
// Initialise serial communication
Serial.begin(9600);
// Set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Set cursor to top line first position
lcd.setCursor(0, 0);
// Print message to the LCD
lcd.print(“Welcome!”);
// Print message to serial
Serial.println(“Welcome!”);
Serial.println("");
// Display the readings on LCD Shield:
// Set cursor to bottom line first position
lcd.setCursor(0, 2);
// Print a message to the LCD.
lcd.print(“Version 1”);
delay(4000);
// Clear the LCD display
lcd.clear();
}
void loop()
{
// put your main code here, to run repeatedly:
// Smoothing with window size 10
int analogSmooth = as.smooth(val1);
// Smoothing with window size 200
int analogSmooth200 = as200.analogReadSmooth(val2);
// Apply the calibration values to the readings:
iMassCH1 = ((val1)Ch1_CalibrationValue); // Convert to kg
iMassCH2 = ((val2)-0.3433+0.1); // Convert to kg
iTotal = iMassCH1 + iMassCH2; // Add the two channels to get a total
iTare = iTotal - iMassCH1 + iMassCH2; // Calculation for the zero value
// Read strain 1:
// Make a force measurement and obtain the calibrated force value
val1 = wsb_strain1.measureForce();
// Obtain the raw ADC value from the last measurement
valRaw1 = wsb_strain1.getLastForceRawADC();
// Print to serial:
Serial.println(">> Strain 1 << “);
Serial.print(”\tRaw ADC value: “);
Serial.print(analogSmooth, DEC);
Serial.print(”\t\t");
Serial.print("\tCalculated force: ");
Serial.println(iMassCH1, DEC);
// Display the readings on LCD Shield:
// Set cursor to top line first position
lcd.setCursor(0, 0);
lcd.print ("Ch1: “);
lcd.setCursor(5, 0);
lcd.print(iMassCH1, DEC); lcd.print(“kg”);
lcd.print(” ");
// Read strain 2:
// Obtain the raw ADC value from the last measurement
valRaw2 = wsb_strain2.getLastForceRawADC();
// Make a force measurement and obtain the calibrated force value
val2 = wsb_strain2.measureForce();
// Print to serial:
Serial.println(">> Strain 2 << “);
Serial.print(”\tRaw ADC value: “);
Serial.print(analogSmooth200, DEC);
Serial.print(”\t\t");
Serial.print("\tCalculated force: “);
Serial.println(iMassCH2, DEC);
Serial.println(”");
// Display the readings on LCD Shield:
// Set cursor to bottom line first position
lcd.setCursor(0, 2);
lcd.print ("Ch2: “);
lcd.setCursor(5, 2);
lcd.print(iMassCH2); lcd.print(“kg”);
lcd.print(” “);
// Set cursor position
lcd.setCursor(11, 0);
lcd.print (“Total”);
lcd.setCursor(11, 2);
lcd.print(iTotal, DEC); lcd.print(“kg”);
lcd.print(” ");
delay(1000);
// Reset time counter:
display_time = millis();
Thank you in advance.