Pocket Galaxy
Pocket Galaxy is an interactive light installation inspired by the beauty of constellations and the night sky. The project explores the relationship between human presence and celestial light. As viewers approach the installation, stars gradually appear and change color, creating the feeling of carrying a small galaxy within reach.
Supplies
Materials and Tools
Hardware
- Arduino Uno
- HC-SR04 Ultrasonic Sensor
- WS2812B LED Strip (20 LEDs)
- Jumper Wires
- Breadboard
- USB Cable
Software
- Arduino IDE
- FastLED Library
Circuit / Wiring Diagram
Ultrasonic Sensor
- VCC → 5V
- GND → GND
- TRIG → D9
- ECHO → D10
WS2812B LED Strip
- 5V → 5V
- GND → GND
- DIN → D6
All components share a common ground.
Code
#include <FastLED.h>
#define NUM_LEDS 20
#define LED_PIN 6
#define TRIG_PIN 9
#define ECHO_PIN 10
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.begin(9600);
}
int getDistance() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH, 30000);
int distance = duration * 0.034 / 2;
if(distance == 0) distance = 200;
return distance;
}
void loop() {
int distance = getDistance();
Serial.println(distance);
int activeStars;
if(distance > 100) {
activeStars = 4;
}
else if(distance > 70) {
activeStars = 8;
}
else if(distance > 40) {
activeStars = 14;
}
else {
activeStars = 20;
}
FastLED.clear();
for(int i = 0; i < activeStars; i++) {
if(distance > 100) {
leds[i] = CRGB(0, 0, 80); // dark blue
}
else if(distance > 70) {
leds[i] = CRGB(80, 0, 120); // purple
}
else if(distance > 40) {
leds[i] = CRGB(255, 50, 150); // pink
}
else {
leds[i] = CRGB::White; // bright white
}
}
// twinkle effect when very close
if(distance < 40) {
int star = random(NUM_LEDS);
leds[star] = CRGB(
random(180,255),
random(180,255),
255
);
}
FastLED.show();
delay(100);
}
Problems Encountered
LED strip setup and configuration
Distance sensor calibration
Creating smooth color transitions
Final Result