Skip to main content
Live robotics updates
Top 10 robotics stories of July 2026The Robot ReportSeedance 2.5: Advancing AI Video Creation for Modern Content WorkflowsRobotics & Automation NewsFCC robot ruling shines a spotlight on U.S. policy; how next-gen AI can help warehousingThe Robot ReportKUKA deploys Automation Management Platform for North American automakersThe Robot ReportAtlas Energy to expand Kodiak-powered autonomous truck fleet to 100 vehicles by 2027Robotics & Automation NewsCreative Gift Ideas You Can Have Custom-MadeRobotics & Automation NewsThe Role of Blockchain and APIs in Shaping the Future of Digital InfrastructureRobotics & Automation NewsProcore Technologies acquires DroneDeploy for $845MThe Robot ReportInterview with Arduino’s Marcello Majonchi: Qualcomm acquisition ushers in new era of edge AI and roboticsRobotics & Automation NewsGoogle DeepMind unveils Gemini Robotics 2 as Apptronik humanoid demonstrates whole-body AIRobotics & Automation NewsTop 10 robotics stories of July 2026The Robot ReportSeedance 2.5: Advancing AI Video Creation for Modern Content WorkflowsRobotics & Automation NewsFCC robot ruling shines a spotlight on U.S. policy; how next-gen AI can help warehousingThe Robot ReportKUKA deploys Automation Management Platform for North American automakersThe Robot ReportAtlas Energy to expand Kodiak-powered autonomous truck fleet to 100 vehicles by 2027Robotics & Automation NewsCreative Gift Ideas You Can Have Custom-MadeRobotics & Automation NewsThe Role of Blockchain and APIs in Shaping the Future of Digital InfrastructureRobotics & Automation NewsProcore Technologies acquires DroneDeploy for $845MThe Robot ReportInterview with Arduino’s Marcello Majonchi: Qualcomm acquisition ushers in new era of edge AI and roboticsRobotics & Automation NewsGoogle DeepMind unveils Gemini Robotics 2 as Apptronik humanoid demonstrates whole-body AIRobotics & Automation News
View all
Back
Arduino sample guide

roboda-sample-0101 - Digital Output 05

Turn a digital output on and off for an LED, relay module, or simple indicator.

Step-by-step build

Blink and pulse digital pins for LEDs, relays, indicators, and simple actuators.

1

Connect the LED/resistor or module input to ledPin.

2

Set ledPin as OUTPUT in setup().

3

Use digitalWrite(HIGH) and digitalWrite(LOW) in loop().

4

Change the two delay() values to control blink speed.

Important code parts

These are the sections learners should understand before changing the sketch.

pinMode(ledPin, OUTPUT)

Makes the pin drive voltage out instead of reading input.

digitalWrite()

Sets the pin HIGH or LOW.

delay()

Pauses so the output stays visible.

Pin mapping for this sample

Use this first table for the exact sample wiring, then use the board-family table when moving the sketch to another Arduino board.

Code nameSample pinModeConnect toNote
ledPinD6OUTPUTLED through 220-330 ohm resistor, relay module input, or indicatorDo not connect a bare load directly to an Arduino pin.

Arduino board pin reference

The code names stay the same; only the physical board pins may change by family. Always confirm with the board silkscreen when using clones or special variants.

Board familyDigitalPWMAnalogI2CSPIInterrupt
Uno / Nano / Pro MiniDefault target for these samples.D0-D13D3, D5, D6, D9, D10, D11A0-A5A4 SDA, A5 SCLD10 SS, D11 MOSI, D12 MISO, D13 SCK / ICSPD2, D3
Mega 2560Best for many sensors or multiple serial ports.D0-D53D2-D13, D44-D46A0-A15D20 SDA, D21 SCLD50 MISO, D51 MOSI, D52 SCK, D53 SS / ICSPD2, D3, D18, D19, D20, D21
Leonardo / MicroUSB serial can behave differently because the main MCU handles USB.D0-D13D3, D5, D6, D9, D10, D11, D13A0-A5 plus extra analog-capable pins by boardD2 SDA, D3 SCLICSP headerD0, D1, D2, D3, D7
Nano Every / Uno WiFi Rev2Check the board package pinout for exact PWM labels.D0-D13PWM-marked digital pinsA0-A7 on Nano Every, A0-A5 on Uno WiFi Rev2SDA/SCL marked pinsICSP/SPI marked pinsUse pins supported by digitalPinToInterrupt()
Uno R4 Minima / Uno R4 WiFi5V logic board; still confirm shield/library compatibility.D0-D13PWM-marked digital pinsA0-A5SDA/SCL marked pinsICSP/SPI marked pinsUse digitalPinToInterrupt(pin)
Due3.3V logic only; protect pins from 5V sensors.D0-D53PWM-marked digital pinsA0-A11SDA/SCL and SDA1/SCL1SPI headerUse digitalPinToInterrupt(pin)
MKR / Nano 33 family3.3V logic. Some AVR-only libraries may need alternatives.Board-marked digital pinsPWM-marked pinsBoard-marked analog pinsSDA/SCL marked pinsSPI marked pinsUse digitalPinToInterrupt(pin)

Full sample code

/*
  Roboda verified Arduino sample 0101
  Feature: Digital Output
  Generated for online build, classroom practice, and hardware upload testing.
*/

const byte ledPin = 6;

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

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(220);
  digitalWrite(ledPin, LOW);
  delay(220);
}

Teacher notes

  • Compile the sample before changing wiring or constants.
  • When changing boards, keep the code names the same and update only the pin number constants.
  • For 3.3V boards, level-shift 5V sensors and modules before connecting signal pins.
  • Use the first compiler error and the Roboda diagnostic suggestion before fixing later warnings.
Roboda support Leave a message

New messages appear in the Finite LiveChat Ops Android app.