0% found this document useful (0 votes)
11 views5 pages

IoT EXP3

The document outlines a practical assignment for interfacing a buzzer, LEDs, pushbuttons, and an LCD with an Arduino Uno. It includes specific cases for toggling an LED with a button press, displaying messages on the LCD, and generating sounds with a buzzer. Additionally, it lists the necessary hardware and software requirements, provides a coding example, and details the learning outcomes related to controlling components and displaying information.

Uploaded by

priyanka gami
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)
11 views5 pages

IoT EXP3

The document outlines a practical assignment for interfacing a buzzer, LEDs, pushbuttons, and an LCD with an Arduino Uno. It includes specific cases for toggling an LED with a button press, displaying messages on the LCD, and generating sounds with a buzzer. Additionally, it lists the necessary hardware and software requirements, provides a coding example, and details the learning outcomes related to controlling components and displaying information.

Uploaded by

priyanka gami
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/ 5

Worksheet 1.3.

Student Name: Priyanka Gami UID: 23MCA20134


Branch: MCA Section/Group:6/B
Semester: 3rd Date of Performance: 10/08/2024
Subject Name: Internet of Things Subject Code: 23CAH-702

1. Aim/Overview of the practical:


Interface a buzzer, led, pushbutton (Pull Down) and LCD with Arduino Uno. Use two led and two
pushbuttons. Use pushbutton as toggle switch.

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>

// Initialize the I2C LCD with the I2C address (0x27)


LiquidCrystal_I2C lcd(0x27, 16, 2);

const int button1Pin = 2; // Pin for Pushbutton 1


const int button2Pin = 3; // Pin for Pushbutton 2
const int led1Pin = 8; // Pin for LED 1
const int led2Pin = 9; // Pin for LED 2
const int buzzerPin = 10; // Pin for the buzzer

int led1State = LOW; // State of LED 1


int led2State = LOW; // State of LED 2
int button1State = LOW; // Current state of Pushbutton 1
int lastButton1State = LOW; // Last state of Pushbutton 1
int button2State = LOW; // Current state of Pushbutton 2
int lastButton2State = LOW; // Last state of Pushbutton 2
bool led1Toggled = false; // Flag to prevent continuous buzzer sound

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);

if (button1State == LOW && lastButton1State == HIGH) {


led1State = !led1State;
digitalWrite(led1Pin, led1State);

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);
}

if (button2State == LOW && lastButton2State == HIGH) {


led2State = !led2State;
digitalWrite(led2Pin, led2State);
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.

You might also like