My project is to build a quadcopter from scratch using Two Arduino’s. One Arduino will the receiver (attached code below as “Transmitter”) while the other Arduino is the receiver on board the Quadcopter (code is named as “Receiver”).
The main goal for this project is simply for entertainment purposes and currently all i want the quadcopter to do is to hover.
I feel that my transmitter code is sufficient (though this may be terribly wrong), but please take a look at that to see if there is any “newb” mistakes.
My main problem (that i think) is with the receiver code.
I am not sure what is the problem because my quadcopter will not stabilize at all.
The second i try and hit the corresponding throttle value for the motors to lift off the ground, the quadcopter flips over in a spectacular (scary) fashion.
The idea behind the Transmitter code is:
1 - Read analog values from two sources:
1a - An analog stick with X and Y readings, for Roll and Pitch
2a - Potentiometer that is for the Throttle
2 - Send the data is 3 packets:
1b - Packet 1 = Throttle
2b - Packet 2 = Roll
3b - Packet 3 = Pitch
and that is it for the Transmitter.
The Receiver on the other hand is:
1 - Read Yaw Pitch and Roll angles from MPU6050. (named “getPosition” in Receiver Code)
2 - Listen to for Radio
3 - Receive Packets for Throttle, Yaw, and Pitch
4 - Send corresponding values to motors (using the Servo library)
5 - Check orientation (compare current angle to Datum angle, which is set to zero for no Roll / Pitch)
6 - Perform Stabilization code(named “getStability” towards bottom of Receiver code)
- Which uses the PID library in it
- Input is the Current Angle
- Setpoint is the Datum angles, (which is set to zero degrees)
- Output is what will be subtracted/added to the value being sent to motors.
And that is all for the Receiver.
I think my code is doing too much at a time and is not reacting fast enough to when the quadcopter changes angles and overcompensates/undercompensates. (maybe not, but this is what i think and i have no idea right now how to fix that.)
Please let me know if i need to elaborate on anything in this post.
Transmitter.ino (1.14 KB)
Receiver.ino (24 KB)