Exp 04
Exp 04
Submitted by Submitted to
Series : 19 RUET
Experiment No: 04
(a) (b)
(c) (d)
(e) (f)
Fig 4.01: Circuit diagram for a) LED blinking, (b) LED fading, (c) Traffic light control, (d)
Interfacing of push switch, (e) On and off of LED by press switch, (f)Interfacing of POT.
Required Apparatus:
01. Arduino UNO.
02. Resistors (220 ohm, 3 pieces)
03. LED (3 pieces)
04. Potentiometer ( 1 pieces, 100k)
05. Bread Board.
06. Laptop.
07. Push button.
08. Wires and etc.
Required Codes:
i) Codes for LED blinking:
void setup() {
pinMode(8, OUTPUT);
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
}
void setup() {
// put your setup code here, to run once:
pinMode(8, OUTPUT);
pinMode(7,OUTPUT);
pinMode(4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(8, HIGH);
digitalWrite(7,LOW);
digitalWrite(4,LOW);
delay(2000);
digitalWrite(8, LOW);
digitalWrite(7,HIGH);
digitalWrite(4,HIGH);
delay(1000);
digitalWrite(8, LOW);
digitalWrite(7,LOW);
digitalWrite(4,HIGH);
delay(1500);
#define LED_PIN 8
#define BUTTON_PIN 7
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
}
void loop() {
if (millis() - lastTimeButtonStateChanged > debounceDuration) {
byte buttonState = digitalRead(BUTTON_PIN);
if (buttonState != lastButtonState) {
lastTimeButtonStateChanged = millis();
lastButtonState = buttonState;
if (buttonState == LOW) {
ledState = (ledState == HIGH) ? LOW: HIGH;
digitalWrite(LED_PIN, ledState);
}
}
}
}
Hardware Implementation:
(a) (b)
(c) (d)
(e) (f)
Fig 4.02: Hardware implementation of (a) LED blinking, (b) LED fading, (c) Traffic light
control, (d) Interfacing of push switch, (e) On and off of LED by press switch, (f)Interfacing
of POT.