ESP32 Sensor Integration
firmware-starter-esp32-temperature-and-load-cell-sensor.U1:VIN because the ESP32 DevKit’s VIN power input is unused, and 20 airwires because the PCB layout has not been placed/routed yet. Next steps are to decide whether to model the DevKit power source explicitly or accept VIN as intentionally unused, then proceed to PCB placement and routing.outOfCredit state. No dangling traces or missing footprints were found, but the board still has 20 airwires because routing did not start.0x44Table
| Function | ESP32 pin | Net | Connected To | Direction | Notes |
|---|---|---|---|---|---|
| I2C SDA | GPIO21 / D21 | I2C_SDA | U2 SDA, R1 pull-up | Bidirectional | 4.7kΩ pull-up to 3V3 |
| I2C SCL | GPIO22 / D22 | I2C_SCL | U2 SCL, R2 pull-up | Output/open-drain | 4.7kΩ pull-up to 3V3 |
| HX711 data | GPIO32 / D32 | HX711_DOUT | U3 DOUT | Input | HX711 serial output |
| HX711 clock | GPIO33 / D33 | HX711_SCK | U3 PD_SCK | Output | Also controls HX711 power-down |
| 3.3V rail | 3V3 | 3V3 | U2 VDD, U3 VSUP/AVDD/DVDD, J1-1 | Power | Load-cell excitation E+ is 3V3 |
| Ground | GND | GND | U2 VSS/R/EP/ADDR, U3 AGND/VFB/XI/RATE, J1-2 | Power | Load-cell excitation E- is GND |
| Load-cell signal + | — | LOADCELL_SIG_P | J1-3 to U3 INA+ | Analog input | Connect load cell S+ here |
| Load-cell signal - | — | LOADCELL_SIG_N | J1-4 to U3 INA- | Analog input | Connect load cell S- here |
platformio.ini:Ini
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 lib_deps = adafruit/Adafruit SHT31 Library@^2.2.2 bogde/HX711@^0.7.5
src/main.cpp:Cpp
#include <Arduino.h> #include <Wire.h> #include <Adafruit_SHT31.h> #include <HX711.h> // Pin definitions from schematic #define I2C_SDA_PIN 21 // U1 D21 -> I2C_SDA -> U2 SDA #define I2C_SCL_PIN 22 // U1 D22 -> I2C_SCL -> U2 SCL #define HX711_DOUT_PIN 32 // U1 D32 -> HX711_DOUT -> U3 DOUT #define HX711_SCK_PIN 33 // U1 D33 -> HX711_SCK -> U3 PD_SCK // Sensor configuration #define SHT31_I2C_ADDR 0x44 // U2 ADDR tied to GND #define READ_INTERVAL_MS 1000 Adafruit_SHT31 sht31 = Adafruit_SHT31(); HX711 scale; unsigned long lastReadMs = 0; // Calibration value: replace after calibration with known weight. // Positive/negative sign depends on load-cell wiring polarity. float hx711CalibrationFactor = 1.0f; long hx711ZeroOffset = 0; void initI2CAndSHT31() { Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN); Wire.setClock(100000); // 100 kHz is conservative for initial bring-up if (!sht31.begin(SHT31_I2C_ADDR)) { Serial.println("ERROR: SHT31 not found at 0x44. Check SDA/SCL, 3V3, and GND."); } else { Serial.println("SHT31 detected at I2C address 0x44."); sht31.heater(false); } } void initHX711() { scale.begin(HX711_DOUT_PIN, HX711_SCK_PIN); Serial.println("Waiting for HX711..."); if (scale.wait_ready_timeout(2000)) { // Use channel A, gain 128 by default in the HX711 library. scale.set_scale(hx711CalibrationFactor); scale.tare(10); hx711ZeroOffset = scale.get_offset(); Serial.print("HX711 ready. Zero offset: "); Serial.println(hx711ZeroOffset); } else { Serial.println("ERROR: HX711 not ready. Check DOUT/SCK, 3V3, GND, and load-cell wiring."); } } void readSHT31(float &temperatureC, float &humidityPct, bool &ok) { temperatureC = sht31.readTemperature(); humidityPct = sht31.readHumidity(); ok = !isnan(temperatureC) && !isnan(humidityPct); } bool readHX711(long &rawValue, float &scaledValue) { if (!scale.wait_ready_timeout(1000)) { return false; } rawValue = scale.read_average(10); scaledValue = scale.get_units(10); return true; } void printSensorReadings() { float temperatureC = NAN; float humidityPct = NAN; bool shtOk = false; readSHT31(temperatureC, humidityPct, shtOk); long hxRaw = 0; float hxScaled = 0.0f; bool hxOk = readHX711(hxRaw, hxScaled); Serial.println("--- Sensor Readings ---"); if (shtOk) { Serial.print("Temperature: "); Serial.print(temperatureC, 2); Serial.println(" °C"); Serial.print("Humidity: "); Serial.print(humidityPct, 2); Serial.println(" %RH"); } else { Serial.println("SHT31 read failed."); } if (hxOk) { Serial.print("HX711 raw: "); Serial.println(hxRaw); Serial.print("HX711 scaled units: "); Serial.println(hxScaled, 3); } else { Serial.println("HX711 read failed or device not ready."); } } void setup() { Serial.begin(115200); delay(500); Serial.println(); Serial.println("ESP32 temperature + load-cell firmware starting..."); initI2CAndSHT31(); initHX711(); Serial.println("Initialization complete."); } void loop() { unsigned long now = millis(); if (now - lastReadMs >= READ_INTERVAL_MS) { lastReadMs = now; printSensorReadings(); } }
scale.tare(10) zero the reading.hx711CalibrationFactor = raw_change / known_units or use the HX711 library calibration examples.hx711CalibrationFactor = 1.0f with the measured value.Bash
pio run pio run -t upload pio device monitor
Platform & Toolchain
Pin Mapping
Dependencies & Project Setup
Complete Firmware Source
HX711 Calibration Procedure
Build & Flash Instructions