Arduino and Load cell

I have been doing some experiments to get load cells working with Arduino.

This is a collection of my experiences.  Something about:

  • What is a load cell
  • How did I wire it up to an Arduino board
  • What crazy application did I use it for?

Dancing people in a rope in the hull of the illutron ship – Load cell senses the weight and control music and light.

  • Light was controlled by using diode boxes and Sonny Windstrups great code
  • Music was controlled by using Pure Data to read the Arduino board and generate a midi-controller to use in Ableton Live.
  • Dancing: Allison Lorenzen and others. Mounting: Thomas Fabrik. Rigging: Karl Gillick. Interactive music: Bo Boye.


So.. What is a load cell anyway

A digital weight.

Usually a piece of steel containing one or more Strain Gauges arranged in a Wheatstone bridge.

Full bridge configuration

How to get a load cell

The load cell I have been using is a commercial one.

SKANTRONICS FH SERIES – STAINLESS-STEEL Shear Beam Load Cell

These are quite expensive if you are heading to buy one.

Break a digital weight
There is actually a load cell sitting inside any digital weight you can find. Paper weight, Bath weight.
Buy or find a cheap one, and take it apart. Then rehook the loadcell inside.
Its a little bar of steel with 4 wires coming out of it.

Load cell inside a kitchen weight

Load cell inside a kitchen weight

The 4 wires are pretty standard color coded.
Look here for a good reference: http://www.controlweigh.com/loadcell_colors.htm

You can play around with the gain to get the accuracy you want.

Connection a load cell to an Arduino board

You need some sort of microvolt amplifier to read the minute change in volt over the bridge.

ina125P – An IC that does it all for you.

  • Very simple to use.
  • Cheap. Around 7 € at Farnell
  • Usable for many different instrumentation amplifications

This is the schematics for hooking it up:

The resistor sets the gain. Look in the datasheet of the ina125p for details.

The connection is as suggested for single supply operation in the datasheet:

And this is how it looked at the breadboard:

…And on a shield

Simple arduino example

This is a simplified example of how to convert your load cell analog readings to kilo/load.
Basic trick: Just use map();

// Arduino as load cell amplifier
// by Christian Liljedahl 
// christian.liljedahl.dk

// Load cells are linear. So once you have established two data pairs, you can interpolate the rest.

// Step 1: Upload this sketch to your arduino board

// You need two loads of well know weight. In this example A = 10 kg. B = 30 kg
// Put on load A 
// read the analog value showing (this is analogvalA)
// put on load B
// read the analog value B

// Enter you own analog values here
float loadA = 10; // kg
int analogvalA = 200; // analog reading taken with load A on the load cell

float loadB = 30; // kg 
int analogvalB = 600; // analog reading taken with load B on the load cell

// Upload the sketch again, and confirm, that the kilo-reading from the serial output now is correct, using your known loads

float analogValueAverage = 0;

// How often do we do readings?
long time = 0; // 
int timeBetweenReadings = 200; // We want a reading every 200 ms;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int analogValue = analogRead(0);

  // running average - We smooth the readings a little bit
  analogValueAverage = 0.99*analogValueAverage + 0.01*analogValue;

  // Is it time to print? 
  if(millis() > time + timeBetweenReadings){
    float load = analogToLoad(analogValueAverage);

    Serial.print("analogValue: ");Serial.println(analogValueAverage);
    Serial.print("             load: ");Serial.println(load,5);
    time = millis();
  }
}

float analogToLoad(float analogval){

  // using a custom map-function, because the standard arduino map function only uses int
  float load = mapfloat(analogval, analogvalA, analogvalB, loadA, loadB);
  return load;
}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Considerations

  • I am using the 5V of the Arduino board as exitation to the load cell, not the 5v-ref on the chip
  • Using a 1760 kg load cell I was able to sense 0.1 kg changes
  • You may have to swap the voltage applied to the bridge to get a decent range on the analog signal
  • Measure the output voltage (input to analog 0) while you change your load, and adjust the gain until you get a good sense
  • Analog input at the arduino board is used. Play around with the aref – analogreference – to get a good sense.
  • analogReference in my sketch was set to INTERNAL making it 1.1 V – Wich gave me a good range

31 Responses to “Arduino and Load cell”

  1. barry says:

    Hi,
    i’m looking to do exactly the same thing, but i cant for the life of me work out the code for the arduino board – are you able to email me the code you have used ?

    many thanks.

  2. chrlilje says:

    Hi Barry
    What exactly are the problem with your code?

    Since its all about sensing at the analog input pin, you should take a voltmeter, and test what you get there. Then adjust accordingly.

    I can post my code here when I get to it tomorrow. Or, post your code to me – I may be able to deduct the problem from your code :-)
    yt
    Christian

  3. barry says:

    Hi,
    sorry, been a while – i had to spend some time on another project. anyway, the problem i have is mapping the reading from analog pin 0 to a human readable format – in kilograms and grams …
    if you are able to mail me your code (if you created the code with a conversion to kg) that’d be erally useful !
    many thanks

  4. chrlilje says:

    Hi Barry
    The way to convert your analog data to kilos is by calibrating your load cell.
    The great thing about load cells is, that they behave linear. So you only need two data-pairs to do the rest.
    I havn’t converted my data to actual weight.

    But do something like this:
    Lets say you have a 10 Kg load cell
    Put 1 kilo on and read the analog value
    Put 2 kilo on and read the new analog value

    A quick way around converting your values is by using the map-function in Arduino (http://www.arduino.cc/en/Reference/Map)

    If I at some point make some actual kilo-conversion-code, I will surely post it. :-)

    good luck!
    C

  5. barry says:

    ok, thats great – thanks for your help – will let you know how i go !

  6. vito says:

    Hy I am working on the exact same project in scholl and would love it if you`d post the code…
    I tryed doing some work on the code, but I do not have an arduino kit yet, and my deadline is coming up…
    Would be very grateful for the code.

    thank you

  7. martin says:

    Hi,

    Good day.
    I am trying to use your setup with the load cell for my thrust stand setup.
    My load cell is a 40 kg one with 5 pins: red, black, black, green and white.
    I connected the pins while coupling the two black ones similar to your circuit.
    Apparently, I have not seen much deflection from the INA125P Vout reading.
    Can you give me a typical reading from your setup.
    I have been literally standing on it while the load cell is on the edge of a wooden table and I can’t see deflections.
    I hope you can help me.

    Thanks,

    Martin

  8. chrlilje says:

    Hi – Regarding sensitivity, then I could get about 0.1 kg sensitivity from a 1700 kilo load cell.
    This I did using about 6000 times of amplification with the resistor.

    If you don’t see any deflection, then it is off somehow. It is very visible, when it is visible.

    Did you build your load cell yourself? Sometime the cell is skewd, and you need to add a resistor to correct it.

    You should be able to see a milivolt change on a normal multimeter, even without the amplification of the INA125. My best bet is, that you have connected the wires wrongly. The color codes are completely different from manufacturer to manufacturer.

    Hope you get it working!
    kind regards
    C

  9. chrlilje says:

    Hi vito

    Sorry for not posting the code yet. It was developed on an old computer, and I havn’t dug the code up from it yet.
    I hope you can make your deadline – It is quite simple – Read an analog value, and change it to a corresponding kilogram value. It is linear, so its a basic linear function.

    kind regards
    Christian

  10. martin says:

    Thanks for the advice.
    I got the load cell to work properly finally.
    The problem was bad soldering.
    Right now I am running an arduino and processing visual graphing program to visualize deflections.
    My new problem is that the reading from the INA125P drifts.
    I cannot get a fixed value as a basis or zero line since it keeps on drifting.
    Any guess / tip regarding this?

  11. chrlilje says:

    Did you make your load cell yourself, using strain gauges?

    In that case, if you have a half-bridge configuration, you will get drifting values due to temperature changes.

    This can also be the case, if you are running long wires to your load cell, I think.

    I have always made my designs able to auto calibrate every now and then.

    Good luck! :-)
    Christian

  12. Palle B says:

    Nice work!

    I’m also doing a project, with a load cell, and i have sort of copied your INA125 setup.

    Just now i read your last comment, on auto calibration.
    Would you like to share, the code for that feature?
    I have been thinking a lot about how to overcome this, so any info will be much appreciated.

    Thanks

    // Palle

  13. vito says:

    great work!
    I am still waiting for the code, when you get around to itbut I am most impresed!

    And I agree with Palle the code would be much apriciated.

    thank you again for the great work

    vito

  14. vito says:

    I was wondering why you have the 12 V going into the arduino…
    And are all the grounds are linked together to the -5 V?

    And I know I am being a neusence, but could you please post the code…

    thank you so much :)

    vito

  15. chrlilje says:

    Hey Vito

    I have just been a slug, not posting here for quite a while. The summer has been insanely busy with a lot of projects with illutron (www.illutron.dk) and now I finally have some time off – And can get around to the replys :-)

    About the 12V: That is just the normal power input for the Arduino. Could be 5-19 V or something. The voltage regulator of the Arduino crank it down to +5V.

    The ground wires are all connected together to the ground of the arduino board. No -5V here. It is the easiest way of operating it with the arduino board.

    I am digging for the “autocalibrating” code now. It is not very pretty, and are mostly designed for the installations I have used, where there was no real need for accuratesse. :-)

    yt
    Christian

  16. vito says:

    No wories my friend :)

    thanks for the info and am looking forward to the code.
    I thought as much for the gnd, but had to make shure just in case :)
    I realy apreciate you takeing the time to reply all our posts and am looking forward to the code :)

    thanx again christian

    vito

  17. vito says:

    hy christian!

    its me again :)
    I was wondering what equations you used for the bridge and for the INA 125; to get the resistance diference converted to kg`s or pounds (dont know which you are working with)?

    thanks

    vito

  18. chrlilje says:

    Hey Vito

    I have been a lazy boy with the code, sorry. I dug it up and would have uploaded it, but I realized, that it was such a messy codework, that it would be completely impossible to understand for anyone other than me.
    So – as I am writing this, I am rewriting the code to a more eatable simple example. :-)

    yt
    C

  19. chrlilje says:

    Hey again
    Finally got around to update the page with some code.

    It is a very basic example – Please modify for your own use.
    - and let me know if it makes sense :-)
    /C

  20. vito says:

    hey christian!

    thank you so much for not freaking out on the count of me bothering you so much :)
    I would like to thank you for the code and all your work and “customer suport” :)
    the code makes sense and its great to see everything you can do if you have the will and the knowhow :)
    the code is wonderfuly put together an I actualy understand how it works even thoe I am not an expert like you :)

    so once again thanks so much for your help and motivation on this project and I would be more than happy to return the favor if you ever want to know ANYTHIG about martial arts or workout programs modyfied for the individual user (this is my field of expertise)
    :)

    indeted to you for A LONG TIME :) ))

    vito

  21. vito says:

    THE CODE WORKS PERFECTLY MY FRIEND AND WITH YOUR HELP I PASSED MY EXAM!!!

    so thank you again!
    the profesor wanted me to macek the code useing the equations for the bridge and the amplyfier, but he said this was a very inovative way of solveing the proces :)
    I of course told him that I had help, but he didnt care, becouse it was a beter code that he had planed for :)
    I was thinking of building on your code further and makeing a scale that would aslo mesure body fat procentage and the amount of water inside a person (%) and keeping score of my fitness level as I progress as time goes by…

    what do you think?

    vito

  22. chrlilje says:

    Hey Vito

    I am really glad to hear, that it was usable to you :-) And that your professor even thought it was an innovative solution, thats just great to hear – Thanks for sharing.
    You could definately make body fat calculations and things like that using an Arduino. I havn’t any experiences with this, but look around the net for it.

    What you will be looking at soon, if you want to log stuff, is to get some serious way of reading you data and storing them automatically. That could be on a computer or on a website somewhere.

    It is pretty hard to do any connectivity with the arduino without a computer inbetween. The Ethernet Shield can do you a little help, but it is not too fun to work with.

    Good luck and kind regards
    Christian

  23. Abel says:

    Hey Christian,

    I am using a load cell that requires 10V excitation. I have an external power source, and I bridged the INA125P to work with the 10V. But I wanted to know if I needed to change out or adjust the resistor with this set up. I appreciate any help.

    Abel

  24. chrlilje says:

    Hi Abel
    I must say, that my experience is, that it is needed to fiddle with the amplification, depending on you actual setup.
    It depends on how much you want out of you load cell.
    I needed to experiment with the values. If you look in the datasheet, you can see the amplifications equivalencees to resistor values.

    good luck!

  25. ericson costa says:

    Caro amigo gostaria de saber como consigo o cod para equilibrar as medidas.

    obrigado !!!!

  26. [...] searching around the web today I stumbled upon this great article by Christian Liljedahl about his adventures getting loadcells to work with the arduino. I [...]

  27. lalantha says:

    hi
    i need to measure applied load of caster wheel tyre
    100 kg- 350kg,
    tyre is small so we have to use small strain gauge
    dimension of strain gauge
    length <15mm, width<8mm width<3mm . how I select stain gauge and how i buy

  28. lijuan says:

    Hi,
    I got some problems about this project. I got a load cell from digital scale, and i used arduino nano 3.0 to connect the circuit. I follow the circuit connected. But my circuit is not working so well. it is not sensitive at all. I didn’t use your program to test, i write a simple analogread program to test the analog read. I must use a lot of pressure, then i can get the value. it seems didn’t amplifier. So i really need some help. Please reply me as soon as possible. Thank you so much.

  29. chrlilje says:

    Hi lijuan
    - You problem is probably that you have an offset on your load cell.
    And you need to compensate for that.

    Measure the voltage coming out of the bridge when it is not loaded.
    - You should have the same voltage compared to ground on each of the two. – If not, you have to add a resistor to balance the voltage.

  30. lijuan says:

    Hi chrlilje,

    - Thank you for reply. Because this is the first time i used load cell. I am not familiar with this part. How should i compensate the offset on my load cell. I got the load cell from digital scale, so i don’t have any datasheet about the load cell. Is your load cell have the same problem too?

    - I measure the voltage coming out of the bridge when it is not loaded, the voltage is the same. If this circuit is working, is the load cell working same as the digital scale? is it give very precise value?

    Thank you.

  31. lijuan says:

    Hi Chrlilje,

    Thank you for reply.
    - I used 0-5kg load cell from digital scale. Is that an issue for the sensitive reading? what range load cell is the best choose?
    - Where should i put the resistor to compensate the offset and what value i should choose for the resistor?
    - If the circuit is working, is the same as normal digital scale?

Leave a Reply