Pocket Galaxy

by yanazhukanova in Design > Software

21 Views, 0 Favorites, 0 Comments

Pocket Galaxy

design idea.png

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

  1. Arduino Uno
  2. HC-SR04 Ultrasonic Sensor
  3. WS2812B LED Strip (20 LEDs)
  4. Jumper Wires
  5. Breadboard
  6. USB Cable

Software

  1. Arduino IDE
  2. FastLED Library

Circuit / Wiring Diagram

Sizzling Tumelo-Albar.png
Bazaart_B96BE742-2736-4983-9A64-8DEA2E26464D.PNG

Ultrasonic Sensor

  1. VCC → 5V
  2. GND → GND
  3. TRIG → D9
  4. ECHO → D10

WS2812B LED Strip

  1. 5V → 5V
  2. GND → GND
  3. 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

IMG_2039.jpg
IMG_2040.jpg