IoT EXP3
IoT EXP3
Case 1: Write an Arduino program that toggles LED 1 when pushbutton 1 is pressed. Ensure that each
press changes the state of LED 1 (from ON to OFF or OFF to ON).
Case 2: When pushbutton 1 is pressed, the LCD should show "Button 1 ON" on the first row and "LED 1
ON" on the second row. When pressed again, it should display "Button 1 OFF" and "LED 1 OFF".
Case 3: Add functionality to your program so that the buzzer sounds briefly (e.g., for 500 milliseconds)
whenever LED 1 or LED 2 is turned ON or OFF. Ensure the buzzer does not continue to sound after the
initial toggle
2. Apparatus:
Hardware Requirements
a) Arduino Uno
b) 16x2 I2C LCD Display
c) 2x Pushbuttons
d) 2x LEDs
e) 1x Buzzer
f) 2x 220Ω Resistors (for LEDs)
Software requirements
a) TinkerCad
3. Circuit Diagram(TinkerCad):
1. Coding:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
void setup() {
pinMode(button1Pin, INPUT_PULLUP); // Enable internal pull-up resistor
pinMode(button2Pin, INPUT_PULLUP); // Enable internal pull-up resistor
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.print("System Ready");
delay(2000);
lcd.clear();
}
void loop() {
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
lcd.clear();
if (led1State == HIGH) {
lcd.print("Button 1 ON");
lcd.setCursor(0, 1);
lcd.print("LED 1 ON");
} else {
lcd.print("Button 1 OFF");
lcd.setCursor(0, 1);
lcd.print("LED 1 OFF");
}
tone(buzzerPin, 1000, 500);
delay(500);
}
lastButton1State = button1State;
lastButton2State = button2State;
}
5. Learning outcomes (What I have learnt):
a) Gain experience in controlling LEDs based on button inputs and managing LED states (ON/OFF).
b) Learn how to display text on an LCD and update the display based on user interactions.
c) Understand how to initialize and configure an I2C LCD with the Arduino
d) Learn how to generate tones of different frequencies and durations using the tone() function,
which is useful for sound alerts and notifications.