Pets · Arduino Uno
Good Dog Dispenser
A Arduino Uno build with 3 components. Reads: Button. Drives: Servo, OLED. Press the button, the servo swings the hatch open for a moment.
3 parts · 9 connections · 8 steps
Wiring
Parts
| Part | Refs | Qty | Est. |
|---|---|---|---|
| SG90 micro servo | Servo | 1 | $2.40 |
| Tactile push button | Button | 1 | $0.10 |
| SSD1306 OLED display (128×64, I²C) | OLED | 1 | $3.20 |
| Plus: breadboard, jumper wires, USB cable | ≈ $5.70 | ||
Prices are rough hobby-market estimates. Click a part for wiring notes and specs.
Firmware
1// Treat Dispenser2// Generated by Wirecraft for the Arduino Uno (ATmega328P)3// Prompt: A pet treat dispenser where pressing a button makes a servo open a hatch, with a display showing a happy face4//5// Wiring, parts and step-by-step assembly live alongside this file.67#include <Arduino.h>8#include <Servo.h>9#include <Wire.h>10#include <Adafruit_GFX.h>11#include <Adafruit_SSD1306.h>1213#define SERVO_PIN 314#define BUTTON_PIN 21516Servo servo;17bool buttonPressed = false;18Adafruit_SSD1306 oLED(128, 64, &Wire, -1);1920void setup() {21 Serial.begin(115200);22 servo.attach(SERVO_PIN);23 servo.write(0);24 pinMode(BUTTON_PIN, INPUT_PULLUP);25 if (!oLED.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("OLED not found")); }26 oLED.clearDisplay();27 oLED.setTextColor(SSD1306_WHITE);28 oLED.setTextSize(1);29 Serial.println(F("Treat Dispenser ready."));30}3132void loop() {33 // --- Read sensors ---34 buttonPressed = (digitalRead(BUTTON_PIN) == LOW);3536 // --- React ---37 // Press the button, the servo swings the hatch open for a moment.38 if (buttonPressed) {39 servo.write(90);40 } else {41 servo.write(0);42 }4344 // Refresh the display with live readings45 oLED.clearDisplay();46 oLED.setCursor(0, 0);47 oLED.setCursor(0, 0);48 oLED.print("Button: "); oLED.println(buttonPressed);49 oLED.display();5051 delay(50);52}531; PlatformIO project for Treat Dispenser2[env:uno]3platform = atmelavr4board = uno5framework = arduino6monitor_speed = 1152007lib_deps =8 arduino-libraries/Servo@^1.2.19 adafruit/Adafruit SSD1306@^2.5.1010 adafruit/Adafruit GFX Library@^1.11.911Assembly
- 1
Lay out your workbench
Gather the Arduino Uno, a half-size breadboard, and a bundle of male-to-male jumper wires. Keep the parts list open — every component below gets its own spot on the breadboard. Don't plug in USB power until the last wire is placed.
- 2
Seat the board and power rails
Run a red jumper from the Arduino Uno's 3V3 (or 5V for 5 V parts) pin to the breadboard's + rail, and a black jumper from GND to the − rail. Every component's power and ground will tap these rails.
- 3
Wire the Servo
Place the SG90 micro servo on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: SIG → D3. Tip: Servos are power-hungry. For more than one, feed them from a separate 5 V supply and share GND.
- 4
Wire the Button
Place the Tactile push button on the breadboard. Power first: GND → − rail. Then signals: SIG → D2. Tip: Legs on the same side are connected in pairs — wire diagonally opposite corners to be safe.
- 5
Wire the OLED
Place the SSD1306 OLED display (128×64, I²C) on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: SDA → A4, SCL → A5. Tip: If nothing shows up, try I²C address 0x3D — some modules ship with it.
- 6
Double-check before power
Trace every wire against the diagram once more — 9 connections in total. The classic mistakes: swapped power and ground, and off-by-one rows on the breadboard. Thirty seconds of checking saves a component.
- 7
Flash the firmware
Open the exported folder in VS Code with the PlatformIO extension (free), plug in the Arduino Uno over USB, and hit Upload. PlatformIO fetches the libraries listed in platformio.ini automatically. Prefer the Arduino IDE? Copy src/main.cpp into a new sketch and install the same libraries from the Library Manager.
- 8
Bring it to life
Open the Serial Monitor at 115200 baud to watch live readings. Press the button, the servo swings the hatch open for a moment. Adjust the thresholds at the top of the sketch to match your environment.