#define BLYNK_TEMPLATE_ID "TMPL3H5DJkGdo"
#define BLYNK_TEMPLATE_NAME "led int"
#define BLYNK_AUTH_TOKEN "EgNBl8EswSdWpkZ5xqvDGnl7CD3Tzmc3"
#include <WiFiClient.h>
#include <ESP32Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "HX711.h" // Include the HX711 library
#include <BlynkSimpleEsp32.h> // Include the Blynk library
char auth[] ="EgNBl8EswSdWpkZ5xqvDGnl7CD3Tzmc3" ; // Blynk authentication token
char ssid[] = "Wokwi-GUEST"; // Your Wi-Fi network SSID
char pass[] = "";
// Define the pins
const int dtPin = 32; // DT pin of HX711 connected to digital pin 32
const int sckPin = 33; // SCK pin of HX711 connected to digital pin 33
const int servoPin = 18; // PWM pin for servo motor
const int thresholdWeight = 5; // Threshold weight to differentiate cardboard and plastic
Servo conveyorServo;
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column, 2 rows
HX711 scale; // Create an instance of the HX711 library
void setup() {
Serial.begin(115200);
conveyorServo.attach(servoPin);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
conveyorServo.write(90); // Start with the servo in a neutral position
scale.begin(dtPin, sckPin);
Blynk.begin(auth, ssid, pass); // Initialize Blynk
}
void moveToBin1() {
conveyorServo.write(45); // Move the conveyor to bin 1 position
delay(1000); // Wait for 1 second to simulate moving
//conveyorServo.write(90); // Return to neutral position
}
void moveToBin2() {
conveyorServo.write(135); // Move the conveyor to bin 2 position
delay(1000); // Wait for 1 second to simulate moving
//conveyorServo.write(90); // Return to neutral position
}
BLYNK_WRITE(V1) {
int weight = param.asInt(); // Read weight from the load cell
Serial.print("Weight: ");
Serial.println(weight);
lcd.clear(); // Clear the previous display
lcd.setCursor(0, 0); // Set cursor to the first column, first row
if (weight > thresholdWeight) {
// It's cardboard, move to bin 1
lcd.print("Cardboard");
moveToBin1();
} else {
// It's plastic, move to bin 2
lcd.print("Plastic");
moveToBin2();
}
delay(2000);
}
void loop() {
Blynk.run();
}