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?

1
  • 4
    The LED is probably active-LOW, that is,it will only light when you send a LOW signal to the appropriate LED pin. The fact that it doesn't blink in the second sketch is because you turn the LED on (LOW), wait one second, turn it off again (HIGH) but it will immediately (within a few microseconds) turn on again in the next loop() iteration. If you want it to stay on for longer, you should place a delay() after it's turned off (digitalWrite(RED,HIGH);).
    – StarCat
    Dec 24, 2020 at 8:15

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.