4

I picked up my Arduino Nano 33 BLE Sense for the first time in a while and ran the classic "Blink" sketch to make sure it was alright. After slight usage, I wanted to play with the onboard LEDs. When I run the following code, the onboard LED does not turn on:

#define RED 22

void setup() { pinMode(RED, OUTPUT); }

void loop() { digitalWrite(RED, HIGH); }

However, when I run the following code, the onboard LED does turn on and stays on - it doesn't blink:

#define RED 22

void setup() { pinMode(RED, OUTPUT); }

void loop() { digitalWrite(RED, LOW); delay(1000); digitalWrite(RED, HIGH); }

What's happening? Is my Nano busted?

ocrdu
  • 1,795
  • 3
  • 12
  • 24
Ivan
  • 43
  • 1
  • 1
  • 3

1 Answers1

6

There are 3 LEDS on the Nano 33 BLE:

  • A power LED on pin 25 (yes, you can turn off the power LED programmatically);
  • A built-in LED on pin 13;
  • An RGB LED with red on pin 22, green on pin 23, and blue on pin 24.

In the variant file, they are given names:

#define PIN_LED     (13u)
#define LED_BUILTIN PIN_LED
#define LEDR        (22u)
#define LEDG        (23u)
#define LEDB        (24u)
#define LED_PWR     (25u)

The power LED and the built-in LED are active-high, i.e. you need to set their pin to HIGH to turn these LEDs on. The three LEDs in the RGB LED, however, are active-low.

This isn't well-documented as far as I know, and some example code snippets have it wrong too. A quick look at the schematic helps.

Also, as StarCat mentioned, you need two delay()s to make an LED blink.

ocrdu
  • 1,795
  • 3
  • 12
  • 24