0% found this document useful (0 votes)
12 views

Week2 - IoT Lab Experiments

Uploaded by

Nikitha reddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Week2 - IoT Lab Experiments

Uploaded by

Nikitha reddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Week-2

EXPERIMENT4 : (i)Write program for Buzzer using Arduino UNO.

An Arduiono Buzzer is a basically a beeper. The Arduino Buzzer is a device that


produces sound when an electric current is passed through it. The Arduino Buzzer can be directly
connected to the Arduino and produce different tones by giving different frequency electric
pulses to the Buzzer. The Aruino buzzers are most commonly used as beepers in any system,
Alarm and devices, timers, security systems security systems and to produce sound on
confirmation of user input and in many systems. The buzzers are of different types as
Mechanical Buzzer, Electro mechanical buzzers and Piezoelectric buzzers.

The piezoelectric buzzer is most commonly used with Arduino. As it is lightweight,


simple in construction, typically a low-cost product that can generate different sound tones of
different frequencies and does not require a separate oscillating circuit.

The Positive pin(+ve) of the Arduino Buzzer has to be connected to the VCC of Arduino and the
Negative pin(-ve) has to be connected to the GND pin of the Arduino. The components required
to interface Buzzer with Arduino UNO. Arduino UNO, Buzzer, Breadboard, 100 ohms Resistor,
Connecting jumper wires.

/* Arduino tutorial - Buzzer / Piezo Speaker

const int buzzer = 8; //buzzer to arduino pin 9

void setup(){
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
}

void loop(){
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
(ii) Buzzer with Arduino UNO - Application with Buzzer to play a Music
+ -

Write a Program to music with Buzzer using Arduino UNO


int melody[]={262,294,330,349,392,440,494,523};//melody frequency for 8 sounds SRGMPDNS
const int buzzer = 8; //passive buzzer pin number
int noteDuration = 850; //duration of play song = 850 mseconds
int noteDelay = 850;
void setup()
{
pinMode(buzzer, OUTPUT); //buzzer pin=8 is INPUT/OUTPUT
}
void loop()
{
delay(500);
for (int i=0; i<8; i++) //for loop playing 8 sound frequencies onebyone
{
tone(buzzer, melody[i], noteDuration);
delay(noteDelay);
}
noTone(buzzer);
delay(noteDelay);
for(int j=7; j >=0; j--) //playing reverse
{
tone(buzzer, melody[j], noteDuration);
delay(noteDelay);
}

if (noteDuration> 100) //if duration > 100 is condition


{
noteDuration -=150; //to reduce time
noteDelay = 150;
}
else
{
noteDuration = 850;
noteDuration=850;
}
}
EXPERIMENT-5

5. Write program for LDR using Arduino UNO


An LDR or Light Dependent Resistor is a type of optoelectronic sensor that used for detecting
light in the environment. It works by sensing changes in illumination and converting them into
electrical signals which can be read off from its two terminals. This makes it an essential tool in
many automation systems because it helps detect objects without any physical contact with them.

Light Dependent Resistor(LDR) technology is widely used in may industrial, education and
commercial applications. It is highly sensitive contactless operation allows it to replace
mechanical switches for a wide range of needs. The LDR can be found in use as light sensors or
solar radiation detectors, controlling street lights on highways, automatically changing the
direction of traffic signals at intersections. Even photoelectric equipment such as smoke detector
alarms all rely upon this small but efficient device which monitors changes from darkness into
ambient light with impressive accuracy.

Applications of LDR sensors


 The photoresistor is typically used to measure light intensity and presence
 Used in lights that turn on and off
 Smoke Detector Alarm, Automatic Lighting Clock
 Design of optical circuits
 Solar street lighting

LDR is Light Dependent Register. LDR is for sensing light. If intensity of light is more then its
intensity decreases. If intensity of light is dark then its intensity increases.
Program:

int ldr = 7; // LDR sensor for input pin=7


int x; //LDR sensor value stored in x variable
int led = 13; // LED in 13 pin for HIGH=blink

void setup() //setup code here to run


{
Serial.begin(9600); //serial communication with 9600 bodrate. Arduino send
out commands via USB. How fast data is sent.
pinMode(7,INPUT); //pin 7 for LDR = OUTPUT
pinMode(13,OUTPUT); //PIN 13 LED for blink=HIGH
}

void loop() //main code run repeatedly


{

x = digitalRead(7);
Serial.println(x); //print data to serial port

if(x == HIGH)
{
digitalWrite(13, HIGH); //LED=blink HIGH
}
if(x == LOW)
{
digitalWrite(13, LOW); //LED=blink LOW
}
}
Output: 0 = shows LED OFF when focus light on LDR
1 = shows LED ON when no focus light on LDR
EXPERIMENT-6
6. Write program for IR Sensor using Arduino UNO.

IR sensor is an electronic device, that emits the light in order to sense some object of the
surroundings. An IR sensor can measure the heat of an object as well as detects the motion.
Usually, in the infrared spectrum, all the objects radiate some form of thermal radiation.
These types of radiations are invisible to our eyes, but infrared sensor can detect these
radiations.

Working Procedure IR Sensor: IR sensor using infrared frequencies. In IR sensor two


LEDs present. White IR LED continuously transfer the IR signals. IR sensor detect any
object then signals reflect to photo diode (Black color LED). The photo diode inform to
Ardiono UNO about the object detection.

Application of IR sensor
 Water analysis
 Petroleum exploration
 Rail safety
 Gas detectors
Program:
int LED = 13; // LED in 13 pin for HIGH=blink
int x = 7; //IR sensor value stored in x variable
int y;
void setup()
{
// put your setup code here, to run once:
pinMode(LED, OUTPUT); //pin 7 for LDR = OUTPUT
pinMode(x, INPUT); //PIN 13 LED for blink=HIGH
}
void loop()
{
// put your main code here, to run repeatedly:
y = digitalRead(x);
if (y == LOW)
digitalWrite(LED, HIGH); //LED=blink HIGH

else
digitalWrite(LED, LOW); //LED=blink LOW
}

Result: Any object detect by IR sensor automatically the LED=ON.


Otherwise LED=OFF.

***

You might also like