JACK
Published © MIT

Arduino interfacing hx711 load cell with oled display

In this article we will learn how to Interface Arduino with HX711 Load cell.

AdvancedProtip2 hours3,212
Arduino interfacing hx711 load cell with oled display

Things used in this project

Hardware components

1. Arduino
×1
2. HX711
×1
3. O Led
×1
4. Load cell
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

arduino interfacing hx711 load cell with Oled display diagram

Code

arduino interfacing hx711 load cell with Oled display code

Arduino
#include "HX711.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define DOUT 3
#define CLK 2

HX711 scale;

float weight;
float calibration_factor = 419640; // Calibration factor

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
Serial.begin(9600);
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");

scale.begin(DOUT, CLK);
scale.set_scale();
scale.tare(); // Reset the scale to 0
long zero_factor = scale.read_average(); // Get a baseline reading

Serial.print("Zero factor: ");
Serial.println(zero_factor);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}

void loop() {
scale.set_scale(calibration_factor); // Adjust to this calibration factor
Serial.print("Reading: ");
weight = scale.get_units(5);
if (weight < 0) {
weight = 0.00;
}

Serial.print("Kilogram:");
Serial.print(weight);
Serial.print(" Kg");
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();

display.clearDisplay();
display.setTextSize(3);
display.setCursor(0, 0);
display.print("Weight:");
display.setTextSize(3);
display.setCursor(0, 35);
display.print(weight);
display.setTextSize(3);
display.setCursor(75, 35);
display.print("Kg");
display.display();
delay(100);
}
No preview (download only).

Credits

JACK

JACK

21 projects • 2 followers

Comments