Learn ARDUINO-C-CPP with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Blink an LED
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
Toggle an LED on pin 13 every 500 ms.
2
Read Analog Sensor
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(100);
}
Read a potentiometer value and print it to the serial monitor.
3
Control Servo Motor
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9);
}
void loop() {
for(int pos = 0; pos <= 180; pos++) {
myServo.write(pos);
delay(15);
}
for(int pos = 180; pos >= 0; pos--) {
myServo.write(pos);
delay(15);
}
}
Sweep a servo motor from 0° to 180° and back.