3

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,673
  • 2
  • 9
  • 22
Ivan
  • 33
  • 1
  • 3
  • 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 '20 at 08:15

1 Answers1

5

There are 3 LEDS on the Nano 33 BLE:

  • A power LED on pin 25 (yes, you can turn off the power LED programatically);
  • 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, ie. 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,673
  • 2
  • 9
  • 22