Magic Staff With LED Strip Effect Which Only the User Knows How to Light Up

by sharonkunne in Circuits > Arduino

194 Views, 0 Favorites, 0 Comments

Magic Staff With LED Strip Effect Which Only the User Knows How to Light Up

IMG_2345.jpg
Staff

This staff only lights up when you know how to use it.


> By only swinging the staff down will give the sound of the buzzer.

> To make the staff light up, you need to both push a secret button and swing the staff down.


This is my first Arduino project I made for a school assignment. We had to use the Arduino Uno.

In the future, I might work on more projects like this and probably use the Arduino Lilypad, which will make it easier to create the casing. I also intend to dedicate more time to designing the enclosure and creating detailed projects, such as those for cosplay purposes.

Supplies

Tools:

  • Soldering iron
  • Hot glue gun
  • Wire stripper (optional)
  • Scissors

Electronics:

  • Arduino Uno
  • WS2812B LED Strip
  • 9V Battery Clip with DC Jack
  • ADXL345 Digital 3-axis Accelerometer Module V2
  • Buzzer
  • Electrical wires

Additional:

  • Some styrofoam board

Staff:

  • Glass/Plastic ball
  • Some casing for the circuit (for example: plastic soap packaging)
  • Decorations (Fake plants, gems, paint, cloth)
  • Branch

Accelerometer

IMG_2196.jpg
circuit.png

We start by building the circuit by only using the buzzer and Accelerometer.

The accelerometer was mounted on some styrofoam board for stability because it and the connections were pretty fragile. Some hot glue also helped mounting the accelerometer in place. The Wires were soldered on and with an additional styrofoam plate secured. (see picture)

Then with some simple code the accelerometer was tested.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified();

void setup() {
Serial.begin(9600);

if(!accel.begin())
  {
   Serial.println("No valid sensor found");
   while(1);
  }
}

void loop() {
sensors_event_t event; 
accel.getEvent(&event);
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("");
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("");
Serial.println("m/s^2 ");
delay(500);
}

With this code the values from the ADXL345 are being printed so we can check that everything is working correctly.


The LED Strip

This step is pretty straight forward. Solder wires to the terminal of the LED strip and connect those to the arduino. When it comes to the code, we're using the adafruit Neopixel library to control it.

The Code

Now we complete our code to essentially boil down to this:

If the ADXL345 reads a value on the axis of the staff beyond a tested value ->

the buzzer makes a noise


if this happens and the button is also pressed ->

the LED strip goes through a lighting effect of flashing random colors (purple hues)


The code is as follows, file is also attached:

//LIBRARIES NEEDED
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <Adafruit_NeoPixel.h>

#define PIN 3
#define BUZZERPIN 5
#define NUMPIXELS 12
#define BUTTONPIN 2

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified();
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


void setup() {
  pixels.begin();
  Serial.begin(9600);

  pinMode(BUTTONPIN, INPUT);
  digitalWrite(BUTTONPIN, HIGH);

//CHECKING IF THE ACCELEROMETER IS CONNECTED CORRECTLY
  if (!accel.begin()) {
    Serial.println("No valid sensor found");
    while (1)
      ;
  } else {
    Serial.println("Sensor connected");
  }
}


void loop() {
  //LEDSTRIP CLEAR
  pixels.clear();

  //READING THE VALUES FROM THE ADXL345
  sensors_event_t event;
  accel.getEvent(&event);

  //PRINTING VALUES OF THE ADXL345
  // Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("");
  // Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("");
  // Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("");
  // Serial.println("m/s^2 ");
  // delay(500);

  //IF ADXL345 DETECTS Y-AXIS MOVEMENT AND BUTTON IS PRESSED ACTIVATE LIGHTNING FUNCTION
  if (event.acceleration.y < -18 && digitalRead(BUTTONPIN)==LOW) {
    Serial.println("Bonk");
    lightning();

  //ELSE IF ONLY THE Y-AXIS MOVEMENT IS DETECTED THE BUZZER MAKES NOISE
  }else if(event.acceleration.y < -18){
    tone(BUZZERPIN, 500, 500);
    delay(100);
    tone(BUZZERPIN,500,500);
  }

  //UPDATE THE LED STRIP
  pixels.show();
}


//LED LIGHTNING FUNCTION
void lightning() {
  int wait = random(50, 100);  // Time to wait before the next lightning in milliseconds

  for (int j = 0; j < 6; j++) {
    int duration = random(50, 300);  // Duration of the lightning effect in milliseconds

    for (int i = 0; i < NUMPIXELS; i++) {
      pixels.setPixelColor(i, pixels.Color(random(255), 0, random(255))); //SET THE COLOR RANDOMLY BETWEEN RED AND BLUE -> END UP WITH PURPLE HUES
    }
    pixels.show();

    delay(duration);  // Wait for the duration of the lightning effect

    for (int i = 0; i < NUMPIXELS; i++) {
      pixels.setPixelColor(i, pixels.Color(0, 0, 0));  // Turn off all pixels
    }
    pixels.show();

    delay(random(50, 200));  // Wait before the next lightning effect
  }

  delay(wait);  // Wait before the next lightning strike
}



Completing and Testing the Circuit

IMG 2200
IMG_2203.jpg

Now we solder some wires to a button and to the buzzer to integrate these as well in our circuit. We can now test our completed circuit partially on breadboard. (as seen in the video)

Making the Housing and Intergrating the Circuit

IMG_2199.jpg
IMG_2201.jpg
IMG 2204 1
IMG_2230.jpg
IMG_2351.jpg
IMG_2352.jpg
IMG_2347.jpg
  1. First we put the LED strip in a ball. I used a garden lamp which I could easily screw off and on the holder. We can use toilet paper or wrapping paper to nicely diffuse the LED lights. This creates a nice bloom effect and prevents the visibility of individual LED dots.
  2. Now we need a casing where we can easily conceal the circuit. I used a large bottle that previously held hand soap for this purpose. I cut the bottom of the bottle to be the same size as the base of the bulb holder. Then, I installed my circuit inside. With use of some hot glue and fidgeting we can attach the components to the inside wall of the water bottle housing. The only thing left to do now is add a 9V battery. I cut open a flap to allow easy access for inserting the battery later on. Finally, I wrapped the bottom of the bottle tightly with tape around my branch. To add some texture to the bottle, I experimented by completely covering it with painter's tape.
  3. Moving on to the crafting part, I painted my found branch with brown acrylic paint. For added detail, I highlighted the texture of the branch using drybrushing techniques.
  4. The key in this step is to hide the large casing around the Arduino. It took some trial and error to figure out the best way to do it. Luckily, I had some artificial plants at home that I could cut into pieces. I used a lot of hot glue to layer and attach them onto the casing, effectively concealing it.
  5. Next, let's add some decorations. I used artificial stones, fake flowers, and a piece of painted old fabric that I wrapped around my branch. Finally, I wrapped the bulb with transparent wrapping paper.
  6. Now we can plug in the battery and the build is complete!