0% found this document useful (0 votes)
3 views4 pages

LED Counter Logic

The document outlines an Arduino experiment to control three LEDs based on a counter value. The green LED lights up when the counter is below 100, the yellow LED activates between 101 and 200, and the red LED illuminates when the counter exceeds 200. The counter resets to 0 after reaching 300, and its value is displayed in the Serial Monitor.

Uploaded by

prathameshkate15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

LED Counter Logic

The document outlines an Arduino experiment to control three LEDs based on a counter value. The green LED lights up when the counter is below 100, the yellow LED activates between 101 and 200, and the red LED illuminates when the counter exceeds 200. The counter resets to 0 after reaching 300, and its value is displayed in the Serial Monitor.

Uploaded by

prathameshkate15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO.

– 6

Problem Statement:

Create an Arduino program that:


• Illuminates the green LED when the counter is less than 100.
• Illuminates the yellow LED when the counter is between 101
and 200.
• Illuminates the red LED when the counter is greater than 200.

Components Required:
• Arduino Board (UNO, Mega, etc.)
• 3 LEDs (Green, Yellow, Red)
• 3 x 220Ω Resistors
• Breadboard
• Jumper Wires
• Arduino IDE

Circuit Connections:
1. Green LED
• Anode (long leg) → Digital Pin 7 (via a 220Ω resistor)
• Cathode (short leg) → GND
2. Yellow LED
• Anode (long leg) → Digital Pin 8 (via a 220Ω resistor)
• Cathode (short leg) → GND
3. Red LED
• Anode (long leg) → Digital Pin 9 (via a 220Ω resistor)
• Cathode (short leg) → GND
Arduino Code :

#define GREEN_LED 7
#define YELLOW_LED 8
#define RED_LED 9

int counter = 0;

void setup() {
pinMode(GREEN_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
Serial.begin(9600);
}

void loop() {
counter += 10;
Serial.println(counter);

if (counter < 100) {


digitalWrite(GREEN_LED, HIGH);
digitalWrite(YELLOW_LED, LOW);
digitalWrite(RED_LED, LOW);
}
else if (counter >= 101 && counter <= 200) {
digitalWrite(GREEN_LED, LOW);
digitalWrite(YELLOW_LED, HIGH);
digitalWrite(RED_LED, LOW);
}
else if (counter > 200) {
digitalWrite(GREEN_LED, LOW);
digitalWrite(YELLOW_LED, LOW);
digitalWrite(RED_LED, HIGH);
}
delay(1000);

if (counter > 300) {


counter = 0;
}
}
Output :

1. When the counter is less than 100 → Green LED illuminates.


2. When the counter is between 101 and 200 → Yellow LED
illuminates.
3. When the counter is greater than 200 → Red LED illuminates.
4. The counter resets to 0 after reaching 300 and repeats the
cycle.
5. The counter value is displayed in the Serial Monitor.

You might also like