I'm asking this because I'm using a timer to generate a 38KHZ signal to drive an IR diode, and I also need to use SoftwareSerial to talk to an HC-12 radio using serial communication.

The code I'm using was written by Nick Gammon and is here:

//Setup Conter/overflow to create 38KHZ drive for IR38KHZ
//38khz, no interrupts
#define IR_CLOCK_RATE 38000L
// toggle on compare, clk/1
TCCR2A = _BV(WGM21) | _BV(COM2A0);
TCCR2B = _BV(CS20);
// 38kHz carrier/timer
pinMode(IR38KHZ, OUTPUT);

I'm not quite up-to-date on the timer use on an Arduino (I'm using a Nano), plus I've no idea what the SoftwareSerial library uses.

1 Answer 1


No. It uses pin-change interrupts to trigger reception, and both reception and transmission use calibrated delay loops. However, interrupts are disabled during both transmission and reception so that the calibrated delay loops remain always the precise length - so if you do anything with any other interrupts they will not work at the same time as SoftwareSerial.

  • 1
    The SoftwareSerial uses almost all cpu time. The AltSoftSerial uses less cpu time, but it does use Timer1 : pjrc.com/teensy/td_libs_AltSoftSerial.html Since you use Timer2, you still have the option to use AltSoftSerial. Even when all three timers are used, it is still possible to add a speaker to your Nano with TimerFreeTone: bitbucket.org/teckel12/arduino-timer-free-tone/wiki/Home
    – Jot
    Feb 23, 2017 at 22:35
  • When I try to link to altsoft serial, I get this:The owner of www.pjrc.com has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website. This site uses HTTP Strict Transport Security (HSTS) to specify that Firefox may only connect to it securely. As a result, it is not possible to add an exception for this certificate.
    – user29356
    Feb 23, 2017 at 22:44
  • I was able to get a copy of the library directly from github......now to try it out.....THANKS.
    – user29356
    Feb 23, 2017 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.