Simple Infrared PWM on Arduino

We are often asked on discussion boards, about conflicts between IRremote or IRLib and other Arduino Libraries. In this post, we present a sketch for ‘Simple Infrared PWM on Arduino’. This is the first part in a 3 part series of posts. Part 1 shows how to generate the Simple Infrared PWM on Arduino (AKA carrier frequency), using any available IO pin and without conflicting with other libraries. Part 2 will show how to send a RAW infrared signal using this approach and Part 3 will show how to send a common NEC signal from the binary or HEX value.Simple Infrared PWM

Next we consider the example sketch, by section:

Definitions

1
2
3
4
5
6
7
8
9
10
11
#define Duty_Cycle 56 //in percent (10->50), usually 33 or 50
//TIP for true 50% use a value of 56, because of rounding errors
//TIP for true 40% use a value of 48, because of rounding errors
//TIP for true 33% use a value of 40, because of rounding errors
#define Carrier_Frequency 56000 //usually one of 38000, 40000, 36000, 56000, 33000, 30000
#define PERIOD (1000000+Carrier_Frequency/2)/Carrier_Frequency
#define HIGHTIME PERIOD*Duty_Cycle/100
#define LOWTIME PERIOD - HIGHTIME
#define txPinIR 8 //IR carrier output

First we configure the duty cycle for the Infrared carrier. Typically, values of 33% or 50% are used for IR, with 33% being popular in battery-powered systems. You will note our suggestions to use a value of 56 for 50% duty cycle and 40 for 33%, which is an artefact of rounding errors in the ‘#define’ statements. In simple terms set Duty_Cycle to 56 for a 50% duty cycle. Next we define the carrier frequency. Almost all IR systems us a carrier frequency of either 38 kHz, 40 kHz, 36 kHz, 56 kHz, 33 kHz or 30 kHz. In addition, Bang + Olufsen systems use a carrier frequency of 455 kHz. However, this is very rare in use and is outside the scope of this sketch. The PERIOD is a simple calculation based on the defined carrier frequency. Similarly, HIGHTIME and LOWTIME are calculated automatically based on the period and the duty cycle. AS we mentioned before, you can select any Arduino pin for the IR output signal, including all digital and analogue pins.

For more detail: Simple Infrared PWM on Arduino


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top