IOT File
IOT File
OF IOT
1
INDEX
1. Write a program to blink internal light with delay in
Arduino board (pg.- 3-4)
2. Write a program to blink led light with delay, which is
connected with Arduino board. (pg.- 5-6)
2
Q1. Write a program to blink internal light with
delay in Arduino board.
Solution:
void setup() {
// Initialize the digital pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Turn the LED on
digitalWrite(ledPin, HIGH);
// Wait for 1 second
delay(1000);
// Turn the LED off
3
digitalWrite(ledPin, LOW);
// Wait for 1 second
delay(1000);
}
Output:
4
Q2. Write a program to blink led light with
delay, which is connected with Arduino board.
Solution:
void setup() {
// Initialize the digital pin 13 as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Turn the LED on
digitalWrite(ledPin, HIGH);
// Wait for 1 second (1000 milliseconds)
delay(1000);
// Turn the LED off
5
digitalWrite(ledPin, LOW);
// Wait for 1 second (1000 milliseconds)
delay(1000);
}
Output:
6
Q3. Write a program to blink led light using
pushbutton which are connected with Arduino
board.
Solution:
// Pin connected to the LED
int ledPin = 13;
// Pin connected to the pushbutton
int buttonPin = 2;
void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
// Initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
}
void loop() {
7
// Check if the button is pressed
if (digitalRead(buttonPin) == 1) {
// Blink the LED when button is pressed
digitalWrite(ledPin, HIGH); // Turn the LED
on
}
else {
// Keep the LED off if the button is not
pressed
digitalWrite(ledPin, LOW);
}
}
Output:
8
9