
Download Arduino IDE and continue with the setup.




// Blink - the "hello world" of microcontrollers.
// LED_BUILTIN is the LED soldered to the board, wired to digital pin 13.
void setup() {
// Runs once at power-on and after every reset.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// Runs forever, immediately after setup() finishes.
digitalWrite(LED_BUILTIN, HIGH); // 5V on the pin - LED on
delay(1000); // wait 1000 ms
digitalWrite(LED_BUILTIN, LOW); // 0V - LED off
delay(1000);
}// externalLed.ino - the same blink, on your own LED.
// Wiring: pin 9 -> 330 ohm resistor -> LED long leg (anode);
// LED short leg (cathode) -> GND.
const int LED_PIN = 9;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(500);
digitalWrite(LED_PIN, LOW);
delay(500);
}// button.ino - press to light the LED.
// Wiring: one leg of the button -> pin 2, the other leg -> GND.
// No resistor: INPUT_PULLUP switches on the chip's internal one.
const int LED_PIN = 9;
const int BUTTON_PIN = 2;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
// Pulled up means the pin idles HIGH and reads LOW when pressed -
// the logic looks backwards, and is correct.
if (digitalRead(BUTTON_PIN) == LOW) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}// fade.ino - a potentiometer dims the LED, and the value prints to serial.
// Wiring: pot outer legs -> 5V and GND; pot middle leg -> A0.
// LED still on pin 9 (a PWM pin - this matters).
const int LED_PIN = 9;
const int POT_PIN = A0;
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int raw = analogRead(POT_PIN); // 0-1023, a 10-bit reading
int level = map(raw, 0, 1023, 0, 255); // analogWrite wants 0-255
analogWrite(LED_PIN, level);
Serial.print("pot: ");
Serial.print(raw);
Serial.print(" -> pwm: ");
Serial.println(level);
delay(50);
}