Self balancing propellers with Arduino Uno

Hi there,

I would like to begin saying that I don’t have that much experience in electronics, I’m learning a lot through the development of this project but I’ve hit a roadblock and feel the need to ask for help.

What I’m trying to achieve?

The proposed idea is to balance two motors with propellers fixed to the same axis (like in a see-saw), using data recollected by an MPU6050 gyro/accelerometer, processed by an Arduino Uno R3 clone to actuate via PWM two N-channel MOSFETs and vary the speed of said motors. Knowing that this type of control needs a PID controller, I first need to make sure that the readings of the MPU6050 are correct and the circuit is free from errors.

I designed a circuit (with my very limited skills) to make this happen, also made a physical prototype and arduino sketch to test it out (see attachments), I’m using a repurposed ATX power supply to feed the motors while the Arduino and MPU6050 rely on power from the USB cable connected to my PC.

So my first goal is to be able to plot the angle readings of the MPU6050 while the motors alternate in a cycle, everything seems fine until…

What problems I have encountered?

When plotting the angle of the sensor while the motors are running I see spikes and noise, most notably right when one of the motors stops and the other starts (see attachments). Also the Arduino freezes and stops sending serial messages and needs to be restarted after a random amount of time.

What clues do I have?

My first suspect is the circuit since is very likely that I’ve made a mistake either in the placement in the schematic of the components or the choosing of those specific components. Other suspect is the interference produced by the DC motors, which are the same used in affordable mini quadcopters. If I disconnect the power supply for the motors and move the axis by hand the Arduino won’t freeze.

Also, moving dupont cables could lead to them being slowly pulled and disconnected from the protoboard, but even when I’m holding them in place by hand the Arduino freezes.

Extra info about the used components

IRLR024N n-channel MOSFET https://www.infineon.com/dgdl/irlr024n.pdf?fileId=5546d462533600a4015356694bf6265b
1N4005 diode https://www.onsemi.com/pub/Collateral/1N4001-D.PDF
CL-0720-12 motors CL-0720-12 coreless motor – Micro Motor Warehouse

Many thanks in advance, any help would be very appreciated :smiley:

forum.ino (2.73 KB)

ssaman:
When plotting the angle of the sensor while the motors are running I see spikes and noise, most notably right when one of the motors stops and the other starts (see attachments).

Of course. No surprise there.

Also the Arduino freezes and stops sending serial messages and needs to be restarted after a random amount of time.

That's a harder one to deal with - interference from the motors is indeed likely to blame. Place those capacitors as close to the motor as possible. Also keep the ground return currents of the motors separate from the Arduino - use a star configuration, connecting all grounds in one and only one point.

It is always best to use separate power supplies for the motors and Arduino. Twisted pairs of wires to the motors will also reduce radiation, and keep sensor wires as far from motor wires as possible.

Don't forget to connect the grounds.