LOAD CELL INTERFACING USING ADS1231 AND ARDUINO

Photo of author

By Jackson Taylor

Home » Hardware Hardware » LOAD CELL INTERFACING USING ADS1231 AND ARDUINO

As an Amazon Associate we earn from qualifying purchases.

A load cell produces a very small voltage change when weight is applied, usually only a few millivolts at full load. To turn that into a number a microcontroller can use, you need a low-noise, high-resolution analog to digital converter. The ADS1231 from Texas Instruments is built for this job. It is a 24-bit converter with a built-in amplifier stage and a simple two-wire serial interface.

This article shows how to read a load cell with the ADS1231, how the sample program works, and how to set up a tare (zero) button and get stable readings on the serial monitor. The video demos below show the project working.

What you need

Why use the ADS1231 for a load cell

A load cell is a Wheatstone bridge. Its output is a small differential signal, so a standard 10-bit Arduino analog input cannot resolve it well. A dedicated converter solves that in three ways:

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video
  • 24-bit resolution gives fine steps, so small weight changes are visible.
  • Built-in gain stage amplifies the bridge signal, so you do not always need a separate load cell amplifier circuit.
  • Selectable data rate lets you choose 10 samples per second (slower, quieter) or 80 samples per second (faster, noisier).

The chip also has a power-down pin, so it can be switched off when you are not measuring, which helps in battery-powered scales.

CIRCUIT

The circuit connects the load cell bridge to the differential inputs of the ADS1231. The control and data lines then go to the microcontroller. Check the pin names against the ADS1231 datasheet and your load cell colour code before powering up, as colours differ between manufacturers.

Circuit diagram connecting a load cell, ADS1231 ADC and microcontroller

The microcontroller side uses these connections in the sample program:

  • POWERDOWN (P1_0): output. Low powers the chip down, high is normal operation.
  • SPEED (P1_4): output. Low selects 10 SPS, high selects 80 SPS. (The original comment called this a chip select pin, which is incorrect. The ADS1231 has no chip select.)
  • DATAPIN (P1_5): input. It goes low when a conversion is ready, then carries the data bits out.
  • CLOCK (P1_6): output. The serial clock to the ADS1231.
  • ZEROSWITCH (P1_3): input with pull-up. Pressing the button to ground re-zeroes the reading.
See also
CUK CONVERTER WITH MPPT FOR 12V BATTERY CHARGING FROM SOLAR PANEL USING ARDUINO

The names like P1_0 are LaunchPad (Energia) style pin names. If you use an Arduino Uno or similar board, replace them with normal digital pin numbers, for example #define CLOCK 3. The logic does not change.

OUTPUT DATA SCREEN SHOT

The serial monitor first prints the calibration (zero offset) value, then keeps printing the averaged, zero-corrected reading. With nothing on the load cell the value stays close to zero, and it rises as you add weight.

Serial monitor screenshot showing calibrated ADS1231 load cell readings

How the program works

1. Setup

The initspi() function sets the pin directions, switches the chip on with POWERDOWN high, selects 10 SPS by driving SPEED low, and leaves the clock low. Serial is started at 9600 baud, the zero switch gets an internal pull-up, and caliberate() is called once to store the starting offset.

2. Reading 24 bits

The readADS1231() function first waits until DATAPIN goes low, which means a new conversion is ready. It then sends 24 clock pulses. After each pulse it reads the data pin and adds the matching bit value to adcvalue, starting from the most significant bit (0x800000) down to the least significant bit (0x1).

One extra clock pulse follows the 24 data bits. This returns the data line to its high state, as described in the ADS1231 datasheet, so the chip is ready for the next conversion. The clock is then left low.

3. Zeroing (tare)

The caliberate() function takes one reading, divides it by 100 and stores it as the offset c. The main loop checks the zero switch continuously. When it is pressed, a new offset is stored and the displayed value returns to zero.

4. Averaging and display

The displaydata() function takes three readings, subtracts the offset from each, and prints the average. Averaging reduces the visible jitter, though at 10 SPS it also means the display updates about three times a second at most.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works
See also
bldc sensorless control using arduino

PROGRAM


//CONNECTIONS
#define POWERDOWN P1_0    //POWERDOWN -LOW TO POWER DOWN
#define SPEED P1_4    //Data rate select pin
#define DATAPIN P1_5    //Data pin
#define CLOCK P1_6 //ADS1231 clock
#define ZEROSWITCH P1_3
 unsigned long   adcvalue;
 short int i;
 float c,y,x,z;
void setup() 
{         
 initspi();
 Serial.begin(9600); //Initialize serial for debugging
 pinMode(ZEROSWITCH, INPUT_PULLUP);
 caliberate();
}
void loop() 
{
 displaydata();
 //delay(200);
 if(!digitalRead(ZEROSWITCH))
 {
 caliberate();
 //float c=y;
 }
}
void readADS1231(void) 
{
 adcvalue=0;  
 //digitalWrite(POWERDOWN, HIGH); //POWER ON
 while(digitalRead(DATAPIN));//WAIT UNTIL DATA IS READY
 //24-->21
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X800000;} //24
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X400000;}//23
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X200000;}//22
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X100000;}//21
 //20-->17
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X80000;} //20
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X40000;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X20000;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X10000;}//17
 //16-->13
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X8000;} //16
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X4000;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X2000;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X1000;}//13
 //12-->9
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X800;} //12
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X400;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X200;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X100;}//9
 //8-->5
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X80;} //8
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X40;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X20;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X10;}//5
 //4-->1
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X8;} //4
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X4;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X2;}// 
 clock ();
 if(digitalRead(DATAPIN)){adcvalue=adcvalue+0X1;}//1
 clock ();//TO PULL DATA READY TO HIGH STATE --PAGE No.14 ON ADS1231 DATASHEET
 //
 digitalWrite(CLOCK, LOW);  
 //digitalWrite(POWERDOWN, LOW);
}
void caliberate(void)
{
 readADS1231();
 c=(adcvalue/100.0);
 Serial.print("caliber=");Serial.println(c);  
}
void displaydata(void)
{
    readADS1231();
 z=(adcvalue/100.0);//100000
 z=z-c;
    readADS1231();
 x=(adcvalue/100.0);//100000
 x=x-c;
    readADS1231();
 y=(adcvalue/100.0);//100000
 y=y-c;
 y=(y+x+z)/3.0;
 Serial.print("adcvalue=");Serial.println(y);  
}
void clock (void)
{
 digitalWrite(CLOCK, LOW);  
 digitalWrite(CLOCK, HIGH);
 delayMicroseconds(10);
}
void initspi(void)
{
 pinMode(POWERDOWN, OUTPUT);  
 pinMode(DATAPIN, INPUT);
 pinMode(CLOCK, OUTPUT);
 pinMode(SPEED, OUTPUT);
 digitalWrite(POWERDOWN, HIGH); //0--> POWERDOWN(SLEEPING -NO CONVERSION) ,1-->WORKING MODE
 digitalWrite(SPEED, 0);//0--> 10SPS ,1-->80SPS
 digitalWrite(CLOCK, LOW);
}

Improving the sample code

  • Use a loop for the bits. The 24 repeated lines can be replaced by a short for loop that shifts adcvalue left by one bit and adds the data pin state each time. It does the same thing and is easier to read.
  • Rename the clock function. A function called clock can clash with a standard C library name on some boards. A name such as clockPulse avoids that.
  • Handle negative values. The ADS1231 sends its result in two’s complement. The sample code treats it as an unsigned number, so a reading below the ADC zero point would appear as a very large value. If your load cell can read negative, sign-extend the 24-bit value into a signed 32-bit variable.
  • Convert to real units. The program prints a raw scaled number, not grams. Place a known weight on the load cell, note the zero-corrected reading, and divide by the weight to get a scale factor. Divide later readings by that factor to display grams or kilograms.
See also
Arduino ,bluetooth/pc and triac based speed control of ac home fan

Tips for stable readings

  • Mount the load cell firmly and let the platform settle before taring.
  • Keep wires between the load cell and the ADC short, and away from motors or switching supplies.
  • Use a clean, well-filtered supply. Noise on the supply shows up directly in the readings.
  • Keep clock pulses short. If the clock line stays high for too long, the ADS1231 can enter power-down mode.
  • Start with 10 SPS. Switch to 80 SPS only if you need the speed and can accept more noise.

Where to go next

If you want to test the signal chain before building hardware, you can simulate a load cell in Proteus with an instrumentation amplifier. To compare this chip with a simpler serial converter, see the ADS7816 analog to digital converter project. For a practical application of weighing, take a look at the smart ration card system, which uses a load cell to measure dispensed goods.

FAQ

Do I need a separate amplifier with the ADS1231?

Usually not. The ADS1231 includes a gain stage designed for bridge sensors such as load cells, so the bridge can connect directly to its inputs.

What does the SPEED pin do?

It sets the data rate. Low gives 10 samples per second and high gives 80. The slower rate gives lower noise, which is better for a precise scale.

Can I use this code on an Arduino Uno?

Yes, but you must replace the P1_x pin names with Arduino digital pin numbers. The bit-banged read routine only uses digitalRead, digitalWrite and delayMicroseconds, which Arduino supports.

Why does my reading drift or jump?

Common causes are a loose mechanical mount, supply noise, long wires, and temperature changes. Average several samples, keep the wiring short and re-tare before measuring.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works