import machine
from machine import Pin, PWM
import time
from hx711 import HX711
# Configure the servo motor
servo_pin = 2 # Change this to your servo signal pin
servo = PWM(Pin(servo_pin), freq=50) # Set PWM frequency to 50 Hz
# Configure the HX711 load cell
hx711_dout_pin = 21 # DOUT pin of HX711
hx711_sck_pin = 22 # SCK pin of HX711
hx711 = HX711(dout=Pin(hx711_dout_pin), pd_sck=Pin(hx711_sck_pin))
hx711.set_scale(1) # Set the scale (1kg)
hx711.tare() # Reset the tare weight
# Define the threshold weight (1kg)
threshold_weight = 1000 # In grams
# Function to control the servo
def control_servo(angle):
servo.duty(angle)
# Main loop
while True:
weight = hx711.get_units()
if weight > threshold_weight:
# If weight is above 1kg, close the servo (adjust angle as needed)
control_servo(1024) # Adjust the duty cycle for your servo
else:
# If weight is below 1kg, open the servo (adjust angle as needed)
control_servo(0) # Adjust the duty cycle for your servo
time.sleep(0.1) # Adjust the delay as needed
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
cell1:VCC
cell1:DT
cell1:SCK
cell1:GND
servo1:GND
servo1:V+
servo1:PWM
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r