This circuit integrates an Arduino UNO microcontroller with an HX711 Weighing Sensor Module and an ESP8266 ESP-12E WiFi Module to create a smart weighing system. The system measures the weight of an object using a Load Cell and communicates the data wirelessly via the ESP8266 module. The Arduino UNO is used to process the data from the HX711 module and control the data flow to the ESP8266 for wireless transmission.
#include "HX711.h"
#include <SoftwareSerial.h>
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
// ESP8266 communication pins
const int ESP8266_RX_PIN = 10;
const int ESP8266_TX_PIN = 11;
HX711 scale;
SoftwareSerial esp8266(ESP8266_RX_PIN, ESP8266_TX_PIN); // RX, TX
float initialWeight = 0;
float tareWeight = 0;
bool isTared = false;
bool isInitialWeightRecorded = false;
void setup() {
Serial.begin(9600);
esp8266.begin(115200); // Initialize SoftwareSerial for ESP8266
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// Wait for the scale to stabilize
delay(1000);
// Tare the scale (set the current weight as zero)
if (scale.is_ready()) {
scale.set_scale();
scale.tare();
tareWeight = scale.get_units();
isTared = true;
Serial.println("Scale tared successfully.");
} else {
Serial.println("Error: HX711 not ready for taring.");
}
// Record the initial weight after taring
if (isTared) {
Serial.println("Place the filled container on the load cell...");
delay(5000); // Wait for 5 seconds to place the container
if (scale.is_ready()) {
initialWeight = scale.get_units();
isInitialWeightRecorded = true;
Serial.print("Initial Weight (with water): ");
Serial.println(initialWeight);
} else {
Serial.println("Error: HX711 not ready for initial weight measurement.");
}
}
}
void loop() {
if (isTared && isInitialWeightRecorded) {
if (scale.is_ready()) {
float currentWeight = scale.get_units();
float waterConsumed = initialWeight - currentWeight;
Serial.print("Current Weight: ");
Serial.println(currentWeight);
Serial.print("Water Consumed: ");
Serial.println(waterConsumed);
// Send water consumption data to ESP8266
esp8266.print("Water Consumed: ");
esp8266.println(waterConsumed);
} else {
Serial.println("Error: HX711 not ready for weight measurement.");
}
} else {
Serial.println("Error: Scale not properly initialized.");
}
delay(1000);
}
This code is designed to run on the Arduino UNO and manages the interaction between the HX711 weighing sensor, the load cell, and the ESP8266 WiFi module. It initializes the scale, tares it to zero, records the initial weight, and then continuously measures and transmits the weight data wirelessly.