Iot Remaining Experiment
Iot Remaining Experiment
Experiment-6
OBJECTIVE: To interface motor using relay with Arduino/Raspberry Pi and write a program to turn
ON motor when Push-button is pressed.
RESOURCE REQUIRED: Tinkercad
THEORY:
CODE:
The intention behind the project is to explain how a microcontroller (in this case, an Arduino) can be used
to control a high voltage and high current devices using a relay. When the system is powered on, the
Arduino waits for the button to be pressed (as per the code written). The button terminal is pulled up
internally. Hence, when the button is pushed, the Arduino detects Logic 0 (LOW).This will send a Logic
1 (HIGH) signal to Pin 7,which is connected to the base of the transistor. As a result, the transistor is
switched ON. As one of thecoil terminals of the relay is connected to the collector of the transistor (which
is switched ON), a conduction path between the supply, coil and collector – emitter terminals of transistor
is formed. Because of this, the coil in the relay gets energized and acts as an electromagnet. As a result, the
movingcontact of the coil, which was initially in the Normally Closed (NC) position, will be attracted
towardsthe electromagnet and moves to the Normally Open (NO) position. This action will complete the
motor circuit and hence, the motor starts rotating. The motor keeps on rotating as long as the button is
pushed.Once the button is released, the transistor is switched OFF and the coil in the relay is de energized.
Hence, the contact goes back to the Normally Closed position and the motor is turned OFF.
CIRCUIT DIAGRAM
Pankaj Kumawat (20EC41)
OBSERVATIONS:
When pushbutton is pressed, then the motor rotates due to amount of current provided required to turn
on relay by the pushbutton.
RESULT:
Continuous motor operation with a momentary start switch is possible if a
Normally-open―seal-in‖ contact from the contactor is connected in parallel with the start switch so that
once the contactor is energized it maintains power to itself and keeps itself latched on. Time delay relays
are commonly used in large motor controlcircuits to prevent the motor from being started (or reversed)
until a certain amount of time has elapsed from an event.
Pankaj Kumawat (20EC41)
EXPERIMENT-7
THEORY:
Miniature OLED display modules are a great way to add a small screen to your
Raspberry Pi projects. They are available in various sizes but common sizes include
128×32 and 128×64 pixels. The cheaper ones have single colour pixels that are either
white, yellow or blue.
We connected them directly to the Raspberry Pi‟s GPIO header using the following
scheme :
OLED Pin Pi GPIO Pin Notes
Vcc 1* 3.3V
Gnd 14 ** Ground
SCL 5 I2C SCL
SDA 3 I2C SCA
We can connect the Vcc pin to either Pin 1 or 17 as they both provide 3.3V. We can connect the Gnd
pin to either Pin 6, 9, 14 , 20, 25, 30, 34 or 39 as they all provide Ground.
Enable I2C Interface
The I2C interface is disabled by default so you need to enable it. You can do this
within the raspi-config tool on the command line by running :
sudo raspi-config
The following libraries may already be installed but run these commands anyway to
make sure:
Pankaj Kumawat (20EC41)
Circuit Diagram :
Pankaj Kumawat (20EC41)
RASPBERRY PI CODE:
import time
import Adafruit_GPIO.I2C as I2C
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
# Raspberry Pi pin configuration:
RST = 0
# Note the following are only used with SPI:
#DC = 23
#SPI_PORT = 0
#SPI_DEVICE = 0
# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0
# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
# Initialize library.
disp.begin()
# Clear display.
disp.clear()
disp.display()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
draw = ImageDraw.Draw(image)
padding = 2
shape_width = 20
top = padding
bottom = height-padding
# Move left to right keeping track of the current x position for drawing shapes.
x = padding
# Load default font.
font = ImageFont.load_default()
draw.text((x, top), 'Hello', font=font, fill=255,)
draw.text((x, top+10), 'IOT LAB', font=font, fill=255)
# Display image.
disp.image(image)
disp.display()
Pankaj Kumawat (20EC41)
OBSERVATIONS:
RESULT:
We have understood the working of OLED SSD 1306 and how to interface it
with Raspberry Pi. Results are verified by varying the text of display.
Pankaj Kumawat (20EC41)
EXPERIMENT-8
THEORY: In this experiment, the temperature request can be sent to the Arduino at any
time. It also has a feedback system. The command is sent wirelessly to the Arduino Uno,
the Arduino once receive the command then replay back with the temperature
and humidity values. Here, DHT11 temperature and humidity module are used for
monitoring the temperature and humidity.
The data pin of the DHT11 sensor is connected with the Arduino‟s digital pin. While
the power supply pins are connected with the Arduino‟s 5V and GND pins.
The Bluetooth module HC-05 or HC-06 is connected with the Arduino‟s pins 0 and 1.
The RX pin of the Bluetooth module is connected with the Arduino‟s pin TX. The TX
pin of the Bluetooth module is connected with Pin RX of the Arduino Board, while the
Power supply pins are connected with the Arduino‟s power supply.
The android phone connects via Bluetooth interface with a transmitter section having
the sensor circuit. For this purpose, HC-05 Bluetooth module is being used. The sensor
used in the project is DHT-11 which relays ambient temperature and humidityvalues
to the microcontroller. The microcontroller digitizes the sensor readings using inbuilt
ADC and send them to Android phone via Bluetooth.
On the Android phone, an app Bluetooth Serial Control is used. This app can read
data over the Bluetooth interface like a serial monitor application on the desktop
computer. The serially read data is displayed within the main activity of the app.
On the transmitter side, the DHT 11 temperature and humidity sensor are interfaced
to an Arduino Uno. The Arduino board reads data from the temperature sensor, digitize
it and transmit it through the Bluetooth module. The Arduino sketch is written on
Arduino IDE and burnt to the board. Smartphone display the received sensor on a
terminal window of the app.
Pankaj Kumawat (20EC41)
CIRCUIT DIAGRAM:
ARDUINO CODE:
#include <DHT.h>
#define DHTPIN 6 // The data pin of DHT11/DHT22 should be connected to the
digtal pin 9 of Arduino.
#define DHTTYPE DHT22
DHT dht ( DHTPIN, DHTTYPE ) ;
char val;
void setup ( ) { // Void setup is the function which technically created at the top of
the program. It is used to initialize variables, pin modes, start using libraries, etc.
Serial.begin ( 9600 ) ;
dht.begin ( ) ;
}
void loop ( ) { // The loop is ran again and again and consists the main code.
float humidity = dht.readHumidity ( ) ;
float Temprature = dht.readTemperature ( ) ;
if ( isnan ( Temprature ) || isnan ( humidity ) ) {
Serial.println ( " Sensor is not avaliable right now " ) ; }
else
{ Serial.print ( " Temprature is " ) ;
Serial.print ( Temprature ) ;
Serial.println ( " *C " ) ;
delay(2000);
Serial.print ( " Humidity in % is : " ) ;
Serial.print ( humidity ) ;
Serial.print ( " % \t " ) ;
}
}
OBSERVATION:
RESULT:
The Bluetooth device and DHT 11 sensor have been interfaced with
Arduino Uno successfully and sent sensor data to smart phone.
Pankaj Kumawat (20EC41)
EXPERIMENT-9
OBJECTIVE: To interface Bluetooth with Arduino/Raspberry Pi and write a
program to turn LED ON/OFF when 1„/„0„ is received from smartphone using
Bluetooth.
THEORY:
HC 05/06 works on serial communication. The Android app is designed to send serial
data to the Arduino Bluetooth module when a button is pressed on the app. The
Arduino Bluetooth module at the other end receives the data and sends it to the
Arduino through the TX pin of the Bluetooth module (connected to RX pin of
Arduino). The code uploaded to the Arduino checks the received data and compares
it. If the received data is 1, the LED turns ON. The LED turns OFF when the received data is 0. We can
open the serial monitor and watch the received data while connecting.
There are three main parts to this project. An Android smartphone, a Bluetooth
transceiver, and an Arduino.
CIRCUIT:
ARDUINO CODE:
#define LED 8
char val;
void setup()
{
pinMode(LED , OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{
val = Serial.read();
switch(val)
{
case '1': digitalWrite(8, HIGH);break; // when 1 is pressed on the app on
your smart phone
case '2': digitalWrite(8, LOW);break; // when 2 is pressed on the app on
your smart phone
case '3': digitalWrite(8, HIGH);break; // when 3 is pressed on the app on
your smart phone
case '4': digitalWrite(8, LOW);break; // when 4 is pressed on the app on
your smart phone
default : break;
}
Serial.println(val);
}
delay(50);
Pankaj Kumawat (20EC41)
}
{
case '1': digitalWrite(8, HIGH);break; // when 1 is pressed on the app on
your smart phone
case '2': digitalWrite(8, LOW);break; // when 2 is pressed on the app on
your smart phone
case '3': digitalWrite(8, HIGH);break; // when 3 is pressed on the app on
your smart phone
case '4': digitalWrite(8, LOW);break; // when 4 is pressed on the app on
your smart phone
default : break;
}
Serial.println(val);
}
delay(50);
}
RESULT:
The Bluetooth device and LED have been interfaced with Arduino Uno and LED has
been operated using smart phone. In this way, we can control the devices using
smartphone wirelessly.
Pankaj Kumawat (20EC41)
EXPERIMENT-10
OBJECTIVE: Write a program on Arduino/Raspberry Pi to upload temperature
and humidity data to thingspeak cloud.
THEORY:
DHT22 sensor will collect the temperature and humidity data and send it to
Raspberry Pi. Later Raspberry Pi will send it to Thingspeak channel.
Before starting, you need a ThingSpeak account. Create an account by clicking on this
link here. After creating the account login and click on New Channel to create a
channel.
Once we have saved the channel, we will be automatically redirected to the “Private
View” tab. Here the mapped fields are shown as a diagram. We will find the
“Channel ID” (we will need it later). Below we will also see API Keys option.
Later, click on the “API Keys” tab. The two values of “Write API key” and “Read
API key” are equally necessary for us to write or retrieve data. Copy these keys and
keep it safe as we need to put it in the code.
Pankaj Kumawat (20EC41)
Connection Diagram
This is how we have to make the connection with the sensor to the Pi board. Data or
signal pin of DHT11 sensor is connected with GPIO 4 with Raspberry Pi.
CIRCUIT DIAGRAM:
RASPBERRY PI CODE:
from time import sleep
import Adafruit_DHT
from urllib.request import urlopen
myAPI_key = "KROC48HI5D3YIDLX" # your Write API Key
Pankaj Kumawat (20EC41)
OBSERVATION:
RESULT:
Account is created on thingspeak cloud and got API Key successfully.
Temperatureand humidity data have been uploaded on thingspeak successfully.
Pankaj Kumawat (20EC41)
EXPERIMENT-11
THEORY:
DHT22 sensor will collect the temperature and humidity data and send it to Raspberry Pi. Later
Raspberry Pi will send it to Thingspeak channel.
“EXACTLY SAME THEORY AS PREVIOUS EXPERIMENT”
CIRCUIT DIAGRAM:
RASPBERRY PI CODE:
import json
from urllib.request import urlopen
READ_API_KEY='0WTY8S1HC2UP74
G4'
CHANNEL_ID=1329570
def main():
conn = urlopen("http://api.thingspeak.com/channels/%s/feeds/last.json?api_key=%s" \
% (CHANNEL_ID,READ_API_KEY))
response = conn.read() print( "http status code = %s" % (conn.getcode()))
data=json.loads(response)print (data['field1'],data['created_at'])
print (data['field2'],data['created_at'])
conn.close() if name == ' main ':
main()OBSERVATION:
RESULT:
Temperature and humidity data have been downloaded from thingspeak successfully.
Pankaj Kumawat (20EC41)
EXPERIMENT-12
RESULT:
MySQL database has been installed successfully and performed queries.
Pankaj Kumawat (20EC41)
EXPERIMENT-13
OBJECTIVE: Write a program to create UDP server on Arduino/Raspberry Pi and
respondwith humidity (or any string) data to UDP client when requested.
Code:
## We import the necessary socket python
moduleimport socket
## Here we define the UDP IP address as well as the port number that we
have## already defined in the client python script.
UDP_IP_ADDRESS = "192.168.43.254"
UDP_PORT_NO = 6789
## declare our serverSocket upon
which ## we will be listening for UDP
messages
serverSock = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)## One difference is that we will have to
bind our declared IP address ## and port number to our newly
declared serverSock serverSock.bind((UDP_IP_ADDRESS,
UDP_PORT_NO))
while True:
data, addr =
serverSock.recvfrom(1024)
print("Message: ", data)
Client Code:
import socket
UDP_IP_ADDRESS = "192.168.43.254"
UDP_PORT_NO = 6789
Message = "Hello, Server"
clientSock = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)clientSock.sendto(Message,
(UDP_IP_ADDRESS, UDP_PORT_NO))
OBSERVATION:
RESULT:
In this experiment, we have created UDP server on raspberry pi and respond
withhumidity (or any string) data to UDP client when requested.
Pankaj Kumawat (20EC41)
EXPERIMENT-14
OBJECTIVE: Write a program to create TCP server on Raspberry Pi and respond
with humidity (or any string) data to TCP client when requested.
HARDWARE REQUIRED: Raspberry Pi 3B + setup
THEORY: The Transmission Control Protocol (TCP) is one of the main protocols of
the Internet protocol suite. The TCP Server origin listens at the specified port numbers,
establishes TCP sessions with clients that initiate TCP connections, and then processes
the incoming data. The origin can process data from tables with simplenumeric primary
keys. The origin cannot process data from tables with compound or non-numeric
primary keys. The TCP Server can process data from multiple clients simultaneously,
creating separate batches for each client, and sending acknowledgements to the
originating client after parsing each record or committing each batch. When you
configure the TCP Server origin, you specify the ports to use and the TCP mode that
indicates the type of data the origin will receive. Then you configure mode-related
properties, such as the characters that separate records.
Code:
pi@raspberrypi:~ $ sudo nano TCPServer.py
write the code
# -*- coding: utf-8 -*-
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('', serverPort))
serverSocket.listen(1)
print("Server is Listening for incoming Client Requests!!!")
while True: connectionSocket, addr = serverSocket.accept()
messagefromclient = connectionSocket.recv(1024)
print ("Message from Client: ", messagefromclient)
messagefromserver = raw_input("Enter reply message for client: ")
connectionSocket.send (messagefromserver)
pi@raspberrypi:~ $ sudo python TCPServer.py
Output is :
Server is Listening for incoming Client Requests!!!
('Message from Client: ', 'hii')
Enter reply message for client: how r u
('Message from Client: ', 'where are avewnger')
Enter reply message for client: yes
Client code
pi@raspberrypi:~ $ sudo nano TCPClient.py
# -*- coding: utf-8 -*-
from socket import *
serverName = "192.168.43.254"
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName, serverPort))
messagetoserver = raw_input("Enter Message for Server: ")
clientSocket.send(messagetoserver)
replyfromserver = clientSocket.recv(1024)
print("Reply Message from Server:", replyfromserver)
clientSocket.close()
pi@raspberrypi:~ $ sudo python TCPClient.py
Output Message:
Enter Message for Server: where are avewnger
Pankaj Kumawat (20EC41)
this is universe
('Reply Message from Server:', 'yes')
pi@raspberrypi:~ $ this is universe
RESULT:
In this experiment, we have created TCP server on Arduino and respond with any
string data to TCP client when requested.
ENGINEERING COLLEGE AJMER
Department of Electronics and Communication Engineering
Ajmer, Rajasthan
Submitted By:
Pankaj Kumawat
(20EEAEC041) (EC-2)
LIST OF EXPERIMENT
Exp. no List of Experiment
Exp: 1 Study the fundamental of IOT softwares and components.
Exp: 9 To interface Bluetooth with Arduino/Raspberry Pi and write a program to turn LED
ON/OFF when 1/0 is received from smartphone using Bluetooth.