0% found this document useful (0 votes)
13 views17 pages

Internet of Things

ecommerce report

Uploaded by

kanchanbaniya903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views17 pages

Internet of Things

ecommerce report

Uploaded by

kanchanbaniya903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Tribhuvan University

Faculty of Humanities and Social Sciences

A LAB REPORT
Of
INTERNET of THINGS (CACS 460)

Submitted to:
Department of Computer Application
Mechi Multiple Campus

In partial fulfillment of the requirements for the Bachelors in Computer Application

Submitted by:
Pawan Adhikari (Roll no.35)
(Ashoj 2081)

Under the Supervision of


Sunil Sharma

Internal Examiner External Examiner


Lab Report for Internet of Things
Lab 1: Blink LED
i) Objectives
ii) Components Required
iii) Circuit steps
iv) Source Code
v) Connection Diagram
vi) Procedure
vii) Observation and Analysis
viii) Conclusion
Lab 2: Ultrasonic Distance Sensor (HC-SR04)
i) Objectives
ii) Components Required
iii) Circuit steps
iv) Source Code
v) Connection Diagram
vi) Procedure
vii) Observation and Analysis
viii) Conclusion
Lab 3: Buzzer Control
i) Objectives
ii) Components Required
iii) Circuit steps
iv) Source Code
v) Connection Diagram
vi) Procedure
vii) Observation and Analysis
viii) Conclusion
Lab 4: Sending Data to ThingSpeak using ThingSpeak API
i) Objectives
ii) Components Required
iii) Circuit steps
iv) Source Code
v) Connection Diagram
vi) Observation and Analysis
vii) Conclusion
Lab 5: Constructing a mini piano
i) Objectives
ii) Components Required
iii) Circuit steps
iv) Source Code
v) Connection Diagram
vi) Observation and Analysis
vii) Conclusion
Lab 6: Constructing a basic Traffic Light system
i) Objectives
ii) Components Required
iii) Circuit steps
iv) Source Code
v) Connection Diagram
vi) Observation and Analysis
vii) Conclusion
Lab 7: Reading temperature and humidity using DHT11 sensor
i) Objectives
ii) Components Required
iii) Circuit steps
iv) Source Code
v) Connection Diagram
vi) Observation and Analysis
vii) Conclusion
Lab 1: Blink LED
Objectives:
 To demonstrate basic digital output using an Arduino Uno.
 To understand the concepts of setting up pins and controlling them.
Components Required:
 Arduino board (Arduino Uno)
 LED (Light Emitting Diode)
 220-ohm resistor
 Jumper wires
Circuit Steps:
 Connect the anode (longer leg) of the LED to digital pin 13 on the Arduino.
 Connect the cathode (shorter leg) of the LED to one leg of the 220-ohm resistor.
 Connect the other leg of the resistor to the ground (GND) on the Arduino.
Source Code:
void setup() {
pinMode(13, OUTPUT); // Set pin 13 as an output
}
void loop() {
digitalWrite(13, HIGH); // Turn on the LED
delay(1000); // Wait for 1 second (1000 milliseconds)
digitalWrite(13, LOW); // Turn off the LED
delay(1000); // Wait for 1 second
}
Connection Diagram:
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 blinking an LED.
 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 the LED on the circuit. It should blink on and off with a 1-second interval.
Observation and Analysis:
We observed that the LED blinks on and off with a 1-second interval.
Conclusion:
In this experiment, we successfully demonstrated the basic concept of digital output using an
Arduino Uno. We connected an LED to a digital pin, and by controlling the state of the pin,
we were able to turn the LED on and off, creating a blinking effect. This experiment lays the
foundation for understanding how to interface and control various components using an
Arduino Uno.

Lab 2: Ultrasonic Distance Sensor (HC-SR04)


Objectives:
 To measure distance using an Ultrasonic Distance Sensor (HC-SR04) and display the
results on the Serial Monitor.
 To understand sensor interfacing and how ultrasonic sensors work.
Components Required:
 Arduino board (Arduino Uno)
 Ultrasonic Distance Sensor (HC-SR04)
 Jumper wires
Circuit Steps:
 Connect the VCC pin of the HC-SR04 sensor to 5V on the Arduino.
 Connect the GND pin of the HC-SR04 sensor to GND on the Arduino.
 Connect the TRIG pin of the HC-SR04 sensor to digital pin 2 on the Arduino.
 Connect the ECHO pin of the HC-SR04 sensor to digital pin 3 on the Arduino.
Source Code:
const int trigPin = 2; // TRIG pin of HC-SR04
const int echoPin = 3; // ECHO pin of HC-
SR04
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration;
int distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000); // Delay before next reading
}
Connection Diagram:
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 r distance measurement
using the HC-SR04 sensor.
 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.
 Open the Serial Monitor to view the distance measurements.
Observation and Analysis:
We observed that the distance values displayed in the Serial Monitor. These values represent
the distance in centimeters.
Conclusion:
In this experiment, we successfully interfaced an Ultrasonic Distance Sensor (HC-SR04)
with an Arduino to measure distances. The sensor uses ultrasonic waves to determine the
distance to an object, making it useful for applications like object detection and obstacle
avoidance. This experiment provides a practical introduction to sensor interfacing and
distance measurement using ultrasonic sensors.

Lab 3: Buzzer Control


Objectives:
 To generate different tones using a piezo buzzer controlled by an Arduino.
 To understand how to interface and control an audio output device.
Components Required:
 Arduino board (Arduino Uno)
 Piezo Buzzer
 Jumper wires
Circuit Steps:
 Connect one leg of the piezo buzzer (anode) to digital pin 8 on the Arduino.
 Connect the other leg of the piezo buzzer (cathode) to GND on the Arduino.
Source Code:
int buzzerPin = 8; // Connect the buzzer to pin 8
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
tone(buzzerPin, 1000); // Play a 1000Hz tone
delay(1000); // Delay for 1 second
noTone(buzzerPin); // Turn off the buzzer
delay(1000); // Delay for 1 second
// Play a different tone
tone(buzzerPin, 2000); // Play a 2000Hz tone
delay(1000); // Delay for 1 second
noTone(buzzerPin); // Turn off the buzzer
delay(1000); // Delay for 1 second
}
Connection Diagram:

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.

Lab 4: Sending Data to ThingSpeak using ThingSpeak API


Objectives:
 To send sensor data to ThingSpeak using the ThingSpeak API.
 To demonstrate the process of interfacing with cloud platforms for data logging.
Components Required:
 Computer with internet connection
 ThingSpeak Account
Steps:
 Log in to ThingSpeak account.
 Create a new channel and note down the Channel ID.
 Set up the necessary fields (Field1 for temperature) for channel.
 Create a CSV file named temperature_data.csv with two columns: timestamp and
sensor_value.
 Fill in the CSV file with sample data.
 Write the provided Python code for sending data to ThingSpeak and execute.
Source Code:
import csv
import requests
import time
# Read the CSV file
with open('temperature_data.csv', 'r') as file:
csv_data = csv.reader(file)
next(csv_data) # Skip the header row
for row in csv_data:
# Extract data from the row
timestamp = row[0]
sensor_value = row[1]
# Prepare the data for ThingSpeak API
api_key = 'DOHGA51CEF3GYHLF'
api_url = 'https://api.thingspeak.com/update'
payload = {
'api_key': api_key,
'field1': sensor_value,
'field2': timestamp
}
# Make an HTTP POST request to ThingSpeak
API response = requests.post(api_url,
json=payload)
# Check the response status
if response.status_code == 200:
print('Data sent successfully.')
else:
print('Failed to send data:', response.text)
# Wait for 15 seconds before sending the next request
time.sleep(15)
Connection Diagram:
Observation and Analysis:
We observed the console output to see if the data is sent successfully or if there are any
errors.
Conclusion:
In this experiment, we successfully demonstrated how to send sensor data to ThingSpeak, a
cloud platform, using the ThingSpeak API. This process allows for remote monitoring and
storage of sensor data in a cloud environment, enabling various applications such as data
analysis, visualization, and more.
Lab 5: Constructing a Mini Piano
Objectives:
 To construct a mini piano using an Arduino Uno microcontroller.
 To learn the basics of interfacing buttons with an Arduino.
 To understand the concept of tone generation using PWM.
 To create a musical instrument that can play simple melodies.
Components Required:
 Arduino Uno microcontroller
 Jumper wires
 Push buttons (8)
 Piezo buzzer
Circuit Steps:
 Connect the positive pin of the piezo buzzer to pin 8 on the Arduino.
 Connect the negative pin of the buzzer to ground.
 Connect one leg of each push button to digital pins on the Arduino
 Connect one leg of the each push button to the ground.

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:

Observation and Analysis:


We observed the piezo buzzer's behavior when buttons were pressed and analyzed the relationship
between buttons and frequencies. We evaluated the quality of musical notes and identified potential
design flaws.
Conclusion:
The project successfully achieved its goals of creating a mini piano using an Arduino and
demonstrating button interfacing, tone generation, and musical note production. While encountering
challenges, the project provided valuable educational insights and opportunities for further
exploration.

Lab 6: Constructing a basic Traffic Light system


Objective:
To create a functional traffic light system using an Arduino microcontroller.
Components Required:
 Arduino Uno microcontroller
 Breadboard
 Jumper wires
 LEDs (red, yellow, green)
Circuit Steps:
 Place the red, yellow, and green LEDs in different rows of the breadboard.
 Connect the long leg (anode) of the red LED to pin 9 on the Arduino.
 Connect the long leg (anode) of the yellow LED to pin 8 on the Arduino.
 Connect the long leg (anode) of the green LED to pin 7 on the Arduino.
 Connect the short leg (cathode) of the red LED to GND on the Arduino.
 Connect the short leg (cathode) of the yellow LED to GND on the Arduino.
 Connect the short leg (cathode) of the green LED to GND on the Arduino.
Source Code:
// Define pins for the LEDs
int redLED = 9;
int yellowLED = 8;
int greenLED = 7;
void setup() {
// Initialize the digital pins as outputs
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
void loop() {
// Red light on for 5 seconds
digitalWrite(redLED, HIGH);
delay(5000);
digitalWrite(redLED, LOW);
// Green light on for 5 seconds
digitalWrite(greenLED, HIGH);
delay(5000);
digitalWrite(greenLED, LOW);
// Yellow light on for 2 seconds (warning)
digitalWrite(yellowLED, HIGH);
delay(2000);
digitalWrite(yellowLED, LOW);
}
Connection Diagram:

Observation and Analysis:


We observed that the red, yellow, and green LEDs lit up sequentially, correctly simulating a
traffic light system based on the programmed Arduino code. The timing intervals and
transitions worked as expected, the omission of resistors was identified as a key design flaw.
Conclusion:
The project successfully demonstrated the basic concept of a traffic light system using an Arduino,
with proper timing and LED control. The project achieved its goals of simulating a traffic light
sequence, showcasing how to control multiple LEDs and introduce basic automation. The project
provided valuable educational insights into circuit design, current management, and timing control.

Lab 7: Reading temperature and humidity using DHT11 sensor


Objective:
 To measure and display temperature and humidity values using the DHT11 sensor and
Arduino Uno.
 To demonstrate how to interface the DHT11 sensor with the Arduino without using
resistors in the circuit.
Components Required:
 Arduino Uno
 DHT11 Sensor
 Jumper wires
 Breadboard
 USB Cable
Circuit Steps:
 Connect the power pin (VCC) of the DHT11 sensor to the 5V pin on the Arduino.
 Connect the ground pin (GND) of the DHT11 sensor to the GND pin on the Arduino.
 Connect the data pin (DATA) of the DHT11 sensor to a digital pin on the Arduino
(e.g., pin 2).
Source Code:
#include "DHT.h"
#define DHTPIN 2 // Pin where the DHT11 is connected
#define DHTTYPE DHT11 // Define DHT type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHT11 Sensor Test");
dht.begin();
}
void loop() {
delay(2000); // Wait a few seconds between measurements
// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
float temperature = dht.readTemperature(); // Temperature in Celsius
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print temperature and humidity
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
}
Connection Diagram:

Observation and Analysis:


The DHT11 sensor measures temperature and humidity within its specified accuracy, though
without a pull-up resistor, occasional erratic readings may occur due to environmental factors
or wire length. While the sensor has a limited sampling rate and precision, its readings
generally stabilize after a few measurements, remaining within acceptable ranges for basic
applications.
Conclusion:
The DHT11 sensor can be reliably used with an Arduino Uno to measure temperature and
humidity without requiring external resistors, though a pull-up resistor improves
communication stability. This project is a simple and effective way to learn sensor interfacing
and environmental monitoring using Arduino.

You might also like