Pages

Thursday, April 4, 2019

HX711 load cell amplifier library for AVR ATmega

Update to v02


HX711 is a precision 24bit ADC IC designed for weigh scales and industrial control applications to interface directly with a bridge sensor.

A load cell is a transducer that is used to create an electrical signal whose magnitude is directly proportional to the force being measured.

The library you can find here is usefull to implement a weigh scale using the HX711.


References used to implement this library are
This HX711 Arduino library, https://github.com/bogde/HX711
And that other library here https://github.com/getsiddd/HX711

Methods to get raw values and unit values from the HX711 are provided.
Also you can find function to calibrate the IC.

Before using this IC you have to calibrate it against the load cell used.
The calibration task is split in 2 steps:
1) The tare raw value offset needs to be obtained, To perform this task you have to run the calibrate step 1 function without any weight on the load cell.
2) Using the tare raw value and a know weight put on the scale you can capute the scale value that is used to obtain the weighted value.
For this reason is important that the reference weight has a well know value.


Once you have obtained the scale value, you can use it to get weight, and you can also perform a new tare without having to calibrate the scale again.

The sample provieded contains all the step needed to calibrate the sensor and obtain raw and unit values.

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1Mhz.


Changelog
  • v02: fixed a bug in read function, clean code
  • v01: first version

Code

Notes
  • read risk disclaimer
  • excuse my bad english

42 comments:

  1. hello the schematics and the picture of the connection is different

    ReplyDelete
  2. Replies
    1. Hello, yes you can add it. Just use an LCD driver and code a little the sample file to show it on LCD.

      Delete
  3. Pls did use USB to ttl to interface with pc and pls what app did u use on the PC and how did u do it

    ReplyDelete
    Replies
    1. Hello, you have to implement your own protocol over UART, and use a USB to TTL adapter like the CP210x based one.

      Delete
  4. hello,
    can atmega32/atmega16 be used instead of atmega8?

    ReplyDelete
    Replies
    1. thanks for your immediate response,
      I already connected the dout and sck pin to A0 and A1 pin respectively, but am unable to get any output on a 20X4 lcd connected to the IC with internal clock off 1 MHz.
      Should i connect the pins to digital inputs?

      Delete
    2. You just have to connect DOUT and PD_SCK, remember to set proper pins in hx711.h file. Also I would not use LCD for the first test, I would use uart. If you have a logic analizer you can find out DOUT and SCK trace to debug what's going on.

      Delete
  5. Hi, amazing work! Thanks alot.
    I am having an issue that my weight reading is NOT changing. Can you help me please?

    ReplyDelete
    Replies
    1. Please let me know if there is any thing to check?

      Delete
    2. Hello Saad, you could use a logic analizer to inspect the DOUT and PD_SCK lines. Alternatively you can add an uart library and put some uart debug point in the code to check what's wrong. Also consider double checking your wiring, or try with other hx711 board and load cell, it also may be some hardware related error. That's what i would do, hope this helps.

      Delete
  6. hi sir.
    I use a 10kg sensor, what should I change.
    sorry. |double weight = hx711_getweight();|
    Is the value here calculated in kilograms or grams?

    I use google translate to ask questions. hope you forgive me.
    Xin Cảm Ơn - Thanks You

    ReplyDelete
    Replies
    1. Dear Thach. The getweight function return the weight based on the calibration weight you have put during calibration. In order to use this sensor you have to calibrate it. You can test the calibration using the sample code provided (take a look at HX711_MODECURRENT), but in a production environment you have to expose the calibration functionalities.

      Delete
    2. that means, i need to change the "Offset and scale" parameters ?

      Xin Cảm Ơn Ngài

      Delete
    3. Yes, those two depends on you load cell.

      Delete
  7. Hello brother, This code for Codevision avr?? Or not?

    ReplyDelete
    Replies
    1. Hello, no. This library was developed on Eclipse, built with avr-gcc.

      Delete
  8. Sir I am successfuly build this project but sir I am using 1000 kg load cell but sir reading is fluctuating ,I am want .5 kg accuracy

    ReplyDelete
    Replies
    1. The reading should not be fluctuating. I think there's something workng. About the accurancy take a look at the combined error of your load cell too.

      Delete
    2. Sir I am use hx711 ready-made module,pin no 13(VfB) is not used in your ckt VfB is use,in any effe
      ct this,and what is used this pin?

      Delete
    3. Hello, there are just two pin you have to score, they usually are named DOUT and SCK.

      Delete
  9. Can you interface weight sensor to MegaTRon Atmega 16 Board

    ReplyDelete
    Replies
    1. Hello, yes. You should just change the ports used by the chip.

      Delete
    2. I have used the B port for LCD display and HX711 load cell also uses B port. what should I do?

      Delete
    3. You can use other ports for one of the two. In case of HX711 you can set the ports in the header file of this library.

      Delete
  10. Sir I am use load cell at a+ ,a- and sir b+ and b- is connect ground or keep open?

    ReplyDelete
    Replies
    1. Hello, you should use A+- and E+- pins, like schematic attached.

      Delete
  11. Sir, thanks for sharing your own library. I stil got some trouble with your lib, so can i see your main.c to understand more?
    Thanks alot!

    ReplyDelete
    Replies
    1. Hello. You can find the main,c in the sample project.

      Delete
  12. Can you Please show the Weights in LCD Display 16X2. Like if we put a Weight on Load Cell it as to be display in LCD even when weight changes

    ReplyDelete
    Replies
    1. Hello, you can build this using the P.Fleury LCD library for AVR, putting all togheter with this library.

      Delete
  13. Hi. Can I connect 5 HX711 modules to the SCK pin on the ATmega328P. I want to measure force in all 3 axes.

    ReplyDelete
    Replies
    1. Hello, you can connect more than one HX711 but you have to change the code for this library. This library just support one ic at time. It wouldn't be that hard.

      Delete
  14. Sir I am use 1000 kg load cell I want 1 kg accuracy but sir load cell count not sense below 2kg weight.mean loadcell give no count of 1 kg wieght

    ReplyDelete
    Replies
    1. Hello, take a look at comment "May 21, 2021 at 6:48 AM"

      Delete
  15. Sir in here when we use atmega32 should we need to resolute the digital signal to 24 bit to 8 bit?

    ReplyDelete
    Replies
    1. Hello, you can use the library as provided, there should not be problem using this on ATmega32.

      Delete
  16. I need to get force and then it send to activate vibration motor. What kind of vibration motor should I use? Can I use 12V DC motor?

    ReplyDelete