wirecraft

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

Mini Map
power
ground
data
signal
analog

Parts

PartRefsQtyEst.
SG90 micro servoServo1$2.40
Tactile push buttonButton1$0.10
SSD1306 OLED display (128×64, I²C)OLED1$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

src/main.cpp
1// Treat Dispenser
2// 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 face
4//
5// Wiring, parts and step-by-step assembly live alongside this file.
6
7#include <Arduino.h>
8#include <Servo.h>
9#include <Wire.h>
10#include <Adafruit_GFX.h>
11#include <Adafruit_SSD1306.h>
12
13#define SERVO_PIN 3
14#define BUTTON_PIN 2
15
16Servo servo;
17bool buttonPressed = false;
18Adafruit_SSD1306 oLED(128, 64, &Wire, -1);
19
20void 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}
31
32void loop() {
33 // --- Read sensors ---
34 buttonPressed = (digitalRead(BUTTON_PIN) == LOW);
35
36 // --- 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 }
43
44 // Refresh the display with live readings
45 oLED.clearDisplay();
46 oLED.setCursor(0, 0);
47 oLED.setCursor(0, 0);
48 oLED.print("Button: "); oLED.println(buttonPressed);
49 oLED.display();
50
51 delay(50);
52}
53
platformio.ini
1; PlatformIO project for Treat Dispenser
2[env:uno]
3platform = atmelavr
4board = uno
5framework = arduino
6monitor_speed = 115200
7lib_deps =
8 arduino-libraries/Servo@^1.2.1
9 adafruit/Adafruit SSD1306@^2.5.10
10 adafruit/Adafruit GFX Library@^1.11.9
11

Assembly

  1. 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. 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. 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. 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. 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. 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. 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. 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.