Drone project - 4 motors and radio receiver don't work together


I am prototyping small drone with 4 motors and 1 radio receiver.
I use
Arduino Nano
433 Mhz transceiver/receiver - https://www.amazon.com/gp/product/B017AYH5G0/ref=oh_aui_search_detailpage?ie=UTF8&psc=1
4 motors 8520 https://www.amazon.com/gp/product/B01M7TX4KS/ref=oh_aui_search_detailpage?ie=UTF8&psc=1

Power converter - https://www.amazon.com/gp/product/B06WP64QWY/ref=oh_aui_search_detailpage?ie=UTF8&psc=1 to get 3.7V for motors

I use RadioHead library for radio receiver.
Here is the sketch example I am having problem with:

#include <Arduino.h>
#include <RH_ASK.h>
void setup() {
    pinMode(3, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(9, OUTPUT);
    RH_ASK driver;

void loop() {

    for (int i = 0; i < 360; i++) { //convert 0-360 angle to radian (needed for sin function)
        float rad = DEG_TO_RAD * i; //calculate sin of angle as number between 0 and 255 int
        float sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
        analogWrite(3, sinOut);
        analogWrite(5, sinOut);
        analogWrite(6, sinOut);
        analogWrite(9, sinOut);


When I run this code the device goes to un-responsive state. The motor speed adjustment isn't happening, sinOut parameter isn't being print.
The sketch works either if I comment out

 RH_ASK driver;


        analogWrite(9, sinOut);

It looks like that pin 9 cannot be used by a motor if radio receiver is used. Can it?

Read through your post. Can you find ANYWHERE where you tell us how the radio is connected to the Arduino? I can't.

It looks like that pin 9 cannot be used by a motor if radio receiver is used. Can it?

That depends on whether the radio uses pin 9, or not, and on whether the radio library uses a timer that controls PWM on pin 9, or not.

You didn't tell us how the radio is connected, or provide a link to the library, so we can only conclude that you have some kind of conflict.

The radio receiver is connected in the same way as described here - RF 433MHz Transmitter/Receiver Module With Arduino | Random Nerd Tutorials

The code shows that it uses default constructor for RH_ASK driver. Therefore it uses pin 11 to read messages.

I believe I mentioned the library I used - RadioHead. I was under assumption that this is pretty famous library and I shouldn't provide link to it. Here is it:


I used the version that is published on a PlatformIO - PlatformIO Registry

The documentation for the RH_ASK class shows that it has a public method, handleTimerInterrupts(), that you are not supposed to call. Now, I can't imagine anyone naming a function that, unless the function actually handled timer interrupts. There would be no timer interrupts to handle if the class didn't use a timer.

The UNO only has 3 timers. PWM also uses timers. When some library shanghais a timer, that timer can't be used for PWM, so two PWM pins don't act as you expect.

I am still confused. What does it actually means? I can't use all PWM pins on my nano?

I have four motors and radio receiver. So If there are 3 timers and one is used by RH_ASK I would expect that at least 2 motors would be affected. But sketch works if I disable only one of them.

I am not an expert in Arduino nano, but does it actually mean that I cannot use more than 3 PWM pins simultaneously if board has only 3 timers?

Hi afedorov,

Assuming you're controlling brushless motors using standard PWM Electronic Speed Controllers, you'll need to use timers 1 and 2 to generate the the 490Hz PWM signal using the Arduino analogWrite() function on digital pins 3, 9, 10, and 11.

The pin mapping for the ATMega328P micro-controller used on the Arduino Nano is shown here: https://www.arduino.cc/en/Hacking/PinMapping168.

Timer 1 outputs on the OC1A and OC1B outputs using digital pins 9 and 10, while timer 2 outputs on OC2A and OC2B using digital pins 3 and 11.

I'm not familiar with the RadioHead library, but in the RH_ASK.h header it states that it uses timer 1, but that it's also possible to use timer 2 and if you're prepared to forgo the use of the Arduino timing functions such as delay(), millis(), etc..., timer 0.

In summary this means that unless you're prepared to use timer 0 for your RH_ASK.h library, you might need to consider using an alternative micro-controller board with more timers, or use a different means of radio commication with your flight controller.

no, I use brushed motors with MOFSETs, and yes I use PWM pins.

I updated my device, and use timers 0 and 1 for 4 motors. I use pins 5,6,9,10. Timer 2 is used for radio receiver.

Does this setup mean that I cannot use millis() and delay() functions in my code? Are there options of creating "PWM like" pin from a regular digital pin? Does arduino line has a boards with more timers? I selected Arduino Nano because of its size and of course lack of knowledge and experience.

This discussion on timers covers a lot.

Basically, the Mega uses a chip that has 6 timers.
I bought one of these Mega Pro from Ali Express
I have not used it yet so I cannot vouch for its worthiness.

Hi afedorov,

no, I use brushed motors with MOFSETs, and yes I use PWM pins.

My apologies, I didn't read the link you provided in your initial post.

If you're using brush motors then I presume you're going to need PWM frequencies in the kilohertz range. The Nano can generate PWM in this frequency range, but needs to be configured for fast PWM. This is detailed in ATMega328P datasheet. If you know what PWM frequency you intend to use, I can provide you with some example code.

Does this setup mean that I cannot use millis() and delay() functions in my code?

Arduino set up timer 0 to tick every 4us (microseconds). As timer 0 is an 8-bit timer and 2^8=256, the timer overflows (reaches 255) every 4us * 256 = 1 millisecond. This timing is used to generate millis(), micros() and delay() timing functions.

If you change timer 0's frequency of operation these timing functions will still work, but they won't be measuring milliseconds and microseconds anymore.

Are there options of creating "PWM like" pin from a regular digital pin?

Yes, it's possible to toggle the digitial pins manually. This can be done using a timer and it's interrupt service routine in a similar manner to the servo library. However, the servo library operates at 50Hz and this may not be possible if you need to generate PWM signals in the kilohertz range, as frequent calls to the interrupt service routine might overload the micro-controller.

Does arduino line has a boards with more timers?

The Arduino Micro (ATMega32U4) might suit your application better, as it's similar in size to the Nano but has 4 timers: 0, 1, 3 and 4. Timer 0 is used in the same way as the Nano for the timing functions. Timers 1 and 3 can be used to generate PWM, as they have 4 output channels between them. You'll then need to configure the RH_ASK.h library to work with timer 4.

The Arduino Micro also has the advantage that timers 1 and 3 are both 16-bit, producing higher resolution PWM signals.

There's also the option of using ARM micro-controllers like the SAMD21 on the Arduino MKR ZERO, (based on the Arduino Zero). These have more than enough timers, but are slightly more complex to configure and operate at 3.3V instead of 5V.

Thank you MartinL. I would appreciate help with frequencies.

I don't know frequencies I need.

I have 4 motors - https://www.amazon.com/gp/product/B01M7TX4KS/ref=oh_aui_search_detailpage?ie=UTF8&psc=1. Based on description they should be able to generate 45kRPM. Voltage 3.7V and current is 0.1A.

4 MOSFET transistors - https://www.amazon.com/gp/product/B01GNORMWA/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1

Motor 1 - pin 10 OC1B
Motor 2 - pin 5 OC0B
Motor 3 - pin 6 OC0A
Motor 4 - pin 9 OC1A

After I made RH_ASK use timer2 all motors has started spinning. But! Motor 3 and Motor 4 start first. Motor 1 and Motor 2 start when the value I write to corresponding PWM pins reaches ~80. The drone has total weight of 90g but it is not going in the air.

I don't use LIPO batteries and playing with - https://www.amazon.com/EBL-Battery-Charger-Rechargeable-Batteries/dp/B00HV4KFSA/ref=sr_1_fkmr0_1?ie=UTF8&qid=1525045290&sr=8-1-fkmr0&keywords=EBL+840+9V+Li-ion+Ni-MH+Battery+Charger+with+600mAh+Lithium-ion+Rechargeable+9+Volt+Batteries+(2+Pack).

I use 2 DC-DC step down chips to convert 9V to 3.7V for motors and 5V for arduino nano - https://www.amazon.com/gp/product/B06WP64QWY/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1

So know I am trying to understand.
Is dron not going up because:

  • PWM don't generate high frequency signal to generate required thrust?
  • Battery is not good for the drone and is the reason why it is not moving?
  • Transistors are not appropriate for this project?

Why do motors start at different analog value?


Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

A picture of your project would help also, so we can see your component layout.

Thanks... Tom.. :slight_smile:

Here is png of a circuit and pictures.


Here is a handy image guide for posting images.


Could anybody help here?