I am looking at making a strain gauge with an ESP 32, Wheaton stone bridge made up off 121 ohm resistors, a 121 ohm strain gauge and HX711 amplifier. When I upload my code I get sporadic values or values the will steadily increase or decrease. I have included my code and some wiring diagrams:
#include "HX711.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 18; // Data pin
const int LOADCELL_SCK_PIN = 19; // Clock pin
HX711 scale;
// OLED display configuration
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C // I2C address of the OLED display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// Start serial communication for debugging
Serial.begin(9600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// Initialize OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display(); // Clear the buffer
delay(2000); // Pause for 2 seconds
// Tare the scale to zero it out
Serial.println("Taring the scale. Please ensure no weight is applied.");
delay(2000); // Wait for stabilization
scale.tare();
Serial.println("Taring complete.");
// Set scale calibration factor
// Replace with the calibration factor determined experimentally
scale.set_scale(2280.0); // Example calibration factor
}
void loop() {
if (scale.is_ready()) {
// Read the weight or force
float weight = scale.get_units(3); // Average of 3 readings
// Display on OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Measured weight/force: ");
display.print(weight);
display.println(" units"); // Replace "units" with "grams" or "kg" after calibration
display.display(); // Show the updated display
// Display on Serial Monitor
Serial.print("Measured weight/force: ");
Serial.print(weight);
Serial.println(" units"); // Replace "units" with "grams" or "kg" after calibration
} else {
Serial.println("HX711 not found. Check connections.");
}
delay(500); // Delay for readability
}