Maker 101
Published © GPL3+

Pet Feeder Controlled Via WiFi

This project shows how to make a pet feeder controlled via WiFi. You can wirelessly control the pet feeder at any time with an app.

IntermediateFull instructions provided1,415
Pet Feeder Controlled Via WiFi

Story

Read more

Custom parts and enclosures

pet_feeder_whole_wISXhHccwO.stl

pet_feeder_spiral_screw_xL7oSLCBur.stl

pet_feeder_cover_DfkmIMRdyG.stl

Schematics

bom_pet_feeder_esp8266_2022-03-27_4k2mtuhOVY.csv

pet_feeder_app_aia_JAbdbnQZFX.zip

Code

ESP8266_WiFi_PET_FEEDER.ino

Arduino
#include <ESP8266WiFi.h>

#define IN1a 15
#define IN2a 13
#define IN3a 12
#define IN4a 14

int delayTime = 2;

WiFiClient client;
WiFiServer server(80);

const char* ssid = "YOUR_WiFi_NAME";
const char* password = "WiFi_PASSWORD";

String  data = "";

void setup() {
  pinMode(IN1a, OUTPUT);
  pinMode(IN2a, OUTPUT);
  pinMode(IN3a, OUTPUT);
  pinMode(IN4a, OUTPUT);

  Serial.begin(115200);
  connectWiFi();
  server.begin();
}

void loop() {
  client = server.available();
  if (!client) return;
  data = checkClient ();

  if (data == "feed") {
    for (int adim = 0; adim < 200; adim++) {
      Serial.println("FORWARD");
      forwardMotor();
    }
    
    delay(200);
    
    for (int adim = 0; adim < 200; adim++) {
      Serial.println("BACKWARD");
      backwardMotor();
    }
    stopMotor();
  }
}

void connectWiFi()
{
  Serial.println("Connecting to WIFI");
  WiFi.begin(ssid, password);
  while ((!(WiFi.status() == WL_CONNECTED)))
  {
    delay(300);
    Serial.print("..");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("Wemos Local IP is : ");
  Serial.print((WiFi.localIP()));
  Serial.print("");
  Serial.println("");
}

String checkClient (void)
{
  while (!client.available()) delay(1);
  String request = client.readStringUntil('\r');
  request.remove(0, 5);
  request.remove(request.length() - 9, 9);
  return request;
}

void forwardMotor(void) {
  digitalWrite(IN4a, HIGH);
  digitalWrite(IN3a, LOW);
  digitalWrite(IN2a, LOW);
  digitalWrite(IN1a, LOW);
  delay(delayTime);
  digitalWrite(IN4a, LOW);
  digitalWrite(IN3a, HIGH);
  digitalWrite(IN2a, LOW);
  digitalWrite(IN1a, LOW);
  delay(delayTime);
  digitalWrite(IN4a, LOW);
  digitalWrite(IN3a, LOW);
  digitalWrite(IN2a, HIGH);
  digitalWrite(IN1a, LOW);
  delay(delayTime);
  digitalWrite(IN4a, LOW);
  digitalWrite(IN3a, LOW);
  digitalWrite(IN2a, LOW);
  digitalWrite(IN1a, HIGH);
  delay(delayTime);
}

void backwardMotor(void) {
  digitalWrite(IN4a, LOW);
  digitalWrite(IN3a, LOW);
  digitalWrite(IN2a, LOW);
  digitalWrite(IN1a, HIGH);
  delay(delayTime);
  digitalWrite(IN4a, LOW);
  digitalWrite(IN3a, LOW);
  digitalWrite(IN2a, HIGH);
  digitalWrite(IN1a, LOW);
  delay(delayTime);
  digitalWrite(IN4a, LOW);
  digitalWrite(IN3a, HIGH);
  digitalWrite(IN2a, LOW);
  digitalWrite(IN1a, LOW);
  delay(delayTime);
  digitalWrite(IN4a, HIGH);
  digitalWrite(IN3a, LOW);
  digitalWrite(IN2a, LOW);
  digitalWrite(IN1a, LOW);
  delay(delayTime);
}

void stopMotor(void) {
  digitalWrite(IN4a, LOW);
  digitalWrite(IN3a, LOW);
  digitalWrite(IN2a, LOW);
  digitalWrite(IN1a, LOW);
}

Credits

Maker 101

Maker 101

50 projects • 178 followers
Maker 101; Beginner and intermediate level Maker projects!

Comments