Introduction: Accelerometer Sensor With Arduino
I had an idea for an electronic helmet that would make an excellent Halloween Costume. without going into too much detail it would involve lighting up in different patterns depending on which direction the mask turned, so that when I look up, the helmet lights up, but stays neutral if I don't move.
(1) Arduino Uno and USB connector cord
(1) L3G4200 triple axis gyro (available at MPJA.com, or anywhere these types of modules can be sold)
a hand full of male/female wires
(2+) LED Lights and the appropriate resistors
(1) Breadboard (Miniature size is fine)
Some sort of housing for all the electronics. For this example, I used a hearty cardboard box, but you could use... literally anything that fits.
Step 1: Step One: Wire the Gyro to the Arduino
Ok so there are a few wires that can be attached directly to the Arduino, but there are two parts that need to be connected to the 3.3v port, so we need to use the breadboard for that. Go ahead and attach a red wire from the 3.3v port to the (+) row on the breadboard. Then attach one cord to connect the VCC pin on the Gyro to the (+) on the breadboard. Repeat this step with the SDO pin on the Gyro. now take a Black wire and attach the GND Pin to the (-) row on the breadboard, then attach a wire from the GND Arduino Port to the (-) row on the breadboard. that about does it for power.
Now for the data wires needed to fully run the Gyro. Underneath the GRN on the gyro is the SDA pin, attach that to the A4 port on the Arduino. Below that is the SCL pin, attach that to the A5 port on Arduino. Your Gyro is now fully plugged in.
Step 2: Step 2: Attach LEDs
Ok so for my project, I had two LEDs that light up depending on how the box moves. lets go ahead and hook those up. This is simple, attach the resistor positive lead to the number pin of your pin of choice (I chose 8 and 9 arbitrarily). wire those to the breadboard, then attach an LED and send the negative lead of the LED to (-) on the breadboard. This will grant you the power to light up two different LEDs based on parameters you set witht he Arduino.
Step 3: Coding!
Ok here is where things get fun. and by fun I mean... um. well. you either love it or you don't. either way here we go! You will need to code the Gyro, which I dont know how to do. BUT, the internet does. For my project, I borrowed code provided lovingly by jtbourke in the Arduino forum ( https://forum.arduino.cc/index.php?topic=147351.0 ) you can pretty much copy and paste this and use it as a base for your project. From here, you need to add a few lines of code to suit your purposes. for one, you want to create some global variables, one for each LED you want to light. This sketch already has variables for the X, Y, and Z coordinate. you need to add to it that part of the code, I recommend an IF THEN statement that looks for when your acceleration reaches a certain threshold. this is a lot of trial and error, so go ahead and make yourself a sandwich and put on some lofi hip hop.
Step 4: Assembly and Construction.
Congrats! if you got past the last step that means you are almost done. Now all you have to do is put all the parts in the box. [IMPORTANT] make sure everything stays plugged in accordingly, make sure the gyro is place front and center of the device or you will get improper readings, and make sure that nothing conductive is touching the front of the gyro, as it will short out the device and you will have to reset the Arduino. after that, you are pretty much good to go.
Step 5: YOU DID IT
Nice work. you are done. now enjoy your box that lights up when it moves!