infrared transmitter/Driving it/06. The first blink
Driving it · 06 of 9

The first blink

Three wires, no library, and a sketch that turns the infrared LED on for a second and off for a second. You will not see it. The red LED beside it shows the transistor switching, and a phone camera often shows the infrared itself as a faint violet glow. VCC goes to 5V; SIGNAL to GPIO 6 on an ESP32-S3, GPIO 22 on an ESP32, D3 on an Uno, GP17 on a Pico.

Three wires

Three wires
Your board
VCC to
5V
SIGNAL to
GPIO 6
pinMode
OUTPUT
GND to GND, VCC to 5V, SIGNAL to GPIO 6. The ESP32-S3's pins run at 3.3 V and VCC can still be 5 V: it only feeds the two LEDs and never reaches GPIO 6. GPIO 6 is not a strapping pin, which matters because SIGNAL pulls a pin down to under a volt.

GND to GND. VCC to 5V, or VBUS on a Pico: it only feeds the LEDs, so 5 V is safe on a 3.3 V board and gives the most light. SIGNAL to the pin this book uses throughout. NC stays unconnected.

The pins are the IR handbook's send pins, so its receiver sketches line up with this block. None of them is a strapping pin, and that matters here in an unusual way. SIGNAL is 1 kΩ and a transistor's base to GND, which pulls a pin down to under a volt. On an ESP32-S3's GPIO 0, against the dev board's 10 kΩ BOOT pull-up, that is about 0.94 V: not a level the chip promises to read as HIGH, so it may start in its download mode, with the LEDs lit through the reset.

The sketch

pinMode(IR_PIN, OUTPUT) and digitalWrite(IR_PIN, LOW) first, because nothing on the board holds the transistor off. Then the loop: HIGH for a second, LOW for a second, a line to the serial monitor each time.

What you should see

Who can see it
Your eye
nothing
Red LED
dark
Wavelength
940 nm
Before the sketch runs, SIGNAL is LOW and both LEDs are dark. Press the button to run the blink.

At 115200 the serial monitor prints on and off a second apart, and the small red LED blinks with it. The infrared LED does not change at all to your eye.

Now look at it through a phone camera, in a dim room, straight into the lens. Many cameras show 940 nm as a faint violet glow that comes and goes with the red LED. Some filter infrared out almost completely; try another camera before suspecting the block. If the red LED blinks, the infrared LED is on: they share the transistor.

The code

No library. digitalWrite HIGH turns the transistor on and both LEDs light; LOW turns them off, once a second, with a line to the serial monitor each time. Change IR_PIN to the pin you wired SIGNAL to.

ir_first_blink.ino
/*
  Infrared Transmitter - first blink                     TK63 / /p/tk63

  Wiring. Count from the square pad on the TinkerBlock board, parts
  up, header at the bottom:

    GND    -> GND
    VCC    -> 5V (VBUS on a Pico) for full range; 3V3 works, shorter.
              VCC only feeds the two LEDs, so 5V is safe on any board.
    NC     -> nothing   (unconnected on the board)
    SIGNAL -> GPIO 6 on an ESP32-S3, GPIO 22 on an ESP32,
              D3 on an Uno, GP17 on a Raspberry Pi Pico

  Arduino IDE
    Tools > Board                 your board, e.g. ESP32S3 Dev Module
    Tools > Port                  the one that appears when you plug in
    Tools > USB CDC On Boot       Enabled   (ESP32-S3 only)
    No library needed.
    Serial Monitor                115200
*/

// The pin SIGNAL is wired to.
// Uno: 3. ESP32: 22. ESP32-S3: 6. Pico: 17.
const int IR_PIN = 6;

void setup() {
  // LOW first: nothing on the board holds the transistor off.
  pinMode(IR_PIN, OUTPUT);
  digitalWrite(IR_PIN, LOW);
  Serial.begin(115200);
}

void loop() {
  // HIGH turns the transistor on: both LEDs light.
  digitalWrite(IR_PIN, HIGH);
  Serial.println("on: the red LED is lit; look through a camera");
  delay(1000);

  digitalWrite(IR_PIN, LOW);
  Serial.println("off");
  delay(1000);
}

setup() drives the pin LOW before anything else, because nothing on the board holds the transistor off. The sketch compiles for an ESP32-S3 and an Uno.

View on GitHub · blocks/tk63-ir-transmitter/arduino/ir_first_blink/ir_first_blink.ino @ v1.5

When it does not work

The red LED blinks but the camera shows nothing.

Then the block works: the red LED is on the infrared LED's transistor. Many phone cameras filter infrared, some completely. Try another camera, the front one included, in a dim room, looking straight down into the lens.

Nothing blinks, not even the red LED.

The transistor never switched or the LEDs have no supply. Count from the square pad: GND, VCC, NC, SIGNAL. Check IR_PIN is the pin SIGNAL is on, and that the wire is not on NC, which is connected to nothing.

The serial monitor stays empty on my ESP32-S3.

Set Tools > USB CDC On Boot to Enabled and upload again. Without it the S3's USB port does not bring up a serial port at boot, so the sketch runs, and blinks, with nowhere to print.

The red LED lit before the sketch started.

Nothing on the board holds the transistor off, so it follows the pin during reset. A pin that floats or is pulled up then can light both LEDs until setup() sets it LOW. It does no harm; on a strapping pin it can also change how the board starts, which is why this book avoids them.

Where this goes next

Why a steady light reaches no remote-control receiver, and the 38 kHz that does.

A carrier the TK15 hears →

Edit this page — content/books/ir-transmitter/the-first-blink.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Infrared Transmitter

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →