Example Code for Arduino-Write Digital Pins
Last revision 2026/01/18
This article offers a comprehensive guide on writing digital pins for Arduino, specifically focusing on blinking an LED using DFRobot Beetle RP2040, Arduino IDE, and the Raspberry Pi Pico SDK. It includes detailed hardware and software preparation, wiring diagrams, and sample code for effective learning and application.
Hardware Preparation
- DFRobot Beetle RP2040, 1, Purchase Link
- USB Type-C Cable, 1
- LED (3mm/5mm), 1
- Current-limiting resistor (220Ω~2KΩ), 1
Software Preparation
- Arduino IDE: Download Link
- Raspberry Pi Pico/RP2040 SDK: Installed via Arduino Boards Manager (see Getting Started)
Wiring Diagram

- R: current-limiting resistor, the value is 220Ω~2KΩ.
- LED: the bent side is positive, the straight side is negative, it's on when GP0 at high level and off when at low.
Other Preparation Work
- Open Arduino IDE.
- Select "DFRobot Beetle RP2040" as the development board.
- Connect the Beetle RP2040 to your computer via USB Type-C cable.
- Wire the LED and resistor to GP0 (D0) as per the diagram.
Sample Code
Function: make the LED connected to GP0 blink at one second intervals.
int digital_test =0;
void setup() {
pinMode(digital_test, OUTPUT); //set the pin to output mode
}
void loop() {
digitalWrite(digital_test, HIGH); //high level for lighting up the LED
delay(1000);
digitalWrite(digital_test, LOW); //low level for turning off the LED
delay(1000);
}
Result
After downloading the code, the LED connected to GP0 will blink at one-second intervals. If the LED is not lit, please check the hardware connection according to the connection diagram.
Additional Information
- The digital pin GP0 is mapped to D0 in the Arduino environment.
- Ensure the LED’s polarity is correct (bent leg to GP0, straight leg to GND via the resistor).
Was this article helpful?
