NodeMCU + IR sensor not working as expected

Hey guys.

I've recently started working on a project since I'm taking a "project centric" approach to learning about electronics. The project involves multiple electronic components so I'm making sure that every component works in isolation prior to combining everything. Everything seems to be working as expected besides one thing: this damned IR sensor.

The sensor works as expected on an Arduino (I am able to decode data no problem) but does not seem to work on my NodeMCU (ESP8266). So with the code + diagram I'm sharing below, I was wondering if someone could help me figure out why it's not working as intended :slight_smile:

Circuit:

Note about the circuit: as you can see, I added an LED in series after the IR sensor's output to see if there was any current. The LED is in fact ON (though extremely dim) and using my IR remote's buttons, I'm able to make the light flicker. This led me to believe that 3.3V was just not enough to power the receiver so I swapped the 3.3V + GND with a 9V battery but the LED is (seemingly) just as dim.

Code:

const int INPUT_PIN = D8;

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

  pinMode(INPUT_PIN, INPUT);
}

void loop() {
    Serial.println("INPUT_PIN " + String(INPUT_PIN) + ": " + String(digitalRead(INPUT_PIN)));
    delay(500);
}

This just outputs: INPUT_PIN 15: 0 repeatedly even when holding a IR remote's button.

If that's of any use, I bought my IR receiver from this link: Amazon.com (supposedly an HS0038B but the pinout is different than on datasheets I've viewed online).

Hoping that someone will be able to help. Thanks!

The series LED isnt helping. You can use an LED and resistor to ground to check the output on "OUT" and sttill use it to drive D8. Which

as an input is high impedance so explains why your LED is "dim"

A 3-pin IR sensor outputs a pulse train, which must be decoded with an IR remote library.
Leo..

IR receivers operate at 5 volts. At least I haven't come across a receiver for another power supply. As well as the output is usually open collector and the connection of the LED and the pin of the ESP8266 does not seem correct. Besides your program is not adequate for me for this test.

HS0038B
Supply Voltage VS 4.5 5.5 V

With a weak internal pull up of 30k, which is probably not harmful for 3.3volt logic.
As you said, most IR sensors need a 5volt supply.
Leo..

Thanks for the prompt answer @johnerrington. After reading about impedance, my understanding of what you just said is the following: "The reason the LED is dim is that most current flows to GND given the high impedance of D8. So a resistor in series with GND implies that more current will flow to D8". Is that correct?
So I tried a little test and with no resistor to GND, I get ~100uA to D8 and with a 1K resistor I get ~108uA. Though I'm not sure exactly how much current is needed to "activate" a pin, I'd assume that's not enough?

Here's what the circuit looked like with a resistor in series:

Thanks again for the help!

Thanks for the answer @Wawa. The reason I've used this simple program is for debugging purposes. My understanding is that the various IR libraries are simply wrappers around the digitalRead function that parses the signal and that I could therefore just test with just digitalRead to see if I can see a 1 while holding the remote button. I can then move to using the library but for now it just seems like I don't get any sort of signal from D8 :confused:
To make sure I caught the "raw" pulse train, I reduced delay(500) to delay(20) but still nothing.
I also tried to use the IR library with code like:

#include <IRremote.h>

const int INPUT_PIN = D8;

void setup()
{
  Serial.begin(9600);
  IrReceiver.begin(INPUT_PIN, DISABLE_LED_FEEDBACK);
}

void loop() {
    if (IrReceiver.decode()) {
        Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
        IrReceiver.resume();
    }
    delay(20);
}


to no avail :confused:

My logic was that since 3.3V didn't create enough current to power D8, I thought I'd up it to a 9V battery but even that doesn't seem to make the LED I previously connected bright enough. I guess this probably comes from a fundamental lack of understanding about voltage but here are my questions:

  • if 9V doesn't seem to provide enough power to D8, why would 5V cut it?
  • Having used a 9V battery, does that imply that I damaged my sensor? Or does it simply imply that it won't work without necessarily breaking the component?
    If the latter, why? I thought going over the max rating for a component would destroy it (which doesn't seem to be the case for my IR sensor since it still makes the dim light flicker when I press buttons on my IR remote)? What happens internally to the component under theses conditions?
  • Besides putting a bunch of AA batteries in series to reach ~5V, do you happen to know if there's a better way to get such voltage from the NodeMCU?

Sorry for the long replies guys but I'm a newbie when it comes to electronics (only background in software engineering).

The output of a 3-pin receiver is normally HIGH, and only a short train of LOW pulses is on it's output when the right remote control is used.
If you must drive a LED with a 3-pin receiver, then you should connect the "LED with1k resistor" between 5volt and receiver output. Better of course to drive the LED with another MCU pin.

Did you look if the IRremote library supports the ESP8266.
In the supported boards section they mention an ESP8266 library.
Leo..

Wow had no idea you'd need a different IR library to decode on the NodeMCU. I'll attempt that and keep you guys updated. Thanks Leo!

Sorry for the delay @Wawa. I hadn't picked up my arduino since then.
It works! As soon as I switched to the new library (and copy pasted code like the programmer I am), I was able to decode stuffs.
Thanks a lot!

One last thing: I noticed that even now, I'm unable to pick up on any current from OUT (which would explain why my previous code didn't work). Do you happen to know why that is and what exactly is being decoded?

Did you connect the LED/resistor between 5volt and 3-pin receiver output?
Show your new diagram.
Leo..

Nope. This time I just set up my multimeter in series with OUT and D8 (basically the first diagram but a multimeter instead of the LED).

What do you think that will do.
Think of it as pin D8, internally in the processor, connected to ... nothing.
Leo..

Is that how multimeters work? I didn't know. I was under the impression that connecting the multimeter in series would force current to flow through the device (as to get a reading) and that the current would still reach D8.
The reason I believed so is because I've always connected multimeters in series with whichever part of the circuit I'm trying to get a reading from and I get something.
Why does it not work under these circumstances?

No, that's how an input pin works. It has a very high impedance.
Voltage will still reach the pin through the 10Megohm internal resistor of the DMM,
but you will measure (close to) nothing. No voltage, no current.

A DMM is put in parallel to measure voltage, and in series to measure current.
Leo..