006 - Brickcell Weight HX711 | MakeCode Microbit
Introduction
The HX711 is a precision 24-bit analog-to-digital converter (ADC) designed for weigh scales and industrial control applications. It is commonly used to interface with load cells, which are sensors used to measure weight or force. The HX711 load cell amplifier provides a stable and accurate digital output of the load cell's signal, making it suitable for applications like kitchen scales, industrial weighing systems, and more.
Hardware Instruction
Let's explore how to connect the HX711 weight sensor to a micro:bit microcontroller and utilize MakeCode for programming.
- Connect the Weight sensor GND pin to microbit GND pin.
- Connect the Weight sensor VCC pin to microbit VCC pin.
- Connect the Weight sensor data pin (DAT) to microbit pin 0.
- Connect the Weight sensor clock pin (SCL) to microbit pin 1.
Software Instruction
Now, let's start into programming the micro:bit to utilize the HX711 weight sensor.
- Login to https://makecode.microbit.org/ using your Microsoft account.
- Create a new project by clicking the "New Project" button. You may name it anything you want, I suggest to name it with descriptive name such as "weight-hx711-test".
- Click the "Extensions" block just under the "Math" block.
- Type https://github.com/gbantique/brickcell-weight-hx711/ on the search bar.
- Select the "brickcell-weight-hx711" from the search results. The "weight hx711" block should appear under the "Brickcell" block.
- Copy the code provided below.
1Brickcell.initHX711(DigitalPin.P0, DigitalPin.P1)
2serial.setBaudRate(BaudRate.BaudRate115200)
3serial.writeLine("Setup done.")
4basic.forever(function () {
5 serial.writeString("Weight: ")
6 serial.writeLine(Brickcell.readWeight())
7 basic.pause(1000)
8})
- Open a Serial Monitor such as Termite terminal app https://www.compuphase.com/software_termite.htm/. Set the baud rate to 115200 bps.
Or you make a copy of my created project in your MakeCode workspace.
https://makecode.microbit.org/S23983-69246-99555-78181/
Expected Result
If you carefully follow the provided instruction above, you should be able to view the measured weight in milligrams on the serial terminal every 1000 milliseconds.
If you want to used the LCD:
- Add the extension of LCD and the Weight Sensor from the following: https://github.com/gbantique/brickcell-lcd-i2c/ and https://github.com/gbantique/brickcell-weight-hx711/
- Copy and paste the following code:
1Brickcell.init(0);
2Brickcell.initHX711(DigitalPin.P0, DigitalPin.P1);
3Brickcell.set_multiplier(423);
4basic.forever(function () {
5 Brickcell.ShowString(Brickcell.readWeight(), 0, 0);
6 basic.pause(1000);
7})
For calibration: Adjust number "423" in the Brickell.set_multiplier(423) until you get accurate readings.
Posts in this series
- 016 - Brickcell 8x16 Dot Matrix Display | MakeCode Microbit
- 015 - Brickcell 8x8 Dot Matrix Display | MakeCode Microbit
- 014 - Brickcell CO2 SGP30 | MakeCode Microbit
- 013 - Brickcell Gesture APDS9960 | MakeCode Microbit
- 012 - Brickcell Rotary Encoder | MakeCode Microbit
- 011 - Brickcell RTC DS3231 | MakeCode Microbit
- 010 - Brickcell Gyro MPU6050 | MakeCode Microbit
- 009 - Brickcell TOF VL53L0X | MakeCode Microbit
- 008 - Brickcell Color TCS34725 | MakeCode Microbit
- 007 - Brickcell Pressure BMP280 | MakeCode Microbit
- 005 - Brickcell Fine Dust | MakeCode Microbit
- 004 - Brickcell Ultrasonic HCSR04 | MakeCode Microbit
- 003 - Brickcell NTC Temperature | MakeCode Microbit
- 002 - Brickcell DHT11 | MakeCode Microbit
- 001 - Brickcell LCD I2C | MakeCode Microbit
No comments yet!