Here's a basic tutorial for blinking an LED with Arduino C++:
Hardware Required: Arduino board, LED, 220-ohm resistor, breadboard, and jumper wires.
Circuit: Connect the longer leg of the LED (anode) to a digital pin on the Arduino through a 220-ohm resistor. Connect the shorter leg (cathode) to the GND pin.
Code:
int LED_PIN = 13; // Use pin 13 (or any other digital pin)
void setup() {
pinMode(LED_PIN, OUTPUT); // Initialize the LED pin as an output
}
void loop() {
digitalWrite(LED_PIN, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second (1000 milliseconds)
digitalWrite(LED_PIN, LOW); // Turn the LED off
delay(1000); // Wait for 1 second
}
pinMode(LED_PIN, OUTPUT): Configures the specified pin as an output.
digitalWrite(LED_PIN, HIGH): Sets the pin to HIGH (5V), turning the LED on.
digitalWrite(LED_PIN, LOW): Sets the pin to LOW (0V), turning the LED off.
delay(1000): Pauses the program for 1000 milliseconds (1 second).
Upload and Run: Upload the code to your Arduino. The LED should blink on and off every second.
You can adjust the delay() values to change the blinking speed.