Iot Record
Iot Record
Iot Record
To avoid any error while uploading your program to the board, you must select the correct
Arduino board name, which matches with the board connected to your computer.
Here, we have selected Arduino Uno board according to our tutorial, but you must select the
name matching the board that you are using.
Go to Tools → Serial Port menu. This is likely to be COM3 or higher (COM1 and COM2 are
usually reserved for hardware serial ports). To find out, you can disconnect your Arduino
board and re-open the menu, the entry that disappears should be of the Arduino board.
Reconnect the board and select that serial port.
Before explaining how we can upload our program to the board, we must demonstrate the
function of each symbol appearing in the Arduino IDE toolbar.
Now, simply click the "Upload" button in the environment. Wait a few seconds; you will see
the RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done
uploading" will appear in the status bar.
Raspberry Pi Installation
REQUIRED ITEMS
● A Raspberry Pi (Either a Model B or Model B+)
● SD Card
o We recommend an 8GB class 4 SD card.
● Display and connecting cables
o Any HDMI/DVI monitor or TV should work as a display for the Pi.
o For best results, use one with HDMI input, but other connections are available for
older devices.
● Keyboard and mouse
o Any standard USB keyboard and mouse will work with your Raspberry Pi.
● Power supply
o Use a 5V micro USB power supply to power your Raspberry Pi. Be careful that
whatever power supply you use outputs at least 5V; insufficient power will cause
your Pi to behave unexpectedly.
● Internet connection
o To update or download software, we recommend that you connect your Raspberry
Pi to the internet either via an Ethernet cable or a WiFi adaptor.
● Sound
o Headphones, earphones or speakers with a 3.5mm jack will work with your
Raspberry
WiringPi is maintained under GIT for ease of change tracking, however there is a Plan B if
you’re unable to use GIT for whatever reasons (usually your firewall will be blocking you, so
do check that first!)
ONLINE INSTALL
If you do not have GIT installed, then under any of the Debian releases (e.g. Raspbian), you
can install it with:
sudo apt-get install git-core
If you get any errors here, make sure your Pi is up to date with the latest versions of
Raspbian:
sudo apt-get update
sudo apt-get upgrade
If you have already used the clone operation for the first time, then
cd wiringPi
git pull origin
Will fetch an updated version then you can re-run the build script below.
cd wiringPi
./build
The new build script will compile and install it all for you – it does use the sudo command at
one point, so you may wish to inspect the script before running it.
voidloop() {
// put your main code here, to run repeatedly:
digitalWrite(3,HIGH); //we can also write digitalWrite(3,1);
delay(1000);
digitalWrite(3,LOW);//we can also write digitalWrite(3,0);
delay(1000);
}
Output:LED will turn on for 1 sec after every 2 seconds by interfacing LED with Arduino.
Experiment 3
Aim: To interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry Pi and
write a program to turn ON LED when push button is pressed or at sensor
detection.
Requirements:
1. Standard 5mm LED
2. Two Resistors
3. Arduino Uno microcontroller board (ATmega328p)
4. Jumper wires
5. Push button
Procedure:
Step 1: Open www.wokwi.com in browser and select “Arduino Uno” microcontroller.
Step 2: In the Simulation part, select the above list by clicking “+” symbol, which are specified
in above requirements.
Step 3: By using jumper wires, Connect Anode (A-pin) of LED to digital pin 3 of Arduino
microcontroller through the resistor1 and Cathode (C-pin) of LED to ground.
Step 4: Give 5volt power supply to pushbutton 1:1L pin.
Step 5: Connect pushbutton 1:1R to both GND through resistor2& digital pin5.
Step 6: Write program in “sketch.ino”.
Program:
int flag=0;
voidsetup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(5, INPUT);
}
voidloop() {
// put your main code here, to run repeatedly:
int value=digitalRead(5);
if(value==1&& flag==0)
{
digitalWrite(3,HIGH);
delay(1000);
flag=1;
}
elseif(value==1&& flag==1)
{
digitalWrite(3,LOW);
delay(1000);
flag=0;
}
}
Output:When push button is pressed, LED will be turned ON by interfacing Push button with
Arduino.
Experiment 4
Aim:To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to
print temperature and humidity readings
Requirements:
1. DHT22 sensor
2. Arduino Uno microcontroller board (ATmega328p)
3. Jumper wires
Procedure:
Step 1: Open www.wokwi.com in browser and select “Arduino Uno” microcontroller.
Step 2: In the Simulation part, select the above list by clicking “+” symbol, which are specified
in above requirements.
Step 3:
By using jumper wires,
i. Give 5 volts power to pin dht1:VCC of DHT22 sensor
ii. Connect dht1:SDA pin of DHT22 sensor to digital pin3 of Arduino Uno
microcontroller board (ATmega328p)
iii. Connect dht1: GND pin of DHT22to ground of microcontroller board.
Step 4: Write program in “sketch.ino”.
Program:
#include<Adafruit_Sensor.h>
#include<DHT.h>
#include<DHT_U.h>
DHT Sensor(3,DHT22);
voidsetup() {
// put your setup code here, to run once:
Sensor.begin();
Serial.begin(9600);
}
voidloop() {
// put your main code here, to run repeatedly:
floattempr = Sensor.readTemperature();
Serial.print("Temperature = ");
Serial.print(tempr);
Serial.print(", ");
delay(1000);
float humid = Sensor.readHumidity();
Serial.print("Humidity = ");
Serial.println(humid);
}
Output:Temperature and Humidity readings are display by interfacing DHT22 sensor with
Arduino.
Experiment 5
Aim: To interface OLED with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings on it.
Requirements:
1. DHT22 sensor
2. Arduino Uno microcontroller board (ATmega328p)
3. Jumper wires
4. SSD1306 OLED display
Procedure:
Step 1: Open www.wokwi.com in browser and select “Arduino Uno” microcontroller.
Step 2: In the Simulation part, select the above list by clicking “+” symbol, which are specified
in above requirements.
Step 3:
By using jumper wires,
I. Give 5 volts power to pin dht1:VCC
II. Connect dht1: SDA to digital pin3 of Arduino Uno microcontroller board
(ATmega328p)
III. Connect dht1: GND to ground.
IV. Make connections between
● Oled1:DATA toAnalog pin A4
● Oled1:CLK toAnalog pin A5
● Oled1:VIN to 5 volt power
● Oled1:GND to ground
Step 4: Write program in “sketch.ino”.
Note:Download libraries Adafruit SSD1306 and DHT sensor library.
Program:
#include<Adafruit_Sensor.h>
#include<Adafruit_GFX.h>
#include<Adafruit_SSD1306.h>
#include<DHT.h>
#include<DHT_U.h>
#include<Wire.h>
Adafruit_SSD1306 display(128,64,&Wire);
DHT Sensor(3,DHT22);
voidsetup() {
// put your setup code here, to run once:
Sensor.begin();
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC,0X3C);
display.setTextColor(WHITE);
}
voidloop() {
// put your main code here, to run repeatedly:
floattempr= Sensor.readTemperature();
float humid= Sensor.readHumidity();
display.setCursor(0,10);
display.setTextSize(1);
display.print("Temperature= ");
display.println(tempr);
display.print("Humidity= ");
display.println(humid);
display.display();
delay(500);
display.clearDisplay();
}
Output: Temperature and Humidity readings are display on OLED by interfacing DHT22
sensor with Arduino.
Experiment 6
Aim: To interface Bluetooth with Arduino/Raspberry Pi and write a program to send
sensor data to smartphone using Bluetooth.
Step 1: Open “MIT App Inventor” in Google Chrome
Step 2: Click on “Create Apps!” button
Step 6: Click on the link which is generated through scanning QR Code in our mobile and
install “LED_Blink”app.
Step 7: Now we can operate to turn LED ON/OFF when ‘1’/’0’ is received from smartphone
using Bluetooth.
Output:
Experiment 8
Aim: Write a program on Arduino/Raspberry Pi to upload temperature and humidity
data to thingspeak cloud
Procedure:
Step 1: Open Arduino Interface and type program
Program:
#include <DHT.h>
#include <DHT_U.h>
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
const char *ssid="xxxxxxx"; // your network SSID (name)
const char *pass="xxxxxxx"; // your network password
void loop() {
// put your main code here, to run repeatedly:
floattempr = Sensor.readTemperature();
float humid = Sensor.readHumidity();
ThingSpeak.setField(1,tempr);
ThingSpeak.setField(2,humid);
int x=ThingSpeak.writeFields(chid,key);
if(x == 200)
{Serial.println("Channel update successful.");
}
else{Serial.println("Problem updating channel HTTP error code " + String(x));
delay(15000);}
}
Step 2: Save the program
Step 3:
⮚ Create “Thingspeak”account ( https://thingspeak.com )
⮚ Login into “Thingspeak” account and click on “New Channel” button.
⮚ Enter Experiment name in Channel Name field.
⮚ Enter “Temperature” in Field1.
⮚ Enter “Humidity” in Field2.
⮚ Click on “Save Channel”
Step 4: Open program in Arduino Interface
Step 5: click on compile button.
Step 6: Using USB cable connect Arduino board to device.
Step 7: Open Device Manager in device and select ports.
Step 8: Now click on Tools option in Arduino interface and select available port
COM6/COM5/COM4/COM3
Step 9: Click upload button
Step 10: Click on Serial Monitor
Output:
Procedure:
Step 1: Open Arduino Interface and type program
Program:
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
const char ssid[] = "xxxxxxx"; // your network SSID (name)
const char pass[] = "xxxxxxx"; // your network password
WiFiClient client;
//---------Channel Details---------//
unsigned long counterChannelNumber = 1648756; // Channel ID
const char * myCounterReadAPIKey = "ODGH1JHLPGDUG39W"; // Read API Key
constint FieldNumber1 = 1; // The field you wish to read
constint FieldNumber2 = 2; // The field you wish to read
//-------------------------------//
void setup()
{
Serial.begin(9600);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop()
{
//----------------- Network -----------------//
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println(" ....");
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
delay(5000);
}
Serial.println("Connected to Wi-Fi Succesfully.");
}
//--------- End of Network connection--------//
Output:
4. Now please execute the following command for secure installation which is shown
below.
sudomysql_secure_installation
13. Please execute the following command to see databases present in the mysql database.
show databases;
14. Execute the following to create Demo database in mysql server which is shown
below.
CREATE DATABASE Demo;
19. Now please execute the following command to come out of database.
quit
Follow the following steps to insert and fetch from the MySQL database.
1. Open the raspberry pi terminal.
2. Execute the following command to login to the database and enter the password which is
shown below.
sudomysql -u root –p
3. Execute the following command to use Demo database which is shown above.
USE Demo;
Output: MariaDB [(none)]> use Demo
Database changed
4. Execute the following command to create login table which has two coloumsi.e is
username and password which is shown above.
create table login(username varchar(25), password varchar(25));
Output: MariaDB [Demo]> create table data(snoint(11), temp varchar(25), hum
varchar(25));
Query OK, 0 rows affected (0.06 sec)
5. Execute the following command to insert data into login table which is shown below.
insert into login values(‘admin’,’admin123′);
6. To see the inserted values please execute the following command which is shown below
select * from login;
client=Client("Device1")
c=client.connect('broker.hivemq.com',1883)
if c==0:
print('client connected')
while True:
hum,temp=Adafruit_DHT.read_retry(11,4)
print('Temperature:',temp)
print('Humidity:', Hum)
message='temp='+str(temp)+",hum="+str(hum)
client.publish('iotdata',message)
time.sleep(2)
Output:
pi@raspberrypi:~ $ cd iot
pi@raspberrypi:~/iot $ python3 dhtpublish.py
client connected
Temperature: 28.0
Humidity: 95.0
Temperature: 29.0
Humidity: 94.0
Temperature: 28.0
Humidity: 94.0
Temperature: 29.0
Humidity: 95.0
Temperature: 28.0
Humidity: 94.0
Temperature: 29.0
Humidity: 94.0
Temperature: 28.0
Humidity: 93.0
Program:
import sys
importAdafruit_DHT
import time
frompaho.mqtt.client import *
defon_message(client,userdata,msg):
print('Channel:',msg.topic)
message=str(msg.payload.decode('utf-8'))
print('Message: ',message)
hum,temp=Adafruit_DHT.read_retry(11,4)
t='temp='+str(temp)
h='hum='+str(hum)
if message=='Temperature':
client.publish('iotdata',t)
if message=='Humidity':
client.publsih('iotdata',h)
client=Client("Device1")
c=client.connect('broker.hivemq.com',1883)
if c==0:
print('client connected')
client.subscribe('iot')
client.on_message=on_message
client.loop_forever()
Output:
python3 dht.py
client connected
channel: iotnew
Message: Temperature
28.0
channel: iotnew
Message: Humidity