R2D2 Creation with Codey πŸ€– Ep.3

Published: (June 7, 2026 at 10:13 AM EDT)
10 min read
Source: Dev.to

Source: Dev.to

Episode 3: The Dome Awakens

β€œI Have a Bad Feeling About These Voltage Levels” ⚑

C-3PO enters the workshop carrying a 12-LED NeoPixel ring with the careful reverence of someone handling a thermal detonator.

C-3PO: β€œI want to begin by saying that I have computed no fewer than twenty-three potential failure modes for this particular connection. NeoPixel WS2812B LED rings operate on 5V logic. The Arduino UNO R3 also operates on 5V logic. So far, so excellent. However, should anyone in this workshop be tempted β€” under any circumstances β€” to use an ESP32 instead, which operates on 3.3V logic, I must warn them in the strongest possible terms that—”

R2-D2 beeps the equivalent of β€œget on with it.”

C-3PO: β€œYes, well. Codey’s voltage safety check will handle that conversation. Shall we begin?”

πŸ—‚οΈ SIPOC β€” The Dome Light System

Suppliers Inputs Process Outputs Customers

You (the maker) β€œAdd a 12-LED NeoPixel ring to pin 6 for R2-D2 dome lights” Codey picks Adafruit_NeoPixel library, generates light animation code Complete .ino + .h header file for animation patterns Arduino UNO R3 β€” which drives all 12 RGB LEDs

Codey Voltage Safety Check NeoPixel ring (5V) + Arduino UNO (5V) Cross-references board voltage vs component logic requirements Green light: compatible β€” or warning with level shifter advice You β€” who avoid magic smoke

NeoPixel Ring (12 LEDs) 5V power + PWM data signal from Pin 6 WS2812B protocol drives each RGB LED individually 12 independently addressable full-color LEDs R2-D2’s dome β€” which lights up with personality

Cloud Compiler Multi-file project: r2d2-dome.ino + animations.h Compiles with Adafruit_NeoPixel pre-installed on Codey servers Firmware ready for upload Arduino UNO β€” via Web Serial

The Components πŸ”§

Luke examines the new parts laid out on the bench.

LUKE: β€œThese are beautiful. The blue and white… it’s exactly right. Like the dome in the movies.”

Component Quantity Notes

Arduino UNO R3 1 From Episode 1

NeoPixel ring (12 LED, WS2812B) 1 5V input β€” white text on back means 5V variant

470Ξ© resistor 1 Data line protection β€” prevents signal ringing

100Β΅F capacitor (electrolytic) 1 Power supply decoupling β€” across 5V and GND

Jumper wires 4

USB cable 1

LUKE: β€œWhy the capacitor?”

Yoda materialises near the component drawer.

YODA: β€œSudden power demand, NeoPixels have when they first turn on. Smooth that spike, the capacitor does. Without it, reset your Arduino might β€” mid-animation.”

LUKE: β€œI had no idea—”

YODA: β€œMuch to learn, you still have. But learn quickly with Codey, you will.”

Codey Prompt: Describing the Dome πŸŽ™οΈ

Open your Codey project. In Plan mode first (to review the plan), then Agent mode to build it:

Plan mode first, then agent:

I'm building R2-D2's dome light system.
Add a 12-LED NeoPixel ring (WS2812B) connected to digital pin 6
with a 470 ohm resistor on the data line.
Add a 100uF capacitor across the power pins for stability.

Create these light animations:
  1. "idle" β€” gentle blue-white breathing pattern, slow
  2. "alert" β€” fast red sweep around the ring, 3 times
  3. "happy" β€” rainbow sweep, then blue-white sparkle
  4. "scan" β€” single blue LED orbiting the ring slowly

Cycle through idle β†’ scan β†’ idle β†’ happy β†’ idle β†’ alert.
Use non-blocking millis() timing throughout.
Split the animations into a separate animations.h file.
Keep the main .ino clean and readable.
Enter fullscreen mode


Exit fullscreen mode

Plan Mode Preview

Codey shows the plan before writing:

Plan for R2-D2 Dome Light System:

1. Main file (r2d2-dome.ino):
   - Include Adafruit_NeoPixel.h and animations.h
   - Setup: initialise ring, set brightness
   - Loop: call state machine from animations.h

2. animations.h:
   - Define RING_PIN = 6, NUMPIXELS = 12
   - Adafruit_NeoPixel ring object
   - State enum: IDLE, ALERT, HAPPY, SCAN
   - Functions: animateIdle(), animateAlert(),
     animateHappy(), animateScan()
   - Timing via millis() β€” non-blocking

3. Wiring diagram:
   - Pin 6 β†’ 470Ξ© β†’ NeoPixel DIN
   - 5V β†’ Cap+ and NeoPixel 5V
   - GND β†’ Capβˆ’ and NeoPixel GND

Proceed with Agent mode to write the code?
Enter fullscreen mode


Exit fullscreen mode

C-3PO reads the plan with visible relief.

C-3PO: β€œA plan! Before the code! How wonderfully methodical. I approve of this approach entirely.”

Click Proceed β€” Codey switches to Agent mode and writes.

The Generated Code: r2d2-dome.ino

// r2d2-dome.ino
// R2-D2 Dome Light System β€” Main File
// Board: Arduino UNO R3
// NeoPixel ring (WS2812B, 12 LEDs) on pin 6

#include 
#include "animations.h"

void setup() {
  Serial.begin(9600);
  initAnimations();
  Serial.println("R2-D2 dome lights online!");
}

void loop() {
  updateAnimations();
}
Enter fullscreen mode


Exit fullscreen mode

The Generated Header: animations.h

// animations.h
// R2-D2 Dome Light Animations
// NeoPixel ring (WS2812B, 12 LEDs) on pin 6

#pragma once
#include 

#define RING_PIN    6
#define NUMPIXELS   12
#define BRIGHTNESS  80   // 0-255 β€” keep under 100 for USB power

Adafruit_NeoPixel ring(NUMPIXELS, RING_PIN, NEO_GRB + NEO_KHZ800);

enum DomeState { IDLE, SCAN, HAPPY, ALERT };

DomeState currentState = IDLE;
unsigned long stateStartMs = 0;
unsigned long lastUpdateMs = 0;

// ── State durations (ms) ────────────────────────────────────────
const unsigned long IDLE_DURATION  = 5000;
const unsigned long SCAN_DURATION  = 4000;
const unsigned long HAPPY_DURATION = 3500;
const unsigned long ALERT_DURATION = 2500;

// ── Dome state machine order ────────────────────────────────────
DomeState stateOrder[] = {IDLE, SCAN, IDLE, HAPPY, IDLE, ALERT};
int stateIndex  = 0;
const int NUM_STATES = 6;

// ── Animation helpers ───────────────────────────────────────────
float breatheValue = 0.0f;
float breatheDir   = 0.02f;
int   scanPos      = 0;
int   alertSweep   = 0;
int   alertCount   = 0;
int   rainbowStep  = 0;

uint32_t blue(uint8_t brightness) {
  return ring.Color(0, 0, brightness);
}
uint32_t white(uint8_t brightness) {
  return ring.Color(brightness, brightness, brightness);
}
uint32_t blueWhite(int pos, uint8_t br) {
  return (pos % 3 == 0) ? white(br) : blue(br);
}

// ── IDLE: gentle blue-white breathing ───────────────────────────
void animateIdle() {
  unsigned long now = millis();
  if (now - lastUpdateMs = 1.0f || breatheValue = NUMPIXELS) {
    alertSweep = 0;
    alertCount++;
  }
}

// ── State machine ────────────────────────────────────────────────
void initAnimations() {
  ring.begin();
  ring.setBrightness(BRIGHTNESS);
  ring.clear();
  ring.show();
  stateStartMs = millis();
}

void updateAnimations() {
  unsigned long now      = millis();
  unsigned long stateDur = 0;

  switch (currentState) {
    case IDLE:  animateIdle();  stateDur = IDLE_DURATION;  break;
    case SCAN:  animateScan();  stateDur = SCAN_DURATION;  break;
    case HAPPY: animateHappy(); stateDur = HAPPY_DURATION; break;
    case ALERT: animateAlert(); stateDur = ALERT_DURATION; break;
  }

  if (now - stateStartMs >= stateDur) {
    stateIndex   = (stateIndex + 1) % NUM_STATES;
    currentState = stateOrder[stateIndex];
    stateStartMs = now;
    alertSweep   = 0;
    alertCount   = 0;
    rainbowStep  = 0;
    scanPos      = 0;
    Serial.print("State β†’ ");
    Serial.println(currentState);
  }
}
Enter fullscreen mode


Exit fullscreen mode

The Voltage Safety Check β€” Codey Saves the Day ⚑

Suddenly, a second prompt flashes on screen.

C-3PO: β€œOh! There it is! Codey’s voltage safety check! I told everyone this moment would come!”

When you type the same prompt but specify ESP32 instead of Arduino UNO, Codey adds a critical warning:

⚑ VOLTAGE SAFETY WARNING

Component: NeoPixel ring WS2812B
Logic level required: 5V data signal
Board selected: ESP32 DevKit V1 (3.3V logic)

ISSUE: The WS2812B data input requires a HIGH signal of at least
3.5V. ESP32 GPIO outputs only 3.3V, which may be unreliable or
cause flickering, colour errors, or complete failure.

RECOMMENDATION: Add a 74AHCT125 level shifter between ESP32
GPIO pin and the NeoPixel DIN pin.
OR: Use a 3.3V-compatible LED strip (SK6812 at 3.3V mode).
OR: Add a pullup via 10kΞ© resistor to 5V on the data line.

The code below uses the level shifter approach.
Shall I update the wiring diagram?
Enter fullscreen mode


Exit fullscreen mode

C-3PO: β€œYou see! THREE THOUSAND SEVEN HUNDRED AND TWENTY TO ONE were my odds and Codey β€” Codey caught it! Without the level shifter, R2-D2’s dome lights would flicker erratically. Or not work at all. I have said it before: voltage compatibility is the cornerstone of reliable hardware.”

R2-D2 emits a long, approving whistle.

C-3PO: β€œYes. Quite.”

The Wiring Diagram β€” The Dome Blueprint 🧭

Click Wiring Diagram. Codey draws:

R2-D2 Dome Lights β€” Wiring Diagram (Arduino UNO R3)
═══════════════════════════════════════════════════════════

[Arduino UNO R3]
  5V   ──────────┬──── (100Β΅F Cap +) ──── GND
                 └──── [NeoPixel Ring: 5V/PWR]
  GND  ──────────┬──── (100Β΅F Cap βˆ’)
                 └──── [NeoPixel Ring: GND]
  Pin 6 ──── (470Ξ©) ── [NeoPixel Ring: DIN/DATA IN]

Color code:
  RED    = 5V power
  BLACK  = GND
  GREEN  = Data signal (Pin 6)
  GREY   = Through 470Ξ© resistor
  BROWN  = Capacitor leads

Connection Table:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ From                β”‚ To                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Arduino 5V          β”‚ NeoPixel Ring: 5V (PWR)          β”‚
β”‚ Arduino 5V          β”‚ 100Β΅F Capacitor: + (long leg)    β”‚
β”‚ Arduino GND         β”‚ NeoPixel Ring: GND               β”‚
β”‚ Arduino GND         β”‚ 100Β΅F Capacitor: βˆ’ (short leg)   β”‚
β”‚ Arduino Pin 6       β”‚ Resistor leg 1 (470Ξ©)            β”‚
β”‚ Resistor leg 2      β”‚ NeoPixel Ring: DIN               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⚑ Notes:
  - Arduino UNO is 5V logic β€” compatible with WS2812B
  - 100Β΅F cap prevents power surge on LED startup
  - 470Ξ© resistor prevents signal overshoot
  - If using ESP32: add 74AHCT125 level shifter on data line
Enter fullscreen mode


Exit fullscreen mode

LUKE: β€œPrint that. Actually β€” download the PDF and print it. I want this on the wall.”

Click Download PDF. The wiring diagram is saved for your build log.

Multi-File Projects: Real Code for Real Droids πŸ“

Han Solo examines the two-tab project with a raised eyebrow.

HAN: β€œTwo files. A main and a header. That’s how real firmware is structured. Not everything crammed into one endless sketch.”

Codey’s Multi-file Projects feature gave us:

r2d2-dome.ino β€” clean, readable main file (12 lines!)

animations.h β€” all animation logic in one focused place

Click between the tabs in Codey’s editor. Both files have syntax highlighting and linting. When you compile, Codey knows they belong together and sends both to the cloud compiler.

HAN: β€œWhen we add the sensor system and the motor system in later episodes, each gets its own file. R2 stays clean. No 500-line monster sketch.”

Compile, Upload, and Watch the Dome Glow πŸš€

Click Compile:

βœ“ Compilation successful
  Board:   Arduino UNO R3
  Sketch:  r2d2-dome.ino + animations.h
  Library: Adafruit NeoPixel (pre-installed)
  Size:    6,842 bytes (21% of flash)
Enter fullscreen mode


Exit fullscreen mode

Click Upload.

The ring comes to life. Blue-white breathing. Slow. Like R2-D2 resting.

Then the scan β€” a single blue LED orbiting the ring.

Then the happiness sequence β€” rainbow wash, then back to blue-white.

Then the alert β€” red sweeping urgently.

LUKE: β€œIt’s… it’s his dome. It looks exactly like his dome.”

R2-D2 β€” the actual one β€” beeps from the corner. The sound is quiet, reverent. Even he seems moved.

Save Your Milestone 🚩

Name this milestone:

Milestone: "R2-D2 Dome Lights β€” Episode 3 Complete"
Enter fullscreen mode


Exit fullscreen mode

Codey saves the code, headers, and chat history.

What’s Next: The All-Seeing Eye πŸ‘οΈ

Yoda sits quietly for a moment.

YODA: β€œA droid that glows and beeps, you have built. But see, R2-D2 can. Obstacles he detects. Danger he senses. In Episode 4 β€” the sensor eye we add. HC-SR04, PIR sensor, reactive behavior. And the Auto Error Fixing feature… needed it will be.”

R2-D2 beeps something urgent.

YODA: β€œYes, Artoo. Ahead, Episode 4 is. Patient you must be.”

πŸ”— Resources

Adafruit NeoPixel library: github.com/adafruit/Adafruit_NeoPixel

WS2812B datasheet: Search β€œWS2812B datasheet”

Codey Online: codey.online

πŸ€– R2D2 Creation with Codey β€” building the galaxy’s greatest droid, one episode at a time. May the Force β€” and the cloud compiler β€” be with you.

0 views
Back to Blog

Related posts

Read more Β»

I'm so tired to code. Not even Vibe Coding... D:

!FrancisTRᴅᴇᴠ っ◔◑◔っhttps://media2.dev.to/dynamic/image/width=50,height=50,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fupl...