#include <WiFi.h>
#include <HTTPClient.h>
#include <HX711.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1 // Set the OLED reset pin to -1 if not used
Adafruit_SSD1306 display(OLED_RESET);
// Define the SSID and password for your WiFi network
const char* WIFI_SSID = "your_wifi_ssid";
const char* WIFI_PASSWORD = "your_wifi_password";
// Define the URL for the remote server
const char* SERVER_URL = "http://your_server_url.com";
// Define the pins for the HX711 module
const int LOAD_CELL_DOUT_PIN = 32;
const int LOAD_CELL_SCK_PIN = 33;
HX711 loadCell;
void setup() {
Serial.begin(9600);
// Initialize the OLED display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
// Connect to WiFi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi.");
// Initialize the load cell module
loadCell.begin(LOAD_CELL_DOUT_PIN, LOAD_CELL_SCK_PIN);
loadCell.set_scale(2280); // This value is obtained by calibrating the load cell
loadCell.tare(); // Reset the scale to 0
}
void loop() {
// Read the load cell value
float weight = loadCell.get_units();
// Display the load cell value on the OLED display
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.println("Weight: " + String(weight) + " kg");
display.display();
// Send the load cell value to the remote server
HTTPClient http;
String url = String(SERVER_URL) + "?value=" + String(weight);
http.begin(url);
int httpCode = http.GET();
if (httpCode > 0) {
String response = http.getString();
Serial.println("Server response: " + response);
} else {
Serial.println("Error sending data to server.");
}
http.end();
// Delay for 1 second
delay(1000);
}