Gyroscope Led Control With Arduino

31,010

63

110

Introduction: Gyroscope Led Control With Arduino

About: I'm an electronics enthusiast, passionate about science, and programming. Building things from scratch makes my day!

In this project i will show you how to build a simple 4 led tilt dimmer with a gyroscope and an arduino uno. There are 4 leds arranged in a "+" shape and they will light up more as you tilt the breadboard.

This won't involve any soldering, just basic breadboard assembly and basic arduino programming.

Step 1: Materials:

1) An Arduino Uno board and a USB cable. You can use a different board if you like but keep in mind that different boards have different pin configs, for example if you use an Arduino Mega the SDA and SCL pins are 20 and 21.

2) 4 leds, the leds should be identical , the color doesn't matter it's up to you :)

3) 4 identical resistors anywhere between 100 ohms and 1 K ohm, i recommend around 200

4) a breadboard

5) dupont wires

6) MPU-6050 gyro

7) U-shape jumper cables (optional). I've used these jumper cables because they look better on the breadboard, and the leds are more visible this way. You can find a box of 140 on ebay at about 4$. If you don't have these cables you can replace them with dupont wires.

Step 2: Assembly

1) Begin by placing the 4 leds on the breadboard in a "+" shape. The long pins of the leds are positive. I've placed the positive pins for the top and bottom leds on the right, and for the left and right leds below (see on the first picture.

2) Insert the four resistors in the breadboard.

3) Place the MPU6050 like in the picture

4) Insert the wires. The leds ground pins will go directly to the ground. The positive pins will go through a resistor into the arduino pins: pin 3 through a resistor to the front led, pin 5 through a resistor to the bottom led, and similar with pin 6 right led, pin 9 left led

The MPU6050 must be connected to ground and 5V+, after that connect SDA to A4 (analog 4), SCL to A5

I've also attached an fritzig schematic, if you want to make sure the connections are correct.

Step 3: The Code

Source code here: https://github.com/danionescu0/arduino/tree/master...

Or copy-paste it from below:

You will need two external libs I2CDev and MPU6050, i've attached them here, and i've posted below the source of the code. I've not written those libs it's not my merit :)

If you don't know how to install a library check this instructable:

Then copy paste or download my library and give it a try.

* I2CDev library source: https://github.com/jrowberg/i2cdevlib

Step 4: Improvements and Different Uses of the Gyro

This is the simplest project i've done with MPU6050, i can think of many derivatives from this idea:

- adding two or more leds for each direction, so the steeper the angel, the more leds will light up

- making a wearable that will warn you with a sound that you don't have a correct upright position

Those ugly conditions i think can be improved with some math (replace if's with some equations).

As a BONUS :) i've made a youtube video with another version of the project, i've added 3 leds for up, e for down, 2 for left and two for right.

If you want to check the video click here. I've also attached a picture of the breadboard above.

For those who are interested the code go here, and replace this line

#define SIMPLE_IMPLEMENTATION true

---------- with -----------

#define SIMPLE_IMPLEMENTATION false

The new led pinout is: front leds: 3,12,11, bottom leds: 5,6,7, left leds: 10, 4, right leds: 6, 9

In my other tutorial i've shown how the gyroscope can be used toflip the display on the computer when the display is physically rotated. The instructable is here.

If you liked the youtube videos, you can get more by subscribing to my channel here

Step 5: A Recent Add-on to This Tutorial, a Neopixel Ring Driven by a Gyroscope

You can find the code here if you're interested about that.

1 Person Made This Project!

Recommendations

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

110 Discussions

0
drspeedphoto
drspeedphoto

Question 6 months ago

hello I wanted to ask you if it was possible to increase the sensitivity of the gy 521 sensor if yes which values ​​should be changed thanks

0
drspeedphoto
drspeedphoto

Question 7 months ago on Introduction

Si può usare con esp32
Mi daresti una mano grazie

0
danionescu
danionescu

Answer 7 months ago

Hello, can you please post in English? Thanks

0
drspeedphoto
drspeedphoto

Reply 7 months ago

good morning I wanted to ask you if it was possible to replace the relays with the led in. more I asked her how it is possible to vary the sensitivity of the 6050 mpu thanks in advance

1
danionescu
danionescu

Reply 7 months ago

Morning

Do you mean you want to replace the led's with relays? sure you can do that, but be sure you use relay board. If you're using just relays varoius components must be added like a resistor, a transitor and a diode but the relay board contains them all.
For your second question the MPU6050 doesn't have variable sensitivity it just reports what it senses, please tell me what are you trying to achieve so i may offer a workaround:)

0
drspeedphoto
drspeedphoto

Reply 7 months ago

I want to use a card with 8 relays I have to create a self-leveling system for campers the gyroscope must manage the relays which in turn will manage the solenoid valves and a hydraulic pump

0
danionescu
danionescu

Reply 7 months ago

That's a very interesting project, but it's substantially more complex that my LED's project. You would have to know each actuator(valve) position how much is it opened and closed, and use some geometry to model the 3 dimensional rectangle.
Also the controll might be through PID (https://www.norwegiancreations.com/2016/08/the-seesaw-part-2-basic-pid-theory-and-arduino-implementation/).
Check out this simpler project: http://www.diva-portal.org/smash/get/diva2:916229/FULLTEXT01.pdf

Well don't have enough knowledge to take this project on my own, but i gave you some hints which might get you started :)

Have fun with the project!

0
drspeedphoto
drspeedphoto

Reply 7 months ago

this is the scheme of operation

image.jpg
0
EmengTV
EmengTV

1 year ago

Is this correct?

received_599764553826411.jpeg
0
danionescu
danionescu

Reply 1 year ago

It's a problem with the instructable editor, i'm sorry. It adds some <br> an <p> tags, please delete the <br> and all will be fine.

0
EmengTV
EmengTV

Reply 1 year ago

Thanks to the respond man!
-------
I follow the instuctions but there are two pinouts in #6 ?
ButtomLed and RightLed
Is that correct?

received_671834729942322.jpeg
0
danionescu
danionescu

Reply 1 year ago

Well, i see your sketch it's different from mine, try to use mine to see if it works i don't know how you modified it:)
Mine looks like this:
const int frontLed = 3;
const int bottomLed = 5;
const int rightLed = 6;
const int leftLed = 9;
Double check with the code i provided in the tutorial

0
EmengTV
EmengTV

Reply 1 year ago

But the instruction you said is this... How about the other pinouts?

received_345314313001292.jpeg
0
danionescu
danionescu

Reply 1 year ago

That's the pins coresponding to the led's. The code you just need to ensure the simple implementation is set to false
#define SIMPLE_IMPLEMENTATION false
If you need to add more then 10 led's you need to modify the sketch substantially

0
EmengTV
EmengTV

Reply 1 year ago

Thanks a lot sir!

0
danionescu
danionescu

Reply 1 year ago

You're wellcome. hope this helps

0
EmengTV
EmengTV

Reply 1 year ago

Sorry sir but.. can you help me again... The

is not declared?

received_343364429698397.jpeg