Internet of Things
Internet of Things
A LAB REPORT
Of
INTERNET of THINGS (CACS 460)
Submitted to:
Department of Computer Application
Mechi Multiple Campus
Submitted by:
Pawan Adhikari (Roll no.35)
(Ashoj 2081)
Procedure:
Set up the circuit as per the provided circuit steps.
Open the Arduino IDE on your computer.
Create a new sketch and paste the provided Arduino code for generating tones with a
piezo buzzer.
Connect Arduino board to your computer using a USB cable.
Select the correct board and port (Arduino Uno) in the Arduino IDE.
Upload the code to the Arduino.
Observe and listen to the piezo buzzer. It will generate different tones.
Observation and Analysis:
We observed that Note of the different frequencies of the tones generated by the piezo
buzzer.
Conclusion:
In this experiment, we successfully controlled a piezo buzzer using an Arduino. By varying
the frequency and duration of the tones, we were able to create different musical notes. This
experiment demonstrates how to interface and control an audio output device, which can be
used for various applications including alarms, melodies, and more.
Source Code:
#include "pitches.h"
#define SPEAKER_PIN 8
const uint8_t buttonPins[] = { 12, 11, 10, 9, 7, 6, 5, 4 };
const int buttonTones[] = {
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,
NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5
};
const int numTones = sizeof(buttonPins) / sizeof(buttonPins[0]);
void setup() {
for (uint8_t i = 0; i < numTones; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
pinMode(SPEAKER_PIN, OUTPUT);
}
void loop() {
int pitch = 0;
for (uint8_t i = 0; i < numTones; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
pitch = buttonTones[i];
}
}
if (pitch) {
tone(SPEAKER_PIN, pitch);
} else {
noTone(SPEAKER_PIN);
}
}
Connection Diagram: