Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Roll No:1253 IOT LAB

Practical No. 5

Aim: To interface led, buzzer and two push buttons with Arduino

Objectives:

1. To learn Arduino UNO basics


2. Write a program to interface led, buzzer and two push buttons with Arduino

Theory:

LED: A light-emitting diode is a semiconductor light source that emits light when current
flows through it.

Resistor: A resistor is a passive two-terminal electrical component that implements


electrical resistance as a circuit element. In electronic circuits, resistors are used to reduce
current flow, adjust signal levels, to divide voltages, bias active elements, and terminate
transmission lines, among other uses.

Push-button: a device designed to close or open an electric circuit when a button or knob is
pressed, and to return to a normal position when it is released.

Piezo Buzzer: a piezo buzzer is a type of electronic device that’s used to produce a tone,
alarm or sound. 

noTone(pin):Stops the generation of a square wave triggered by tone(). Has no effect if no


tone is being generated. the Arduino pin on which to stop generating the tone.

tone():Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A
duration can be specified, otherwise the wave continues until a call to noTone(). The pin can
be connected to a piezo buzzer or other speaker to play tones.

digitalRead(pin):Reads the value from a specified digital pin, either HIGH or LOW. the


Arduino pin number you want to read.

Circuit Diagram:

1
Roll No:1253 IOT LAB

Program:

// C++ code

int led = 13;

int buzzer = 3;

int button1 = 12;

int button2 = 11;

int buttonstate1 = 0;

int buttonstate2 = 0;

void setup()

pinMode(led,OUTPUT);

pinMode(buzzer,OUTPUT);

pinMode(button1,INPUT_PULLUP);

pinMode(button2,INPUT_PULLUP);

noTone(buzzer);

2
Roll No:1253 IOT LAB

void loop()

buttonstate1 = digitalRead(button1);

buttonstate2 = digitalRead(button2);

if(buttonstate1 == LOW)

digitalWrite(led,HIGH);

delay(2000);

digitalWrite(led,LOW);

delay(100);

if(buttonstate2 == LOW)

tone(buzzer,500);

delay(2000);

noTone(buzzer);

delay(100);

Output:

3
Roll No:1253 IOT LAB

Conclusion: Thus, learnt about basic components of IoT like Arduino UNO, Breadboard,
resisters, LED’s and interfacing LED with Arduino.

Practical No. 6

4
Roll No:1253 IOT LAB

Aim: To interface three leds, three push button with ArduinoObjectives:

1. To learn Arduino UNO basics


2. Write a program To interface three leds, three push button with Arduino

Theory:

pinMode(pin, mode):Configures the specified pin to behave either as an input or an output.


See the Digital Pins page for details on the functionality of the pins.As of Arduino 1.0.1, it is
possible to enable the internal pullup resistors with the mode INPUT_PULLUP. Additionally,
the INPUT mode explicitly disables the internal pullups.

Circuit Diagram:

Program:

// C++ code

//

const int button1 = 10;

const int button2 = 9;

const int button3 = 8;

const int led1 = 13;

5
Roll No:1253 IOT LAB

const int led2 = 12;

const int led3 = 11;

int buttonstate1 = 0;

int buttonstate2 = 0;

int buttonstate3 = 0;

void setup()

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(button1,INPUT_PULLUP);

pinMode(button2,INPUT_PULLUP);

pinMode(button3,INPUT_PULLUP);

void loop()

buttonstate1 = digitalRead(button1);

buttonstate2 = digitalRead(button2);

buttonstate3 = digitalRead(button3);

if(buttonstate1 == LOW)

digitalWrite(led1,HIGH);

delay(1000);

digitalWrite(led1,LOW);

delay(100);

6
Roll No:1253 IOT LAB

if(buttonstate2 == LOW)

digitalWrite(led2,HIGH);

delay(1000);

digitalWrite(led2,LOW);

delay(100);

if(buttonstate3 == LOW)

digitalWrite(led3,HIGH);

delay(1000);

digitalWrite(led3,LOW);

delay(100);

Output:

7
Roll No:1253 IOT LAB

Conclusion: Thus, learnt about basic components of IoT like Arduino UNO, Breadboard,
resisters, LED’s and interfacing LED with Arduino.

You might also like