Infrared LED not working


I’m trying to build a wi-fi controlled AC remote, based on Wemos D1 mini lite and IRremoteESP8266 library.

The scheme is as simple as it can get, borrowed from the IRremoteESP8266 example - IR LED is connected through a NPN transistor.

Transistor is KSP42.

What I have seen so far:

  • Once after I built the circuit and powered it on, I could see that LED was working through my phone camera.
  • After that one time, without changes to the circuit, the IR LED was not emitting anything, however the code was printing out everything correctly in serial monitor.

Code is the example:

/* Copyright 2016, 2018 David Conran
*  Copyright 2020 Sadid Rafsun Tulon
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
* Suggested circuit:
* Common mistakes & tips:
*   * Don't just connect the IR LED directly to the pin, it won't
*     have enough current to drive the IR LED effectively.
*   * Make sure you have the IR LED polarity correct.
*     See:
*   * Typical digital camera/phones can be used to see if the IR LED is flashed.
*     Replace the IR LED with a normal LED if you don't have a digital camera
*     when debugging.
*   * Avoid using the following pins unless you really know what you are doing:
*     * Pin 0/D3: Can interfere with the boot/program mode & support circuits.
*     * Pin 1/TX/TXD0: Any serial transmissions from the ESP8266 will interfere.
*     * Pin 3/RX/RXD0: Any serial transmissions to the ESP8266 will interfere.
*   * ESP-01 modules are tricky. We suggest you use a module with more GPIOs
*     for your first time. e.g. ESP-12 etc.
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Gree.h>

const uint16_t kIrLed = D2;  // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRGreeAC ac(kIrLed);  // Set the GPIO to be used for sending messages.

void printState() {
  // Display the settings.
  Serial.println("GREE A/C remote is in the following state:");
  Serial.printf("  %s\n", ac.toString().c_str());
  // Display the encoded IR sequence.
  unsigned char* ir_code = ac.getRaw();
  Serial.print("IR Code: 0x");
  for (uint8_t i = 0; i < kGreeStateLength; i++)
    Serial.printf("%02X", ir_code[i]);

void setup() {

  // Set up what we want to send. See ir_Gree.cpp for all the options.
  // Most things default to off.
  Serial.println("Default state of the remote.");
  Serial.println("Setting desired state for A/C.");
  // kGreeAuto, kGreeDry, kGreeCool, kGreeFan, kGreeHeat
  ac.setTemp(20);  // 16-30C
  ac.setSwingVertical(true, kGreeSwingAuto);

void loop() {
  // Now send the IR signal.
  Serial.println("Sending IR command to A/C ...");
#endif  // SEND_GREE

Where should I start?

Thank you.

Don't You need a resistor in serie with the IR diode?

I think you have the base and collector of the transistor swopped and you definitely need a resistor in series with the IR diode.

Then a resistor in serie with the base would be good.

  • Common mistakes & tips:
    • Don’t just connect the IR LED directly to the pin, it won’t
  • have enough current to drive the IR LED effectively.

That is flat-out wrong on Arduinos, even the 3.3V ARM chip Arduinos!

And Uno can Easily burn an IR led out. There’s a “funny” smell and smoke you can’t see. Hope the room is ventilated.

Use a phototransistor and very little (4 or 5 mA worth) IR gets detected in under a microsecond.
You can verify this without an Arduino, power a led through a resistor (220 to 1K Ohms) to the phototransistor on a breadboard.

Also try the same with a red led instead of an IR led. Light up led13 on your board and look at it with your camera to see why.

An infra-red LED typically has a forward voltage of 1.2 - 1.5V.

You can drive 20mA through it if you connect it directly between your 5V supply and arduino pin, using a 150 ohm resistor.

most phone & webcams are IR sensitive so you can check its working (IR is not visible to human eye)

The circuit you provided shows it connected directly between +5 and GND through the transistor base emitter junction. If that is not an error in the diagram you WILL have burnt out something; but IR LEDs can take a LOT of current so its likely the transistor or the arduino pin.

You can test the LED by connecting between +5 and GND again with a 150 ohm series resistor

If you NEED more current you can use a transistor or FET to drive the LED.

Thank you a lot for replies, guys.

Will check all of this in a couple days, when I'm back.