กลับไปหน้ารวมไฟล์
wireless-pet-treat-dispenser-using-arduino-nano-rp2040-3e5e45-en.md

Project inspiration

One of our friends recently adopted a senior dog called Jelly who suffers from separation anxiety. To help with training him when he needs to be left on his own, they asked us to make a wireless treat dispenser to go with the pet camera they already own. In the video, we demonstrate the principle with the help of Timothy, our rabbit.

Overall design

This treat dispenser is designed to hang from a wall hook and is controlled wirelessly over WiFi, via an app on the user's phone. There are 8 slots for treats, dispensed using a servo. These compartments might be large enough to hold food for a couple of days for smaller pets, such as hamsters or fish, especially with modifications. However, for our purpose, we only wanted to hold a few small dog treats.

YouTube Video

Watch how we built the device and see it in action in our video:

Technical Deep-Dive

This "Treat-Link" system is a sophisticated dual-core IoT solution built upon the Nano RP2040 Connect, integrating high-performance silicon with cloud-native security.

  • Nano RP2040 & NINA-W102 Integration:
    • Silicon Hub: The project utilizes the Raspberry Pi RP2040 microcontroller (dual ARM Cortex-M0+). While one core manages the Wi-Fi stack via the u-blox NINA-W102 module, the second core handles the real-time PWM timing for the dispenser servo.
    • Secure Authentication: The RP2040 Connect features an ATECC608A crypto-element, which stores the unique private keys needed to authenticate with the Arduino Cloud, ensuring secure communication.
  • IoT Cloud Bi-Directional Logic:
    • Variable Synchronization: The firmware utilizes the ArduinoIoTCloud library. When the drop_treat boolean is toggled on the mobile app, a message is published via the MQTT protocol. The RP2040 subscribes to this topic and executes the onDropTreatChange() callback nearly instantaneously.
    • Telemetry Widgets: The system reports state. The treats_left gauge provides real-time feedback on the physical hopper status, reflecting the calculated index of the 8-slot carousel.
  • Servo Mechatronics & Error Recovery:
    • Indexing Algorithm: The dispenser uses 45-degree rotational increments ($360/8$). The servo is driven by a 50Hz PWM signal, where pulse widths ranging from 1000µs to 2000µs map to the exact physical slot locations.
    • Manual Override: To handle mechanical jams, the system includes a "Position Slider" widget. This allows the user to manually "wiggle" the servo across any degree of its travel range to clear stuck treats remotely.

Engineering & Implementation

  • HMI Status Encoding:
    • The onboard RGB LED is mapped to an rgb_light Cloud variable. This serves as a Local Diagnostic HMI, allowing the user to verify Wi-Fi signal strength or connection status at a glance via color-coded pulses (e.g., Green = Connected, Red = Error).
  • Power Rail Stabilization:
    • Servos can generate significant current spikes. The project connects the servo $V_{cc}$ to the Nano’s VIN pin (sourced from USB 5V), ensuring that the sensitive RP2040 logic rail remains isolated from motor noise.
  • Encapsulation & Mount:
    • The 8-slot design is optimized for small-form-factor treats. The case is engineered with a high-torque mechanical advantage, ensuring the micro-servo can overcome the friction of multiple treats resting against the divider walls.

Case construction:

Check out our Instructable for info on how we made the case: https://www.instructables.com/An-IoT-Pet-Treat-Dispenser-Using-the-Arduino-Nano-/

Our design involves a wider variety of manufacturing techniques than many readers will have access to, so we recommend altering the design to fit your experience and equipment.

Arduino wiring:

The circuit in this project is very simple - connect the servo wires as follows:

  • Red = Vin
  • Brown/Black = GND
  • Yellow/White = D9

In our case, we soldered these through to the Arduino via a piece of stripboard.

On your computer:

Create an Arduino IoT Cloud account at https://create.arduino.cc/iot/

Create a new “Thing”.

In the Setup tab:

Create the following 4 Cloud Variables:

  • bool drop_treat - Read & Write - On Change
  • int position - Read & Write - On Change
  • CloudColoredLight rgb_light - Read & Write - On Change
  • int treats_left - Read Only - On Change

Attach the Arduino Nano RP2040. If you haven’t used Arduino IoT Cloud before, you’ll need to follow the instructions to install the Create Agent software.

Set up your WiFi Name & Password.

In the Sketch tab:

Copy the script from https://github.com/ChronovaEngineering/NanoRP2040_Pet_Feeder/blob/main/IoTCloud_Sketch

Paste this into the script editor, replacing any existing code, then click on the tick icon in the top left to verify the script.

In the Dashboards tab:

Create a new dashboard & name it.

Check that you’re in edit mode (top left).

Click the Add button, then “Widgets” and create each of the following widgets, with the associated variable:

  • Push Button: drop_treat
  • Slider: position (Value range: Min = 0, Max = 180)
  • Colored light: rgb_light
  • Gauge: treats_left (Value range: Min = 0, Max = 8)
  • [Optional] Sticky note for instructions

Rearrange the widgets as desired.

In Things -> Pet feeder -> Sketch:

Plug the Arduino Nano RP2040 Connect into your computer USB port and click the Upload button.

Installation:

Hang the treat dispenser in an appropriate location for dropping treats for your pet. Connect the Arduino to a power source using a MicroUSB cable.

On your phone or tablet:

Download the Arduino IoT Remote app & sign in to your account.

Open the Nano Pet Feeder Dashboard and test that each widget is working as expected.

How to use:

Press the "Drop treat" button to dispense a treat.

If a treat gets stuck, you can use the "Servo position" slider to manually rotate the servo.

The RGB light widget can be useful for debugging connection issues. It will change the colour of the LED on the Arduino to match whatever colour you select on the colour picker.

Conclusion

Treat-Link demonstrates the power of modern IoT ecosystems. By combining high-performance Silicon, native cloud security, and reliable mechanical actuation, it provides a professional framework for home automation and pet welfare.


Cloud Connectivity: Strengthening bonds through secure, remote reinforcement.

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "Arduino IoT Cloud"
  - "Arduino IoT Remote (Mobile GUI)"
author: "KiraKiraSoul"
category: "Internet of Things, BT & Wireless"
components:
  - "1x Arduino Nano RP2040 Connect (IoT Hub)"
  - "1x Micro Servo Motor (Actuator)"
  - "1x Custom 8-Slot Rotary Dispenser Chassis"
  - "1x WS2812B RGB LED (Status Indicator)"
  - "1x Micro-USB Power Source"
description: "A high-security, Wi-Fi enabled treat dispenser powered by the Nano RP2040 Connect, featuring real-time telemetry and remote actuation via the Arduino IoT Cloud."
difficulty: "Easy"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX19arr4HDkSYOVdp+h+rdZKWk+4+sv6S1AIVsf4CTtm7OfukZNUL6F5nYCxqURvHLhcIvS9f7AvQ5DtsuqDb4LyvGDu1ynVt6o1gOPPCeTsVnyKW8QYkYRrAOybldYEasgsk4c/PFxkbXA=="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/wireless-pet-treat-dispenser-using-arduino-nano-rp2040-3e5e45_cover.jpg"
lang: "en"
likes: 3
passwordHash: "0b921d5f8b7df5a2c6c290d77525f2f6d3dfe3f6d3c7cd35ed11550fa45b8471"
price: 1499
seoDescription: "Build a Wireless Pet Treat Dispenser with Arduino Nano RP2040. Feed your pets remotely using the Arduino IoT Remote app."
tags:
  - "iot-automation"
  - "rp2040-connect"
  - "nina-wi-fi"
  - "telemetry-dashboard"
  - "servo-mechatronics"
  - "smart-home"
title: "Wireless Pet Treat Dispenser using Arduino Nano RP2040"
tools:
  - "Soldering Iron"
  - "3D Printer (Optional for Chassis)"
videoLinks:
  - "https://www.youtube.com/embed/oYoICSDV7eg"
views: 2447