Send values from a gyroscope to a drone

Hello everyone,

I want to gather values from a MPU6050 gyroscope and send them to my arduino mega2560 , from where if they pass the values defined in the code, send signal to the drone after passing through a low pass filter. For example when i tilt the giroscope forward, the drone moves forward without problem. The issue comes in with other movements.

Here is the code section where i think i should make the changes

analogWrite( pitchPin,     pitch    );//send the values to the low pass filter>drone joystick
analogWrite( rollPin,      roll     );//send the values to the low pass filter>drone joystick

//left movement
  if ((ypr[2] * 180 / M_PI) < -20)
    digitalWrite(rightLed, LOW);//Light a led to signal which way should the drone move
    digitalWrite(leftLed, HIGH);//Light a led to signal which way should the drone move
    roll = 254; // joystick to the left?

//right movement
  if ((ypr[2] * 180 / M_PI) > 20)
    digitalWrite(rightLed, HIGH);//Light a led to signal which way should the drone move
    digitalWrite(leftLed, LOW);//Light a led to signal which way should the drone move
    roll = 0; //Joystick to the right

//no movement left-right (turn off the leds) -
  if (ypr[2] * 180 / M_PI >= -20 && ypr[2] * 180 / M_PI <= 20)
    digitalWrite(rightLed, LOW);//Light a led to signal which way should the drone move
    digitalWrite(leftLed, LOW);//Light a led to signal which way should the drone move
    roll = 255/2; //middle 

//forward movement
  if ((ypr[1] * 180 / M_PI) < -15)
    digitalWrite(backwardsLed, LOW);//Light a led to signal which way should the drone move
    digitalWrite(forwardLed, HIGH);//Light a led to signal which way should the drone move
    pitch = 0; //joystick forward

//backward movement
  if ( (ypr[1] * 180 / M_PI) > 10)
    digitalWrite(backwardsLed, HIGH);//Light a led to signal which way should the drone move
    digitalWrite(forwardLed, LOW);//Light a led to signal which way should the drone move
    pitch = 254; //backwards movement

//no movement forward , nor backwards
  if (ypr[1] * 180 / M_PI >= -15   && ypr[1] * 180 / M_PI <= 10)
    digitalWrite(forwardLed, LOW);//Light a led to signal which way should the drone move
    digitalWrite(backwardsLed, LOW);//Light a led to signal which way should the drone move
    pitch = 255/2;//middle


Here is the flowchart:

Here is the where the roll/pitch wires connect on the drone board after passing through the low pass filter

The joystick is still connected because i tried to de-solder it and place resistors in it's place, but unfortunately the whole thing then stopped working. So, the final question would be how to pass those movements of the gyro to the drone board joystick ?I am a begginer in this field and any help would be greatly apreciated.

Firstly, you claim to be a beginner in this field. I therefor claim you have bitten off quite mouthful there and suggest you take a step back… before you ruin any (more) gear or injure yourself or just get so bogged that you give up on engineering or computers or drone engineering.

I understand what you are trying to do, and it has nothing to do with the aircraft.

Post all your code. I don’t see any low pass filtering. Point that out. If it is in the part you posted, post all your code and point it out. Post all your code.

You may get a sense that it would be key for you to post your entire current effort.

Does your code, with your circuit not connected in any way to the transmitter, run the LEDs correctly?

Does your code, with serial printing statements strategically placed, produce plausible values as you tilt your IMU?

Do you know the difference between an accelerometer and a gyroscope?

Before you started hacking at your “drone board”, by which one can only assume you mean your transmitter, did you bother to measure the voltage at the wiper of each joystick’s potentiometer? As you moved them throughout their physical range?

Are you following any of the many well trod paths on a project like this, or are you thinking you are about to set the world on fire with this “invention”?

Please provide links to those places where you have learned the best about what you are up to, or sites where this has been done if you’ve visited them with good result.

I’m not intending to be mean. TBH this sounds like a ton of fun. Sorry, it’s like you at Disneyland but aren’t tall enough to ride the big roller coaster.




1 Like

Hello Mr. alto777,

First of all i would like to thank you for answering !

The whole project is connected and working almost as it should(LEDs working as intended too), but i have an issue which i think is caused by bad values transmitted to the joystick(i included this section of the code). I decided not to include them in this post because i thought it would not help much in solving my issue.


An accelerometer is a device that helps us find non-gravitational acceleration and a gyroscope is a device that uses gravity to find orientation?

I only measured the resistance. On the forwards- backwards end i measured 4.8KOhm and on the left-right end of the joystick i had 5.1KOhm.

There aren't many paths i could follow and also i don't expect to set anything on fire with this project. Basically all i am trying to do is move a drone based on the gyroscope orientation. That's all.

Here are a few projects i followed in the meantime :

Thank you anticipated!

OK, good. Please post all your code.

Sorry, I assumed (!) you were talking about a software low pass filter. Rereading, I see clearly from your initial post that you are using an R/C type low pass filter on the analogWrite lines.

Please post a diagram of your circuit.

You are making a number of assumptions essential to getting this to function; fortunately most of them are warranted.

Please provide a make and model of your transmitter!

Separate the transmitter from your circuit in the easiest way you can, and carefully measure the voltages at the wipers of the four joystick potentiometers. With respect to the ground or B- (battery minus side) of the circuitry in the transmitter. Edit: noting the voltage at the extremes of the stick motions, if that wasn’t obvious.


Both of those are incorrect - you need to do a bit more reading about them.

By which you might mean a crap-ton. :wink:


1 Like

Sorry for the late reply.

Let me know if this diagram is what you need

The model of the transmitter is JR-NH010T5, it is used with Eachine E010 drone.

Measured the joystick at the 2 wipers and i have received the following voltages:

Ox axis
-min value on 0 is when the joystick is on the left position
-when the joystick is untouched the miltimeter shows a value of 1.72
-max value is 3.48 when the joystick is on the right position

Oy axis
-min value which is 0, is when the joystick is moved forward
-when the joystick is in default position value is 1.75
-when the joystick is pushed backwards value is 3.5

I attached it since it was too big for the code tags and also i have posted a few pictures of the unconnected transmitter.

sketch_may09a.ino (10.4 KB)

Thank you anticipated and sorry for the late reply.

It's almost nap time for me. But

  1. Please briefly explain the role of the HC-05 device in your concept.

  2. What values are the resistors and capacitors in you low pass filter?

  3. Is it your hope to be able to use both the joysticks and the values coming from the IMU through the Arduino at the same time?

  4. In "WhatsApp Image 2021-05-12 at 21.14.48(1) · 900×1600 146 KB" it appears that you have placed resistors between what were once the top and bottom of the (removed) joy pots. What values are those and why did you do that?

  5. What is the power supply voltage for the transmitter board, both the original batteries and, if so, any other way you are providing its power?

No worries. It's your party, we here.


The Hc05 will receive attention level from an external sensor, which if higher than a certain value, will power up the drone throttle(white wire). This is working just fine, the problem comes at the other joystick.

The resistors are 220 Ohm and capacitors are 100microfarads each (Chosen based on the tutorial projects i sent you in the beginning.

I only want the "IMU"(mpu gyro) to handle the movements the right joystick would(the one that's still soldered on the board)

Before i soldered those resistors in place, i measured the resistance of the joy i removed and soldered 1 x 4.8k Ohm and 1 x 5.1k Ohm resistors.(that's the joy that controlls the throttle). Why did i do that? i saw this in a tutorial, i am still at a very beginner level when it comes to electronics, i am doing my best to learn.

The transmitter was originally powered by 2 AA batteries therefore, i am powering it up now with the arduino 3.3v power supply pin.

Thank you for taking time to help me!

You will have to remove that joystick.

Then feed your filtered values, through a resistor, to the point where the wipers of the respective potentiometers went.

The analogWrite values should be mapped and constrained to fall between 0 and 3.3 (nominal) which for some reason looks like it is actually 3.5. The important point is it not exceed the supply voltage to the transmitter board.

The value of the resistor must be selected so as to not load your filter output capacitors, yet not interfere with getting the signal into the microprocessor on the transmitter board.

As a WAG, I would try 100K. But someone else will know better.

As I said before, this is going out on somewhat of a limb (assumptions) but I'm fairly confident it might work. (warranted assumptions).

The risk is damaging the transmitter board; you may already have done. You report that removing the joystick before made everything fail - did you recover regular operation when you re-installed it?


As an alternative to removing the joystick, you could find and sever the PCB connections between the joysticks and the microprocessor, and feed your signals in at that point. On the microprocessor side of the gap, obvsly.

It would make taking a step back easier, at least.

Just depends on what kind of fun you want to have…


I removed the joystick measured the resistance and placed resistors in it's place which made the whole board not power on. When I soldered it back on the board, everything worked as intended.

Funny thing is that in the current state, on forward backward movement it works, it does not work on left to right. Also if I move the blocks of code ( first section of code I sent you) that take care of the forward backward movement, before left right section, then it works on left right and stops working on forward backward.

Now let me understand better, in the first post you recommend me to send signal from filter to a resistor and then to the input (signal) of the joystick( after I remove it)? If I remove the joystick, do I still have to solder resistors in it's place? Sorry for the probably dumb question!

I can't explain why your code changes make your results change in the manner you describe.

Remove the joystick. It won't hurt to place fixed resistors where the ends of the potentiometers were, either 4K7 or 5K6, shouldn't matter. I don't think it is necessary, but just in case.

Yes, include the series resistor 100K, try, then 10K.

It may be easier to cut the trace on the PCB as I outlined above, at the very least it is less likely to damage your board than installing and removing the joystick mechanism repeatedly.

If you cut the traces, leaving the joystick in place, it will serve the role of the 4K7 resistors so no need to add them.


Thank you for helping me , the reasoning behind leaving the "cutting the traces" option as a last minute solution is because i don't really know how to do it . Could that be done by unsoldering two legs of the transmitter microprocessor and bending them upwards and then from there solder / pitch roll wires to the bent "legs" ? or how is it done?

NO NO, do not lift any legs.

If the traces are clearly visible and unambiguously the ones you are interested in, you can cut them with a razor knife or use a small drill bit and make a little divot that breaks the path.

With the razor knife, make two parallel cuts all the way across the trace about 0.5 mm agape, then remove the piece in between.

Then, you may have to scrape some green stuff off the r]trace where you want to solder, just scrape carefully until you see enough shiny copper metal.

Tin the exposed copper, tin your wire and set them together, reheat and you done.

Maybe if you have another circuit board that is otherwise useless you could practice that a few times.

Secure any wire you have soldered onto you board in this manner; there is a risk of pulling up the trace through mechanical force.

I use hot glue just to fix such wire in place, there are better solutions the real techs use.


Just to make sure i got it right, can i do it the following way? I will scrape the traces, but instead of soldering wires to the scrapes, can i solder them directly to the microprocessor since the area there is a bit wider and would be easier, would that cause any problems? Please check the pic, thank you!

I understand.

It’s your party, as I say, or perhaps your… funeral.

I don’t see that it would be any easier, except that the microprocessor pins are already tinned.

I very prefer to do it where you have painted the traces red: cut to sever the connection, then scrape off the green stuff on the side still leading to the chip. Tin it and you are good to go.

Soldering at the chip risks damage from heat, and the distinct possibility of causing a solder bridge to adjacent pins, which you def want to avoid.

To get a feel for scraping off the green stuff and tinning, you can practice in the middle of any large copper area, not severing but just revealing the copper. Or better would be a discarded PCB.

I can’t know about your soldering ability, but this is something you will want to be able to and be confidant about.

That said, whatever you think will work best. Soldering at the chip pins will work, just use a fine pointed tip on you soldering iron, tin the wires you are to connect and get in and out of there as deliberately as possible.



1 Like

Hello, i have been practicing on a spare board i have, how does this look to you? is this what you meant?

Well, it probably looks better than the first time I did it. :wink:

  1. the cut looks OK, better to make it end up like a 'V' shape, angling from left and right.

but just be sure there isn't the smallest possibility of a continuous path for electricity. Visually, don't go poking around with your plain-sane continuity meter, ever, on circuits like the transmitter board.

  1. What were you scraping with?

Looks like you were using a common pin or the tip of you knife. Think of it more like planing is in woodworking… set your blade flat across the entire trace and scrape gently only towards the gap you cut previously. It may take several passes, but you will end up with a flat, shiny surface.

Key here is removing all the green stuff and as little copper as possible.

Once the area is free of all green stuff, again a peek with something that lets you see up close (I have a jeweler's loupe for just this kind of thing), you can tin it and you are all set.

From the picture it looks OK, just be sure to get all the green stuff off or the solder won't stick well when you tin the area you have exposed.

I certainly hope this works… as I said, it should do, but until it does we can't know for sure.


Thanks for your answer.

That would be a good ideea, thanks!

I did not understand this phrase, can you say it with different words?

Right side of the cut green that comes from the joy shouldn't be removed, right ?And also, should the cut be made deeper than the copper ?

The problem i must overcome is that the actual trace where i should solder the wires is like half of the size of the one you see in the picture. It's like the trace under the one i scraped in the picture.

I used a standard box cutter like tool.

Thank you very much!