LED By Using Arduino Simulator
Component List
a. Resistor
b. Red LED
c. Arduino
Code:
void setup() {
// put your setup code here, to run once:
pinMode(8, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(8, HIGH);
}
Output:
How does the 'loopCount' variable in the provided Arduino
sketch control the number of times the LED blinks?
STEP 1. Setup: Initialize the Arduino board, configuring pin 8 as an output
pin for controlling the light.
STEP 2. Loop: a. Initialize a static variable loopCount to keep track of the
number of loops executed. b. Check if loopCount is less than 3. c. If
loopCount is less than 3:
a. Turn on the light by setting pin 8 to HIGH.
b. Delay for 5 seconds to keep the light on.
c. Turn off the light by setting pin 8 to LOW.
d. Delay for 2 seconds to keep the light off.
e. Increment the loopCount variable. d. Repeat the loop until
loopCount reaches 3.
Required Components:
1. Arduino Board
2. LEDs (Red and Green)
3. Resistors (for current limiting, one for each LED)
4. Jumper Wires
Code:
void setup() {
pinMode(8, OUTPUT);
}
void loop() {
static int loopCount = 0;
if (loopCount < 3) {
digitalWrite(8, HIGH);
delay(5000);
digitalWrite(8, LOW);
delay(2000);
loopCount++;
}
}