Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hackster is hosting Impact Spotlights: Edge AI. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Edge AI. Stream on Thursday!
Austin Allen
Published © MIT

3D Printable Pet Foot Dispenser With Level Sensing

In this project, I built a 3D-printed pet food dispenser with a food level sensor and RGB LED light bar to indicate the fill level.

BeginnerFull instructions provided6 hours174
3D Printable Pet Foot Dispenser With Level Sensing

Things used in this project

Hardware components

LED Light strip
×1
ESP32 Development Board
×1
Single-axis joystick
×1
5VDC Power Supply
×1
Assortment of jumper wires
×1
Hot glue
×1
Black PLA+ 3D Printing Filament
×1
White PLA+ 3D Printing Filament
×1

Hand tools and fabrication machines

FDM 3D printer with sufficiently large build area
Hot Glue Gun

Story

Read more

Custom parts and enclosures

CAD Assembly

Schematics

Wiring Diagram

Code

Arduino Code

Arduino
#include <Adafruit_NeoPixel.h>

#define PIN 32

// Number of LEDs that are connected to the microcontroller
#define NUMPIXELS 18 

// Initialize the NeoPixel library. 
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#define DELAYVAL 500  // Time (in milliseconds) to pause between pixels

// Variables for the joystick
int potPin = 35;
int potValue;
int levelValue;

// Variables for the millis() timing functions
unsigned long startMillis; 
unsigned long currentMillis;
unsigned long previousMillis = 0;  
const unsigned long interval = 1000; 

int ledState = 0;  // ledState used to toggle the LED for flashing

void setup() {
  startMillis = millis();  // Initial start time
  pixels.begin();          // Initialize the NeoPixel strip object
}

void loop() {
  pixels.clear();  // Set all pixel colors to 'off'

  // Gets the current time, reads the joystick positon, and maps the joystick position to 0-18 (number of pixels)
  unsigned long currentMillis = millis();
  potValue = analogRead(potPin);
  levelValue = map(potValue, 745, 0, 0, 18);

  // If the level is above 9, the LED strip is set to green and reflects the posiiton of the joystick level arm. 
  if (levelValue >= 9) {
    for (int i = 0; i <= levelValue; i++) {
      pixels.setPixelColor(i, pixels.Color(0, 255, 0));
      pixels.show();
    }

  // If the value is less than 9 but greater than one, the LEDs are set to yellow and reflect the position of the joystick level arm. 
  } else if (levelValue >= 1) {
    for (int i = 0; i <= levelValue; i++) {
      pixels.setPixelColor(i, pixels.Color(255, 255, 0));
      pixels.show();
    }

  //If the level is less than 1, it will flash the status bar read, indicating a refill is needed)
  } else {
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;

      // If the LED is off, turn it on, and vice-versa:
      if (ledState == 0) {
        ledState = 1;
      } else {
        ledState = 0;
      }
      if (ledState == 1) {
        for (int i = 0; i <= NUMPIXELS; i++) {
          pixels.setPixelColor(i, pixels.Color(255, 0, 0));
        }
      } else {
        for (int i = 0; i <= NUMPIXELS; i++) {
          pixels.setPixelColor(i, pixels.Color(0, 0, 0));
        }
      }

      pixels.show();  // Send the updated pixel colors to the hardware.
    }
  }
}

Credits

Austin Allen
7 projects • 3 followers
I develop novel sports and recreation technologies.
Contact

Comments

Please log in or sign up to comment.