Tuesday, February 16, 2016

Motion Reactive Shake-the-Maze Game




Bring magic to life with an automated, motion reactive shake-the-maze game! Using components from an Arduino starter kit and common materials around the house, this is a customizable game to let you feel like a wizard while learning the ways of servo motors and light sensors.

In this game, wave your hands over the light sensors to control the speed and rotation of the motor and try to get all your marbles (or beads) into the cup. For a multi-player version, have each player choose a color or take turns playing and timing each other. Build interchangeable versions with different themes, multiple stories, add more sensors, etc.

This particular design was inspired and built by re-purposing materials found around the house. Look around for otherwise unused items or visit a local thrift store for quick and inexpensive ways to encase your project. Exercise your design skills and change the components of this project to fit your needs, wishes, and on-hand materials!

Here's a video of the game in action!

 

Materials


Electronics
All electronic materials used for this tutorial can be found in ​this Arduino starter kit.
Motion Detector Stand
  • Clear round vase
  • Small solar path light stand
    Maze and Maze Stand
    • Cardboard box and cardboard sheet (for maze barriers)
    • Plastic bag or saran wrap (maze cover)
    • Beads (or other round objects that can fit through a drinking straw)
    • Plastic cup
    • Straws (two or more)
    • Small, sturdy tuperware lid
    • Four (4) popsicle sticks (or skewers -- to stabilize the base)
    • Optional: Small toy truck with movable bed or other mechanical lever



    Tools

    Note: If you are using stranded wire and a PCB board rather than a breadboard, you'll also need a Soldering Iron.

    Build it! Pt. 1: Electronics!

    1. Connect servo motor leads to Arduino; also recommended to add a switch.
    Connect t-shaped motor arms to servo motor.

    Connect servo motor positive lead (red wire) to Arduino 5V pin, servo negative lead (black wire) to Arduino GND (ground) pin, and the data pin (orange or yellow wire) to Arduino Digital Pin 9.

    If adding a switch, use the switch to interrupt either the servo 5V supply or the data signal.

    2. Connect first photoresistor to Arduino.
    Connect one side of the photoresistor to Arduino 5V. Connect other photoresistor lead to Arduino Analog Pin A0, then to 10 kΩ resistor (in series). Connect other resistor lead to ground.

    3. Connect second photoresistor to Arduino.
    Same procedure as first photoresistor, but connect to Arduino Analog Pin A1.

    4. Write program to read in analog value from photodiodes and use it to adjust the motor speed. ​Here's a sample program for you to use use and/or modify as you wish :)


    In this program, lower light signals increase the rotational speed of the servo motor (aka as it gets darker the motor speed increases) and if there is a change in the light signal for both of the light sensors, the motor jolts.

     

    Build it! Pt. 2: Maze! 

     
    1. Cut hole in top of cardboard box (maze container). 

    2. Design the maze!
    Mark where you want the barriers to go, and decide how difficult or easy you want to make your maze (the one pictured was somewhat difficult).



    Also be sure to allow one side of the box to open and reload the game.






     


    3. Measure width of box, cut out cardboard slats to fit width of box, and cut holes in slats for maze. 

    4. Hot glue slats onto maze container. 

    5. Cut holes for straws at end of maze, attach straws with hot glue. 

    6. Paint maze container! 



    7. Cut plastic bag or Saran wrap and hot glue to top of maze.







     

     

    Build it! Pt. 3: Maze Base!



    There are lots of different ways to build a base for the maze container! Peruse unused objects around the house and challenge yourself to think of, and try, at least three different approaches. Or you can use my design, but that's less fun :)

    1. Cut out cardboard bottom for plastic cup, hot glue onto cup.

    2. Attach maze to top of plastic cup with velcro strips. 

    3. Cut slots in plastic cup for drinking straws. Also may want to cut a "door" in the plastic cup to retrieve your marbles (..or beads).



    4. Remove toy truck lever mechanism and hot glue to bottom of plastic cup. Adhere to tuperware lid via screw(s) or hot glue.
    For a simpler version, hot glue the plastic cup directly onto the servo motor arms.




    5. Hot glue servo motor arms to bottom of tuperware lid.




    6. Screw, or hot glue, popsicle sticks (or skewers) to servo motor mounting sides (the two sides of the servo motor base that stick out).
    This helps stabilize the maze base and provides a more secure connection for the servo motor to the project base.











    7. Paint!

     

     

     

     

     

     

     

    Build it! Pt. 4: Motion Detector Case

    Going for a similar crystal-ball-esque look? Awesome! Use a clear, round vase. There are more more ways to house the photoresistors, let your imagination run wild! If you enclose them completely, use a sufficiently translucent object (dark greens and blues will reduce the signal).

    1. Coat photodiode electrical connections in a thin layer of hot glue (or epoxy, for a super permanent connection).

















    2. Push sensors through stand until both are just barely sticking out the top.
    If the sensors are getting stuck, try adding skewers or toothpicks to help push them through.

    3. Orient the sensors in different directions at the top of the stand. In this version, one faces directly upwards and the other faces horizontally out towards the user.









    Build it! Pt. 5: Project Base & Case

    1. Determine electronic casing materials and base for the maze game and motion detector. Paint and decorate!
    Let loose your creativity and ingenuity! In this design, a tuperware container holds (and hides) the electronics. Since I wanted an opaque, rectangular base, rather than using the tuperware lid, I took part of the case from a discarded printer/scanner and spray painted it copper.

    For the base, use a study material that can withstand the motor movement (avoid materials that flex). Good materials for the base include thick tuperware lids, wood, or metal. Consider available tools as well -- unless you have a drill (or other appropriate power tool), you'll want to use material that can be cut with hand tools.

    2. Determine location for maze base and motion detector stand. Mark with pencil.
    Consider that the maze base will rotate, so double check that it clears the motion detector stand within 360 degrees of rotation.


    3. Measure size of servo motor and cut hole in base (for just the body of the servo motor, keep mounting arms on top of base). Push servo motor body (and wires) through hole, hot glue popsicle sticks to top of base. 







    4. Drill small hole in base for motion detector wires. Place motion detector stand on base, push wires through hole, and hot glue stand to base.








    5. Glue switch onto base in an easily accessible location. 

    6. Adhere base to project case with velcro strips. 











    Finish, Test & Play!


    1. Coat electrical connections in hot glue (or epoxy for a permanent connection, just be sure to test the system before the epoxy..).

    2. Place Arduino and breadboard in project housing and test our your game!
    The Arduino can also be powered with a 9V battery for a transportable game. When you're not using the game, unplug the 9V to avoid draining the battery super quick (or you can add a switch between the 9V battery plug and the Arduino).

    3. Test the system by waving your hands over the motion detector and check that the motor changes speed. 

    4. Adjust any remaining aspects of your game.

    5. Challenge your friends and family to play your personalized, motion controlled game!
    Maybe even let them design their own maze level :)

    Thursday, December 31, 2015

    Sound Reactive EL Wire Costume


    Bring science fiction to life with a personalized light-up outfit! EL wire is a delightfully futuristic-looking luminescent wire that has the added benefit of staying cool, making it ideal for wearable projects. Combining sensors and a microcontroller with EL wire allow for a wide range of feedback and control options.

    This project uses the SparkFun sound detector and the EL Sequencer to flash the EL wire to the rhythm of ambient sound, including music, clapping, and talking.


    Materials

    Electronics



    El Wire comes in a variety of colors, so pick your favorite(s)!

    Costume


    • Article(s) of clothing
    For a Tron-esque look, go for stretchy black material. Yoga pants and other athletic gear work great!
    • Belt
    • Old jacket with large pocket, preferably zippered or otherwise sealable.
    The pocket will house the electronics. If you intend to wear the costume outdoors in potentially wet weather, choose a pocket that is waterproof (i.e. cut a pocket from a waterproof jacket).
    • Piece of packing foam or styrofoam (to insulate the sound detector).

     

    Tools


    Build it! Pt. 1

    CAUTION: Although it is low current, EL wire runs on high voltage AC (100 VAC). There are exposed connections on the EL Sequencer board so BE CAREFUL when handling the board. Always double (and triple) check that the power switch is OFF before touching any part of the board. For final projects, it is recommended to coat all exposed connections in epoxy, hot glue, electrical tape, or other insulating material.

    1. Test EL Sequencer with EL Wire.
    Connect the inverter, battery, and at least one strand of EL wire to the EL Sequencer. (Note that the two black wires of the inverter correspond to the AC side.)
    Be sure that the EL Wire lights up and blinks when you power the EL Sequencer on battery mode.


    2. Solder header pins onto 5V FTDI pinholes on the EL Sequencer and onto the VCC, ground, and A2 input pins.









    3. Solder header pins to the sound detector.







    4. Connect sound detector to EL Sequencer via female-to-female breadboard wires (or solder wire onto header pins).
    Connect the sound detector VCC and ground pins to the VCC and ground pins on the EL Sequencer. Connect the sound detector gate output to the A2 input pin on the EL Sequencer. If you are using the envelope and/or audio output signals, connect these to pins A3 and A4 on the EL Sequencer (more on this in the Program It! section).




    Build it! Pt. 2


    1. Make a protective casing for the sound detector using packing foam or styrofoam to prevent jostling or other physical vibrations (aka collisions) from triggering it.

    Place sound detector on top of foam, outline the board with a pen, and cut out a hole in the foam for the detector to fit snugly inside. Also recommended to epoxy the wires onto the foam (but not the sound detector board).
















    2. Cut out a pocket from the jacket and sew onto the belt.




    3. Put belt on, connect EL Wire to EL Sequencer, and place EL Sequencer in pocket pouch. Determine approximate placement of each EL wire strand based on location of electronics.
















    Build it! Pt. 3 


    1. Mark and/or adhere the base of the EL wire JST connector onto clothing, allowing the full length of the connector to flex. Be sure that the JST connector can easily reach the EL Sequencer.









    2. Starting at the basse of the JST connector, attach EL wire strands to your chosen article of clothing.

    Sew EL wire onto clothing using strong thread or dental floss, or use an appropriate fabric adhesive.
    Prior to adhering the EL wire, it is recommended to use safety pins to determine placement of the EL wire on each article of clothing while you are wearing it. EL wire is flexible but not so stretchy, so give yourself some wiggle room.

    It is also recommended to use separate EL wire strands on different articles of clothing to facilitate the process of taking it on/off.













    Program it!  

    1. Connect EL Sequencer to computer via 5V FTDI BOB or cable. 

    2. Program the EL Sequencer using the Arduino platform; the EL Sequencer runs an ATmega 328p at 8 MHz and 3.3V.

    3. Determine how you want to use the sound detector output(s) to control the EL wire. The sample program below utilizes the gate channel output to turn on the EL wire if there is a sound detected.

    Sample Program:
    // Sound Activated EL Wire Costume<br>// Blink EL Wire to music and other ambient sound.
    //JenFoxBot
    void setup() {
      Serial.begin(9600);  
      // The EL channels are on pins 2 through 9
      // Initialize the pins as outputs
      pinMode(2, OUTPUT);  // channel A  
      pinMode(3, OUTPUT);  // channel B   
      pinMode(4, OUTPUT);  // channel C
      pinMode(5, OUTPUT);  // channel D    
      pinMode(6, OUTPUT);  // channel E
      pinMode(7, OUTPUT);  // channel F
      pinMode(8, OUTPUT);  // channel G
      pinMode(9, OUTPUT);  // channel H
    //Initialize input pins on EL Sequencer
      pinMode(A2, INPUT);
    }
    void loop() 
    {
      int amp = digitalRead(A2);
        
      //If Gate output detects sound, turn EL Wire on
      if(amp == HIGH){
        
        digitalWrite(2, HIGH); //turn EL channel on
        digitalWrite(3, HIGH);
        digitalWrite(4, HIGH);
        delay(100);
      }
      
        digitalWrite(2, LOW); //turn EL channel off
        digitalWrite(3, LOW);
        digitalWrite(4, LOW);
      
    }
     
    This program is just one example of what is possible with the SparkFun sound detector. Depending on your needs, different responses can be achieved by using the "envelope" and "audio" outputs of the sound detector. The EL Sequencer can individually control up to 8 different EL wire strands using the three sound detector output signals, so there are tons of possiblities to customize your sound-activated outfit!

    More information about the sound detector output signals:
    The gate channel output is a digital signal that is high when a sound is detected and low when it is quiet. The envelope channel output traces the amplitude of the sound, and the audio output is the voltage directly from the microphone.



    In the photo provided, the red trace corresponds to the gate signal output, the light green trace corresponds to the envelope signal output, and the dark green trace corresponds to the audio signal output.


    Test, Secure, & Show Off!


    Connect all components to the EL Sequencer (inverter, battery, sound detector) and place in belt pouch. Turn the system on, make some noise (e.g. clapping, snapping, or music) and check that the EL wire flashes when there is a sound.

    If the outfit works as expected, secure all connections by coating them in a (thin) layer of epoxy. Let dry for at least 24 hours. Epoxy is a very permanent adhesive, so if you want to reuse any of the components, try other adhesives like hot glue or electrical tape (less secure, but adjustable and removable).

    You can reduce the overall strain on individual connections by ensuring that wires are securely fastened to the belt and/or pouch approximately one inch (1") from all connections. The goal is to allow the EL wire to flex while keeping electrical connections rigid, as the connections are the most likely point of breakage.

    Wear your one-of-a-kind, high-tech outfit and go show it off to the world!
    Creative Commons License
    This work by Jennifer Fox is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License