0% found this document useful (0 votes)
4 views6 pages

Lab 6

The document outlines two tasks for an Internet of Things lab project. Task 1 involves designing an alarm system using a force sensor and buzzer to detect package damage, while Task 2 focuses on developing a smoke detection system for a building with three floors that sends real-time data to the ThingSpeak IoT platform. Both tasks include detailed algorithms and code implementations for the respective systems.

Uploaded by

adityashinde9620
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)
4 views6 pages

Lab 6

The document outlines two tasks for an Internet of Things lab project. Task 1 involves designing an alarm system using a force sensor and buzzer to detect package damage, while Task 2 focuses on developing a smoke detection system for a building with three floors that sends real-time data to the ThingSpeak IoT platform. Both tasks include detailed algorithms and code implementations for the respective systems.

Uploaded by

adityashinde9620
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/ 6

ICS-423 Internet of Things

Lab-6

Name: Kanak Khandelwal


Roll No.: 2021BCS0012

Task 1: Design an alarm system that triggers warning if a package gets damaged. Use
force sensor and a buzzer alarm.

Algorithm

1. Initialize Components

 Define force sensor pin (Analog A0).


 Define buzzer pin (Digital 9).
 Define LED pin (Digital 7).
 Set the threshold value for the force sensor.

2. Setup Function (Runs Once)

 · Start the Serial Monitor for debugging.


 Set LED and Buzzer as OUTPUT.

3. Loop Function (Repeats Continuously)

 Read the force sensor value from A0.


 Print the sensor value to the Serial Monitor.
 Compare the sensor value with the threshold:

o If the value is greater than the threshold:


 Turn ON the LED.
 Turn ON the Buzzer.
o Else:

 Turn OFF the LED.


 Turn OFF the Buzzer.

 Add a small delay for stability.

Code

const int forceSensorPin = A0;


const int buzzerPin = 9;
const int ledPin = 7;
const int threshold = 400;
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
int sensorValue = analogRead(forceSensorPin);
Serial.println(sensorValue);

if (sensorValue > threshold) {


digitalWrite(buzzerPin, HIGH);
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
}

delay(100);
}

Output

The alarm and the LED bulb are off when the force applied is below the threshold.

The alarm rings and the LED bulb glows when the force crosses the threshold limit.
Task 2: Develop a smoke detecting system for a building consisting of three floors.
Notify the real-time value of the floors to thingspeak IoT cloud platform.

Algorithm

1. Initialize Components:

 Start Serial Communication at 115200 baud.


 Connect ESP8266 to WiFi using AT+CWJAP.
 Set up pin modes:
o A0, A1, A2 → Smoke sensors for Floors 1, 2, and 3.
o Pin 7 → Buzzer.

2. Read Sensor Data:

 Collect readings from A0, A1, and A2.


 Display sensor values on the Serial Monitor.

3. Send Data to ThingSpeak:

 Establish a TCP connection using AT+CIPSTART.


 Construct an HTTP GET request including the API key and sensor values.
 Transmit the request using AT+CIPSEND.

4. Activate Buzzer on High Smoke Detection:

 If any sensor reading exceeds 85, activate the buzzer (tone(7, 1000)).
 Otherwise, turn OFF the buzzer (noTone(7)).

5. Close Connection & Repeat:

 Terminate the TCP connection using AT+CIPCLOSE.


 Wait 10 seconds (due to ThingSpeak's free-tier limit).
 Repeat the process continuously.
Code

int val1 = 0, val2 = 0, val3 = 0;

void setup() {
delay(100);
Serial.begin(115200);

Serial.println("AT+CWJAP=\"Simulator Wifi\",\"\"\r\n");
delay(3000);

pinMode(7, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}

void loop() {
val1 = analogRead(A0);
val2 = analogRead(A1);
val3 = analogRead(A2);

Serial.print("Floor 1 Smoke: "); Serial.println(val1);


Serial.print("Floor 2 Smoke: "); Serial.println(val2);
Serial.print("Floor 3 Smoke: "); Serial.println(val3);
delay(1000);

Serial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\r\n");
delay(3000);

String request = "GET /update?api_key=7FMOOFSORT938HZF&field1=";


request += String(val1) + "&field2=" + String(val2) + "&field3=" + String(val3);

Serial.print("AT+CIPSEND=");
Serial.println(request.length() + 2);
delay(1000);
Serial.print(request);
delay(1000);

if (val1 > 85 || val2 > 85 || val3 > 85) {


tone(7, 1000);
} else {
noTone(7);
}

Serial.println("AT+CIPCLOSE=0\r\n");
delay(10000);
}

Output

Simulation

Graph visualization on ThingSpeak

You might also like