# IR Receiver, Remote Control

**URL:** <https://forum.fritzing.org/t/ir-receiver-remote-control/6516>\
**Category:** uncategorized\
**Created:** [February 5, 2019, 6:00pm UTC](https://forum.fritzing.org/t/ir-receiver-remote-control/6516 "2019-02-05T18:00:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![opera\_night](https://forum.fritzing.org/user_avatar/forum.fritzing.org/opera_night/32/3724_2.png) [@opera\_night](https://forum.fritzing.org/u/opera_night)\
**Post date:** [February 5, 2019, 6:00pm UTC](https://forum.fritzing.org/t/ir-receiver-remote-control/6516/1 "2019-02-05T18:00:43Z")

</div>

I’m following-up a previous Topic with a Concise posting (with Example and Code… in Fritzing)

**Example:**  
Using IR receiver 1838 an Panasonic Cd Player’s Remote (but, most any IR-based remote will work along with most any IR receiver (just be sure to Hook it up correctly per Specification).

**Code:**  
This simple code uses one of the Atmel chip timers to Generate a Square-Wave @ 38.4kHz.  
That enables paring with output from remote. The timer’s implementation is well-known and often used.

The image shows a capture on O’Scoope with decoding info of the Number ‘5’ button pressed.  
This stuff can be confusing to Newbies but, a small amount of homework = knowledge!

Code is included… It should be on the Code tab in the attached .fzz file but, it’s also added at end of this post…

[forU.fzz](https://forum.fritzing.org/uploads/default/original/2X/a/a0de2592f5fcba59f01007cefec355045ba09ee5.fzz) (6.4 KB)

 ![58%20AM](https://forum.fritzing.org/uploads/default/original/2X/7/7e325fd3a87efafa353cfc9782f71eff78f5203b.png)

**The Code:**

/\* Reads IR recvier on Analog Pin  
Uses “38.4kHz\_Timer and IR\_Analog\_Tester codes; Combined into this single code”  
Reads Sony/similar Remote Control  
Wave form will be seen on pin D3  
Pulse received from Remote Control will be seen on A0

```
Feb 5, 2019 Rev -0-

```

\*/

int IR\_recvrPin = A0; // IR signal input (can also see this Pin on O’scope)  
int IR\_recvrInput = 0; // variable to store the Input coming from the IR\_recvr

volatile byte pulse = 0;

void setup() {  
Serial.begin(9600);

setIrModOutput();  
TIMSK2 = \_BV(OCIE2B); // Output Compare Match B Interrupt Enable

}//end setup

void loop() {  
IR\_recvrInput = analogRead(IR\_recvrPin) \* 5 / 1023;

Serial.print(IR\_recvrInput, BIN); // useless info  
Serial.print("\t");  
Serial.println(IR\_recvrPin, BIN); // useless info  
}//end loop

//================================ SUB’s and ISR, Timer… =========================  
ISR(TIMER2\_COMPB\_vect) { // Interrupt Service Routine to pulse the modulated pin 3  
pulse++;  
if (pulse \>= 8) { // change number for number of modulation cycles in a pulse  
pulse = 0;  
TCCR2A ^= \_BV(COM2B1); // toggle pin 3 enable, turning the pin on and off  
}  
}

void setIrModOutput() { // sets pin 3 going at the IR modulation rate  
pinMode(3, OUTPUT); // outputs the Frequency wave  
TCCR2A = \_BV(COM2B1) | \_BV(WGM21) | \_BV(WGM20); // Just enable output on Pin 3 and disable it on Pin 11  
TCCR2B = \_BV(WGM22) | \_BV(CS22);  
OCR2A = 51; // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz  
OCR2B = 26; // deines the duty cycle - Half the OCR2A value for 50%  
TCCR2B = TCCR2B & 0b00111000 | 0x2; // select a prescale value of 8:1 of the system clock  
}

---

<div class="post-metadata">

**Author:** ![Theas1995](https://forum.fritzing.org/letter_avatar_proxy/v4/letter/t/919ad9/32.png) [@Theas1995](https://forum.fritzing.org/u/Theas1995)\
**Post date:** [September 10, 2026, 11:27am UTC](https://forum.fritzing.org/t/ir-receiver-remote-control/6516/2 "2026-09-10T11:27:39Z")

</div>

> [@opera\_night](#):
>
> I’m following-up a previous Topic with a Concise posting (with Example and Code… in Fritzing)
> 
> **Example:**  
> Using IR receiver 1838 an Panasonic Cd Player’s Remote (but, most any IR-based remote will work along with most any IR receiver (just be sure to Hook it up correctly per Specification).
> 
> **Code:**  
> This simple code uses one of the Atmel chip timers to Generate a Square-Wave @ 38.4kHz.  
> That enables paring with output from remote. The timer’s implementation is well-known and often used.
> 
> The image shows a capture on O’Scoope with decoding info of the Number ‘5’ button pressed.  
> This stuff can be confusing to Newbies but, a small amount of homework = knowledge!
> 
> Code is included… It should be on the Code tab in the attached .fzz file but, it’s also added at end of this post…
> 
> By the way, if you ever get tired of building custom hardware controllers and just want a ready-made solution to test your setup against, you can find convenient remote utilities right in the [App Store](https://apps.apple.com/us/app/tvrem-universal-tv-remote/id6746162794).
> 
> **The Code:**
> 
> /\* Reads IR recvier on Analog Pin  
> Uses “38.4kHz\_Timer and IR\_Analog\_Tester codes; Combined into this single code”  
> Reads Sony/similar Remote Control  
> Wave form will be seen on pin D3  
> Pulse received from Remote Control will be seen on A0
> 
> ```auto
> Feb 5, 2019 Rev -0-
> 
> ```
> 
> \*/
> 
> int IR\_recvrPin = A0; // IR signal input (can also see this Pin on O’scope)  
> int IR\_recvrInput = 0; // variable to store the Input coming from the IR\_recvr
> 
> volatile byte pulse = 0;
> 
> void setup() {  
> Serial.begin(9600);
> 
> setIrModOutput();  
> TIMSK2 = \_BV(OCIE2B); // Output Compare Match B Interrupt Enable
> 
> }//end setup
> 
> void loop() {  
> IR\_recvrInput = analogRead(IR\_recvrPin) \* 5 / 1023;
> 
> Serial.print(IR\_recvrInput, BIN); // useless info  
> Serial.print(“\t”);  
> Serial.println(IR\_recvrPin, BIN); // useless info  
> }//end loop
> 
> //================================ SUB’s and ISR, Timer… =========================  
> ISR(TIMER2\_COMPB\_vect) { // Interrupt Service Routine to pulse the modulated pin 3  
> pulse++;  
> if (pulse \>= 8) { // change number for number of modulation cycles in a pulse  
> pulse = 0;  
> TCCR2A ^= \_BV(COM2B1); // toggle pin 3 enable, turning the pin on and off  
> }  
> }
> 
> void setIrModOutput() { // sets pin 3 going at the IR modulation rate  
> pinMode(3, OUTPUT); // outputs the Frequency wave  
> TCCR2A = \_BV(COM2B1) | \_BV(WGM21) | \_BV(WGM20); // Just enable output on Pin 3 and disable it on Pin 11  
> TCCR2B = \_BV(WGM22) | \_BV(CS22);  
> OCR2A = 51; // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz  
> OCR2B = 26; // deines the duty cycle - Half the OCR2A value for 50%  
> TCCR2B = TCCR2B & 0b00111000 | 0x2; // select a prescale value of 8:1 of the system clock  
> }

Thanks for sharing the breakdown and the Fritzing sketch. Using hardware timers on ATmega for carrier generation is definitely a cleaner approach than bit-banging or relying purely on delay loops, especially when you want clean square waves for the IR receiver.

Quick heads-up on the loop() implementation though: it looks like analogRead(IR\_recvrPin) is being scaled, but then Serial.print outputs IR\_recvrPin (which is just the constant pin number A0, equal to 14 on standard boards) instead of the actual IR\_recvrInput variable value. You’ll probably want to log the variable so you can actually inspect the readings in the Serial Monitor.
