This month I have my 18th birthday so I decided to make a gift for myself, then my mind went into a world of crazy thoughts and came up with one of the most crazy project ideas I've ever had or heard of, and it was to control three colors of RGB LED with three axis of a gyroscope, so you can make any color you want just by changing the direction or orientation of cube, and from there the name GyroCube came into existence, we can play games with it like say the name of color and then try to make it, or the hardest one is at one angle all the three colors will turn off, try to find it.
Trust me everyone loves it from kids to elders, because it is never been easier to mix the colors. It is an extremely cool desktop gadget to have, never gets you bored and brings smile to everyone who plays with it, regardless of age.
Lets get started---
Because it is a quite long tutorial, I made a complete video tutorial,I recommend everyone to watch it to at least see how it works.
Ignore my accent please because I was really tired during voice-over.
(https://www.utsource.net/ is an online platform for technicians, Makers, Enthusiasts, Kids to buy electronic components
First you should know how to use soldering iron, download and install softwares and how to read schematics, don't worry if you do not know, you can learn these things in a matter of hours.
- GY-521 MPU6050 Gyroscope
- Arduino, I'm using Arduino Nano because it is tiny and has its own 5V regulator.
- Lithium-Ion battery
- Common Anode RGB LED
- 220 ohm resistor, only one of it.
- 3X NPN Transistor 2N3904 or 2N2222 used as amplifier
- Female headers
- Universal charger this is required for charging the battery, this is a kind of charger where you have and put the battery inside it, see picture for reference.
- Sunmica Sheets I used them for making the box look for them in hardware store
- Glue to stick the sheets together
- Tiny magnets.
Gyroscopes work on the principle of Coriolis acceleration. Imagine that there is a fork like structure, that is in constant back and forth motion. It is held in place using piezo electric crystals. Whenever, you try to tilt this arrangement, the crystals experience a force in the direction of inclination. This is caused as a result of the inertia of the moving fork. The crystals thus produce a current in consensus with the piezo electric effect, and this current is amplified. The values are then refined by the host microcontroller.
The MPU 6050 is a 6 DOF (Degrees of Freedom) or a six axis IMU sensor, which means that it gives six values as output. Three values from the accelerometer and three from the gyroscope. The MPU 6050 is a sensor based on MEMS (Micro Electro Mechanical Systems) technology. Both the accelerometer and the gyroscope is embedded inside a single chip. This chip uses I2C (Inter Integrated Circuit) protocol for communication.
The MPU 6050 communicates with the Arduino through the I2C protocol. The MPU 6050 is connected to Arduino as shown in the following diagram. Here, MPU 6050 module has a 5V pin, then you can connect it to your Arduino’s 5V pin. Else, you will have to connect it to the 3.3V pin. Next, the GND of the Arduino is connected to the GND of the MPU 6050.
- SCL----A5 (Analog 5)
- SDA---A3 (Analog 4)
- INT----D2 (Digital Pin 2)
<iframe frameborder='0' height='448' marginheight='0' marginwidth='0' scrolling='no' src='https://circuits.io/circuits/2897854-the-unnamed-circuit/embed#schematic' width='650'></iframe>
After completing the connections connect Arduino to PC.
IDE is an Integrated Development Environment used to write and upload programs in Arduino, so we need to install this software.
The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board. It runs on Windows, Mac OS X, and Linux. The environment is written in Java and based on Processing and other open-source software.
Download and install the Arduino IDE from this link.
I recommend downloading the latest version because I had compilation errors when using the older version, so if you have the same problem try installing latest one.
A number of libraries come installed with the IDE, but you can also download or create your own.
Download the library from this link extract it and then open it, you will see the folder named Arduino inside the main folder, open it and you will see something as shown in image 2, from here you need to copy two folders named I2Cdev and MPU6050 now paste this in the Arduino library, to find it follow this:
If you installed the IDE then go to your C drive, Program files x86 and then open the folder named arduino and inside it you will se another folder named Libraries, open it and then paste those two folders which we copied.
In this step we will calculate offset values of the sensor, it is simple and important.
Download the calibration Sketch from this link, extract it and you will see a file named MPU6050_Calibration open it. Compile the sketch, and then upload it to Arduino. Open serial monitor and wait till the offset values are being calculated. Offset values for my sensor are shown in image 2. Note the X, Y and Z offset values for Gyroscope only, not for accelerometer.
- Now download the final program for GyroCube from here.
- Open it and then scroll down to the point shown in the image.
- Now here you have to enter your X, Y, and Z offset values for gyroscope.
- After entering the values upload it to Arduino.
We need common anode LED for the project, but it was not available in my area, so I chopped off three LEDs form RGB LED strip, and these LEDs had separate Anode and cathode for each colour, and since we want common anode LED so I soldered there positive ends together, and added headers to separate cathodes.
And finally I soldered them on prefboard, connected all the positive ends together, all the negative terminals of blues together, all the negative terminals of greens together and all the negative terminals of reds together, so finally it will act like one single common anode LED
Below is the schematic for common anode LED.
Connect the things on breadboard according to the schematic below for first test.
Remember that the Gyroscope is not shown in the schematic but it is connected according to Step:2
When you will move the Gyroscope you will see change in colours, to see how watch the video attached in Intro.
Solder everything together on a prefboard,if you want you can even design your own PCB circuit on Autodesk Circuits. Arduino and Gyroscope slides in nicely in female headers. Power the project with battery and make sure that everything is still working.
Nothing is complicated here, just cut the sheets of Sunmica and stick them together with glue, dimensions will depend on your size of battery.
Solder wires on terminals coming out of charger then connect them to battery and plug the charger in switch board, do not worry about polarity, it will be adjusted automatically by the charger.
In future I'll connect Bluetooth module inside it and will adjust brightness of my room just by rotating it clockwise or counter-clockwise, stay tuned for that.