Arduino Load Cell - Project Stage 3

Home Basic Guides Projects Blog
The code for operating the load cell is given below and is available on github (Click here).  The output from the load cell is measured as an analogue input on pin A1.   I have also calculated the input as a rolling average of the 10 measurements.  I used the analogue output is a rolling average of the previous 10 values taken at 500ms intervals.  Therefore you have to wait at least 5 seconds to get a reading.  Both the rolling average and the current reading are sent to the serial monitor (check that the baud rate is 9600).

For the load cell to be any use we need to calibrate it.  To calibrate the load cell we will place a set of known weight on the load cell and record the output readings.  For this I grabbed a couple of my exercise weights.  I used 0.5kg, 1kg and 2.5kg.  This allowed me to mix and match them to get masses of 0,0.5, 1, 1.5, 2.5, 3, 3.5 and 4kg.  We have to be careful, however.  The

/*

Stage 1 sketch for the load cell


Stage 1 simply sets up the load cell and take an analogue reading.


*/


int loadCell = A1;                //output from load cell

int analogValue = 0;


const int numReadings = 10;      //determines the number of values in the rolling average

int readings[numReadings];      // the readings from the analog input

int index = 0;                  // the index of the current reading

int total = 0;                  // the running total

int rollingAverage = 0;         // the rolling average reading




void setup()

{

 Serial.begin(9600);


 for (int thisReading = 0; thisReading < numReadings; thisReading++)    //This need to be in the set-up section to aviod resetting the array in the loop

 readings[thisReading] = 0;                                            // initialize all the readings in the array to 0


 }

 

void loop(){

 

 analogValue = analogRead(loadCell);

  

   rollingReading();

   Serial.print(analogValue);

   Serial.print(", ");

   Serial.println(rollingAverage);



delay(500);


 }



void rollingReading() {

 

 

 total= total - readings[index];              // subtract the last reading   

 readings[index] = analogRead(loadCell);      // read from the sensor

 total= total + readings[index];             // add the reading to the total:      

 index = index + 1;                          // advance to the next position in the array:

 if (index >= numReadings)                  // if we're at the end of the array wrap around to the beginning

 index = 0;                           

 rollingAverage = total / numReadings;         

//  Serial.println(rollingAverage);   

 delay(1);                              // delay in between reads for stability            

}





Next Step

Connect the wires and load the code

THE INSIDES

The Arduino and the amplifier fit neatly inside the wooden support

COMPLETE UNIT

A wooden tray is screwed to the other side of the load cell.  The objects to be weighed sit on this.

masses stamped on the weights may not be that accurate, so I measured them on my kitchen scales to get a more accurate reading.  So in reality I am calibrating my load cell against my kitchen scales.  I don’t really know which is more accurate, but provided I get similar readings I’m happy.  Also you will need to take a reading from the load cell without any thing attached to it, and take into account the weight of the wooden tray that sits on top of it.

The load cell provides an analogue output that is read by the Arduino sketch

© Flow RC June 2014

Disclaimer:  Flow RC cannot accept any liability for any mishaps that you may have if you attempt to copy these projects.  Please read our terms and conditions.


Please contact us at: feedback@flowrc.co.uk