1

I have a very simple circuit with an Elegoo IR receiver module connected to an Arduino UNO. The three wires are connected correctly with the data wire (Y) connected to pin 8. The code works fine, as every time I press button on the remote, the Serial Monitor displays the corresponding button description.

However, I do not understand how Arduino's pin 8 knows which IR button has been pushed. My understanding is that pin 8 can read either 5V or 0V, but to know which of 20+ remote buttons has been pushed it would have to read PWM. But pin 8 does not the PWM icon next to it and yet it works fine. Unless the PWM icon applies only to pin output? Or is there another way I have failed to find info about?

Thanks!

4
  • What do you actually mean by pwm "icon"?
    – Sim Son
    Commented May 12, 2019 at 15:04
  • 1
    @yannism mean that Pin 8 is not a PWM pin, look at a Arduino UNO pin layout.
    – MatsK
    Commented May 12, 2019 at 15:15
  • Serial RX works on one pin too
    – Juraj
    Commented May 12, 2019 at 16:34
  • The PWM icon says that the pin can be used as PWM output. The remote sends a series of pulses (for instance here there is a brief analysis on the NEC protocol - be aware that there exist many more). You will need to decode the pulses lengths to get a code which represent the key. The IRRemote library was done to help in this task (I used it once to control a robot with a remote controller)
    – frarugi87
    Commented May 21, 2019 at 7:27

2 Answers 2

4

You confuse the different technologies here.

  1. PWM is only an output, not an input. So every pin marked with the PWM symbol can OUTPUT a PWM signal. Reading a signal is a totally different task with different hardware involved.

  2. The IR receiver does not output a PWM (meaning Pulse Width Modulation) signal to the Arduino. It ouputs the demodulated IR signal.

So here is what happens: The remote a code, that consists of different periods of "light on" and "light off" (giving pulses of different length, which encode the data from binary format). Since you want to seperate the remotes signal from any other IR signal, that might roam through the air, the remote also modulates the pulses with a special frequency (often this is 38kHz, but might be another frequency around that). This means that every pulse will be chopped into shorter pulses at the specified frequency. This translates to something like: "light on and off with 38kHz for duration x" --> "light off" --> "light on and off with 38kHz for duration y" --> ...

The receiver module senses the IR light comming in and will electronically discard all signals, that don't have the special frequency, and does the demodulation on this. The outputted signal does not have the 38kHz frequency in it anymore. Just the pulses of different length, that encode the data, meaning

The Arduino then reads the length of the pulses (that only consists of sequences of 0V and 5V) and decodes them into a number. This number represents the pressed button.

A proper library for the Arduino can read the different data protocols used in common IR remotes.

1
  • Awesome! So basically my understanding was correct in that the Arduino input pin reads pulses, but I thought it was just another instance of PWM, which is not. Thank you!
    – yannism
    Commented May 12, 2019 at 19:29
1

The remote control emits encoded IR-bursts (each button has its own code) which are transformed into electrical pulses by the sensor (ref. 6. in here: http://eeshop.unl.edu/pdf/VS1838-Infrared-Receiver-datasheet.pdf). On the arduino those pulses are decoded using a proper library. That means pin 8 is not reading any analog or pwm signal, but TTL-logic at 5V.

1
  • Thanks. Will read more on the TTL-logic.
    – yannism
    Commented May 12, 2019 at 19:31

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.