IIOT Prints

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.

2024-25]

const float TEMPERATURE_THRESHOLD = 23.0; // Temperature threshold in Celsius

void setup() {

// Initialize the buzzer pin as an output

pinMode(BUZZER_PIN, OUTPUT);

// Start the Serial Monitor for debugging

Serial.begin(9600);

void loop() {

// Read the temperature from the TMP36 sensor

int tempReading = analogRead(TEMP_PIN);

float voltage = tempReading * (5.0 / 1023.0);

float temperatureC = (voltage - 0.5) * 100.0;

// Print the temperature to the Serial Monitor

Serial.print("Temperature: ");

Serial.print(temperatureC);

Serial.println(" C");

// Check if the temperature exceeds the threshold

if (temperatureC > TEMPERATURE_THRESHOLD) {

// Turn on the buzzer

digitalWrite(BUZZER_PIN, HIGH);

// Print an alert message to the Serial Monitor

Serial.println("ALERT: Temperature is too high!");

} else {

// Turn off the buzzer

Department of1Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

digitalWrite(BUZZER_PIN, LOW);

// Wait for a short period before the next loop

delay(500);

Circuit Diagram –

Conclusion –

Designing a program in Tinkercad to simulate temperature alerts fosters understanding of


sensor integration, data analysis, and user notification systems. This project enhances skills in
IoT development, preparing users to create responsive and effective environmental monitoring
solutions applicable across various industries and scenarios.

Department of2Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

Connect the other end of the resistor to GND on the Arduino.

3. Breadboard Layout:

Use the breadboard to make connections more organized and ensure stable connections.

Insert the PIR sensor, LED, and resistor into the breadboard and make connections according
to the wiring instructions above.

Testing and Observations

1. Build the Circuit: Assemble the circuit on a breadboard following the wiring instructions.

2. Upload and Run the Code: Upload the provided code to the Arduino using the Arduino IDE
and start the program.

3. Observe the LED and Serial Monitor:

When motion is detected within the PIR sensor’s field of view, the LED should light up, and
the serial monitor should display "Motion detected!"

When no motion is detected, the LED will turn off, and the serial monitor will display "No
motion detected."

Source Code –

// Define pin numbers

const int pirPin = 2; // PIR sensor input pin

const int ledPin = 13; // LED output pin (built-in on many Arduino boards)

void setup() {

pinMode(pirPin, INPUT); // Set PIR pin as input

pinMode(ledPin, OUTPUT); // Set LED pin as output

Serial.begin(9600); // Initialize serial communication for debugging

void loop() {

int pirState = digitalRead(pirPin); // Read PIR sensor state

Department of3Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

if (pirState == HIGH) { // If motion is detected

digitalWrite(ledPin, HIGH); // Turn on LED

Serial.println("Motion detected!");

} else {

digitalWrite(ledPin, LOW); // Turn off LED

Serial.println("No motion");

delay(1000); // Wait for a second before rechecking

Circuit Diagram –

Conclusion –

This experiment demonstrates the integration of a PIR sensor with an Arduino to create a basic
motion detection system. The use of a PIR sensor, LED, resistor, and Arduino provides a
comprehensive understanding of digital input-output operations and practical circuit design.

Department of4Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

2. Programming the Arduino:

Write the Arduino code to read temperature data from the TMP sensor.

Develop logic to control the relay based on temperature readings and optimization criteria.

Implement algorithms to monitor energy usage and adjust device operation accordingly.

Use serial communication to output data for real-time monitoring and analysis.

3. Testing and Calibration:

Test each component individually to ensure proper operation.

Calibrate the temperature sensor and verify that the relay controls the light bulb and motor
accurately.

Validate the energy monitoring functionality and optimization algorithms.

4. Analysis and Optimization:

Analyze the data collected during tests to evaluate the performance of the optimization
algorithms.

Adjust the algorithms as needed to improve energy efficiency and system response.

5. Documentation:

Document the system design, programming details, and test results.

Prepare a report on the energy monitoring and optimization performance, including any
observed improvements in efficiency.

Source Code –

float x,y,z,temp;

void setup()

// pinMode(8, INPUT);

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

Department of5Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

pinMode(A5, INPUT);

pinMode(A4, INPUT);

Serial.begin(9600);

void loop()

// x= digitalRead(8);

y= analogRead(A5);

z= analogRead(A4);

Serial.println(x);

Serial.println(y);

Serial.println(z);

temp = (double)z / 1024;

temp = temp * 5;

temp = temp - 0.5;

temp = temp * 100;

//if ( (x>0) )

//{

if ((y<550)&&(temp>30))

digitalWrite(5, HIGH);

digitalWrite(6, HIGH);

else if((y<550)&&(temp<30))

Department of6Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

digitalWrite(5, HIGH);

digitalWrite(6, LOW);

else if((y>550)&&(temp>30))

digitalWrite(5, LOW);

digitalWrite(6, HIGH);

else if((y>550)&&(temp<30))

digitalWrite(5, LOW);

digitalWrite(6, LOW);

/*}

else

digitalWrite(5, LOW);

digitalWrite(6, LOW);

}*/

Department of7Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

Circuit Diagram -

Conclusion - This experiment provides a practical demonstration of IIoT applications for smart
home energy management. By using Arduino and various components, the system enables real-
time monitoring and optimization of energy consumption.

Department of8Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

3. Testing and Calibration:

Component Testing: Test each component individually to ensure proper operation. Check
sensor readings, authentication processes, and alert mechanisms.

Calibration: Adjust the potentiometer to calibrate sensor sensitivity levels. Verify that data
encryption and integrity verification are functioning correctly.

4. Security Analysis:

Evaluate Security Measures: Assess the effectiveness of implemented security features.


Identify any potential vulnerabilities or areas for improvement.

Document Findings: Prepare a report detailing the security measures, implementation process,
test results, and any observed issues.

Source Code –

#include <LiquidCrystal.h>

// Initialize the LCD with the pin numbers

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int V_GasSen = 0;

int V_TempSens = 0;

void setup() {

pinMode(A0, INPUT); // Gas sensor pin

pinMode(A1, INPUT); // Temperature sensor pin

pinMode(7, OUTPUT); // Buzzer pin

pinMode(9, OUTPUT); // LED for gas detection

pinMode(12, OUTPUT); // LED for temperature warning

lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows

Department of9Artificial Intelligence and Data Science ,SVCET,RAJURI


Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

void loop() {

// Read gas sensor value

V_GasSen = analogRead(A0);

// Read temperature sensor value and calculate temperature

V_TempSens = -40 + 0.488155 * (analogRead(A1) - 20);

// Display temperature and gas status on the LCD

lcd.clear(); // Clear the LCD

lcd.setCursor(0, 0); // Set cursor to the first row

lcd.print("Temperature: "); // Print temperature label

lcd.print(V_TempSens); // Print temperature value

lcd.print(" C"); // Print temperature unit

lcd.setCursor(0, 1); // Set cursor to the second row

lcd.print("Gas: "); // Print gas label

lcd.print(V_GasSen); // Print gas sensor value

// Check for alerts

if (V_GasSen >= 250) {

tone(7, 523, 1000); // Play tone if gas is detected

digitalWrite(9, HIGH); // Turn on the gas detection LED

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("ALERT: Gas Detected");

} else {

digitalWrite(9, LOW); // Turn off the gas detection LED

Department of10
Artificial Intelligence and Data Science ,SVCET,RAJURI
Computer Laboratory II B.E.AI&DS-SEM VII [A.Y.2024-25]

if (V_TempSens >= 70) {

tone(7, 523, 1000); // Play tone if temperature exceeds the threshold

digitalWrite(12, HIGH); // Turn on the temperature warning LED

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("ALERT: Temp High");

} else {

digitalWrite(12, LOW); // Turn off the temperature warning LED

delay(1000); // Delay for one second

Circuit Diagram –

Conclusion - This experiment demonstrates the implementation of security measures in an


IIoT system using Arduino and various components within Tinkercad. By integrating
authentication, authorization, encryption, data integrity verification, and monitoring, the
system provides a comprehensive approach to securing IIoT operations.

Department of11
Artificial Intelligence and Data Science ,SVCET,RAJURI
Now go to my scenarios. This is where the FORM KEY will be used. Following
my template, past this into the scenarios field to add:

?entry.1917223082=$status$&submit=Submit Change the bold text with your


FORM KEY that you gathered in step 2. Leave the ? and the other stuff, just
replace the bold with your stuff. Now copy that whole string and past into the add
scenario field. Now click ADD. Then it will say nice job! or something positive
like that. Click ADD AN ACTION. Then select the Service you created only
moments ago.

This will give you a DEsVICE ID remember this, in fact. write it down or copy
and paste it into a notepad doc. This will be used in the Arduino code.

Congrats, you are done with that and now its time to code the Arduino.

Step 4: CODE THE ARDUINO


I have attached my very simple code to run this example. You will find a section of
things to be edited. This code will send responses to the form you created in the
form of data. You will see google then creates a spreadsheet and logs all the
responses WITH time stamps! Use this to create data logs of temperature, light
levels, humidity, motion whatever you want! The example attached uses a DHT11
thermo/humidity sensor. Can easily be modified for something else.

Code:

#include <SPI.h>

#include <Ethernet.h>

#include <EthernetUdp.h>

#include <SPI.h>

#include <dht11.h>

#undef int

#undef abs

SVCET ,Rajuri Department of Artificial Intelligence and Data Science


12
#undef double

#undef float

#undef round

dht11 DHT11;

#define DHT11PIN 3

///////////////////////////////

/// EDIT THIS STUFF //

///////////////////////////////

byte mac[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; //Replace with your
Ethernet shield MAC

byte ip[] = {123,456,7,890}; // Your Arduino device IP address

char devid = v42FE15BC09B20df // THIS IS THE DEVICE ID FROM


PUSHINGBOX

int del=300; // Amount of seconds delay between posting to google docs.

///////////////////////////////

// DONE EDITING //

///////////////////////////////

SVCET ,Rajuri Department of Artificial Intelligence and Data Science


13
char postmsg[100];

int k=0;

int temp_av = 0;

char server[] = "api.pushingbox.com";

EthernetClient client;

void setup()

Serial.begin(9600);

Ethernet.begin(mac, ip);

delay(1000);

Serial.println("connecting...");

void loop(){

SVCET ,Rajuri Department of Artificial Intelligence and Data Science


14
// average temp reading for 'del' time.........................................

for(int j=0; j<del;j++)

// Read local temp........................................

int chk = DHT11.read(DHT11PIN);

int temp = Fahrenheit(DHT11.temperature);

temp_av=temp_av+temp;

delay(1000);

int avtemp=temp_av/(del);

temp_av=0;

// Post to Google Form.............................................

if (client.connect(server, 80))

k=0;

Serial.println("connected");

sprintf(postmsg,"GET /pushingbox?devid=%c&status=%d
HTTP/1.1",devid,avtemp); // NOTE** In this line of code you can see where the
temperature value is inserted into the wed address. It follows 'status=' Change that
value to whatever you want to post.

SVCET ,Rajuri Department of Artificial Intelligence and Data Science


15
client.println(postmsg);

client.println("Host: api.pushingbox.com");

client.println("Connection: close");

client.println();

Serial.println(postmsg);

Serial.println("Host: api.pushingbox.com");

Serial.println("Connection: close");

Serial.println();

delay(1000);

client.stop();

delay(1000);

if (!client.connected())

Serial.println();

Serial.println("disconnecting.");

client.stop();

k==1;

return;

SVCET ,Rajuri Department of Artificial Intelligence and Data Science


16
}

double Fahrenheit(double celsius) // Function to convert to Fahrenheit

return 1.8 * celsius + 32;

Conclusion :------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------

SVCET ,Rajuri Department of Artificial Intelligence and Data Science


17

You might also like