Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino and ESP32 IoT Cat Feeder with Load Cell Monitoring

Image of Arduino and ESP32 IoT Cat Feeder with Load Cell Monitoring

Circuit Documentation

Summary

This circuit is designed to control a cat feeder system based on IoT (Internet of Things) principles. The core of the system is an Arduino UNO microcontroller, which interfaces with an ESP32 module for IoT connectivity, a servo motor to dispense food, and a load cell connected through an HX711 bridge sensor interface to measure the amount of food dispensed. The Arduino UNO controls the servo based on the weight data from the load cell and communicates this data to the ESP32 for potential remote monitoring or control.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P.
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

ESP32 (30 pin)

  • A powerful microcontroller with integrated Wi-Fi and Bluetooth, suitable for a wide range of IoT applications.
  • It has a rich set of peripherals and is widely used for both hobbyist and commercial IoT projects.

Resistor (200 Ohms)

  • A passive two-terminal electrical component that implements electrical resistance as a circuit element.
  • In this circuit, it is used for interfacing between the Arduino UNO and the ESP32.

Servo

  • An actuator that allows for precise control of angular or linear position, velocity, and acceleration.
  • It is commonly used in radio-controlled devices and is used here to control the dispensing mechanism of the cat feeder.

Load Cell - Red/white/black/green

  • A transducer that is used to create an electrical signal whose magnitude is directly proportional to the force being measured.
  • In this circuit, it is used to measure the weight of the cat food dispensed.

HX711 - Bridge Sensor Interface

  • A precision 24-bit analog-to-digital converter (ADC) designed for weigh scales and industrial control applications to interface directly with a bridge sensor.
  • This component is used to read the data from the load cell and communicate it to the Arduino UNO.

Wiring Details

Arduino UNO

  • 3.3V connected to ESP32 3V3 pin.
  • 5V connected to HX711 3.3/3.5V Supply pin and Servo vcc pin.
  • GND connected to ESP32 GND, HX711 GND - GROUND, and Servo gnd.
  • D9 connected to Servo pulse.
  • D3 connected to HX711 SCK - CLOCK (IN).
  • D2 connected to HX711 DATA (OUT).
  • D1 connected to one side of the Resistor.
  • D0 connected to ESP32 TX0.

ESP32 (30 pin)

  • 3V3 connected to Arduino UNO 3.3V.
  • GND connected to Arduino UNO GND.
  • TX0 connected to Arduino UNO D0.
  • RX0 connected to the other side of the Resistor.

Resistor (200 Ohms)

  • One side connected to Arduino UNO D1.
  • The other side connected to ESP32 RX0.

Servo

  • gnd connected to Arduino UNO GND.
  • vcc connected to Arduino UNO 5V.
  • pulse connected to Arduino UNO D9.

Load Cell - Red/white/black/green

  • E+ connected to HX711 E+.
  • A- connected to HX711 A-.
  • E- connected to HX711 E-.
  • A+ connected to HX711 A+.

HX711 - Bridge Sensor Interface

  • 3.3/3.5V Supply connected to Arduino UNO 5V.
  • GND - GROUND connected to Arduino UNO GND.
  • SCK - CLOCK (IN) connected to Arduino UNO D3.
  • DATA (OUT) connected to Arduino UNO D2.
  • E+, A-, E-, A+ connected to corresponding pins on the Load Cell.

Documented Code

/*
 * Cat Feeder based on IoT
 * This Arduino sketch controls a servo motor to dispense food for a cat.
 * It also reads data from a load cell via the HX711 interface to measure
 * the amount of food dispensed. The Arduino communicates with an ESP32
 * for IoT functionality.
 */

#include <Servo.h>
#include <HX711.h>

// Pin definitions
const int servoPin = 9;
const int hx711DataPin = 2;
const int hx711ClockPin = 3;
const int esp32TxPin = 0;
const int esp32RxPin = 1;

// Create servo and HX711 instances
Servo myServo;
HX711 scale;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  Serial1.begin(115200); // Serial1 for ESP32 communication

  // Initialize servo
  myServo.attach(servoPin);
  myServo.write(0); // Initial position

  // Initialize HX711
  scale.begin(hx711DataPin, hx711ClockPin);
  scale.set_scale(); // Set the scale (calibration factor)
  scale.tare(); // Reset the scale to 0

  // Wait for the scale to stabilize
  delay(2000);
}

void loop() {
  // Read weight from load cell
  float weight = scale.get_units(10);
  Serial.print("Weight: ");
  Serial.print(weight);
  Serial.println(" g");

  // Check if weight is below threshold, if so, dispense food
  if (weight < 50) { // Example threshold
    dispenseFood();
  }

  // Send weight data to ESP32
  Serial1.print("Weight: ");
  Serial1.print(weight);
  Serial1.println(" g");

  // Wait before next loop iteration
  delay(1000);
}

void dispenseFood() {
  // Rotate servo to dispense food
  myServo.write(90); // Rotate to 90 degrees
  delay(1000); // Wait for 1 second
  myServo.write(0); // Return to initial position
  delay(1000); // Wait for 1 second
}

This code is responsible for the operation of the cat feeder. It initializes the servo and the HX711 load cell interface, reads the weight of the food, and dispenses food if the weight is below a certain threshold. It also communicates the weight data to the ESP32 for IoT applications.