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

IT18512- INTERNET OF THINGS LABORATORY

Exp NO: MOVEMENT DETECTION WITH PIR


Date:

AIM:
To design an IoT application to illustrate the working of PIR in movement detection.

PROCEDURE:
1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN>RUN or Ctrl+F5.
7. Connect VCC to Pin 2 (VCC)
8. Connect GND to Pin 6 (GND)
9. TRIG to Pin 12 (GPIO18)
10. Connect ECHO to GPIO 24.

CODE:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
TRIG = 23
ECHO = 24
print "Distance Measurement"
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
GPIO.output(TRIG, False)
time.sleep(2)
GPIO.output(TRIG, True)

Register No: 2127210801015 1


IT18512- INTERNET OF THINGS LABORATORY

time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO)==0:
pulse_start = time.time()
while GPIO.input(ECHO)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration x 17150
distance = round(distance, 2)
print "Distance: “, distance,"cm"
GPIO.cleanup()

SAMPLE INPUT AND OUTPUT:

RESULT:
The application was designed using PIR sensor and the distance was measured.

Register No: 2127210801015 2


IT18512- INTERNET OF THINGS LABORATORY

Exp NO: SIMULATION OF TRAFFIC SIGNAL


Date:

AIM:
To design an IoT application to simulate the working of traffic signal.

PROCEDURE:

1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN>RUN or Ctrl+F5.
7. Connect three pins to GPIO 12 ,GPIO 16 and GPIO 23
8. Connect button to GPIO 19.
9. Connect ground to PIN 3

CODE:
import RPi.GPIO as GPIO import time
try:
def lightTraffic(led1, led2, led3, delay ): GPIO.output(led1, 1)
Print(“GREEN”)
time.sleep(delay) GPIO.output(led1, 0)
GPIO.output(led2, 1) Print(“YELLOW”)
time.sleep(delay) GPIO.output(led2, 0)
GPIO.output(led3, 1) Print(“RED”) time.sleep(delay) GPIO.output(led3, 0)
GPIO.setmode(GPIO.BCM) button = 19
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP) ledGreen = 16
ledYellow = 12
ledRed = 23

Register No: 2127210801015 3


IT18512- INTERNET OF THINGS LABORATORY

GPIO.setup(ledGreen, GPIO.OUT) GPIO.setup(ledYellow, GPIO.OUT) GPIO.setup(ledRed,


GPIO.OUT) while True:
input_state = GPIO.input(button) if input_state == False: print('Button Pressed')
lightTraffic(ledGreen, ledYellow, ledRed, 1)
else:
GPIO.output(ledGreen, 0)
GPIO.output(ledYellow, 0)
GPIO.output(ledRed, 0) except KeyboardInterrupt:
print "You've exited the program" finally:
GPIO.cleanup()

SAMPLE INPUT AND OUTPUT:

RESULT:
The Application was developed to simulate the working of traffic signal.

Register No: 2127210801015 4


IT18512- INTERNET OF THINGS LABORATORY

Exp NO: WORKING OF SERVO MOTOR


Date:

AIM:
To control the rotation of a servo motor.

PROCEDURE:
1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN>RUN or Ctrl+F5.
7. Connect orange wire to pin GPIO 21.
8. Connect red wire to GCC
9. Connect brown wire to ground

CODE:
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(12,
GPIO.OUT)
p = GPIO.PWM(12, 50)
p.start(7.5) try:
while True:
p.ChangeDutyCycle(7.5) # turn towards 90 degree print(“90 degree”)
time.sleep(1) # sleep 1 second p.ChangeDutyCycle(2.5) # turn towards 0 degree print(“0
degree”)
time.sleep(1) # sleep 1 second p.ChangeDutyCycle(12.5) # turn towards 180 degree
print(“180 degree”)
time.sleep(1) # sleep 1 second except KeyboardInterrupt:
p.stop() GPIO.cleanup()

Register No: 2127210801015 5


IT18512- INTERNET OF THINGS LABORATORY

SAMPLE INPUT AND OUTPUT:

RESULT:
The servo motor working was connected and rotated.

Register No: 2127210801015 6


IT18512- INTERNET OF THINGS LABORATORY

Exp NO: CONTROLLING LED INTENSITY USING PWM SIGNAL


Date:

AIM:
To vary the brightness of an LED using PWM signal.

PROCEDURE:
1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN>RUN or Ctrl+F5.
7. Connect LED to pin GPIO 21 .
8. Connect ground to PIN 3

CODE:
import RPi.GPIO as GPIO from time import sleep led_pin = 21 GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT) pwm = GPIO.PWM(led_pin, 100) pwm.start(0)
try:
while 1:
Print(“INCREASING”)
for x in range(100): Print(x)
pwm.ChangeDutyCycle(x) sleep(0.01)
Print(“DECREASING”)
for x in range(100,0,-1): Print(x)
pwm.ChangeDutyCycle(x) sleep(0.01)
# If keyboard Interrupt except KeyboardInterrupt:
pass pwm.stop GPIO.cleanup()

Register No: 2127210801015 7


IT18512- INTERNET OF THINGS LABORATORY

SAMPLE INPUT AND OUTPUT:

RESULT:
Using PWM signal the intensity of the LED was varied.

Register No: 2127210801015 8


IT18512- INTERNET OF THINGS LABORATORY

Exp NO: INTERFACING LED, SWITCH AND BUZZER WITH RASPBERRY PI


Date:

AIM:
To implement the interface LED, Switch and buzzer with raspberryPi and interface
board by using the python.

DESCRIPTION:
Raspberry Pi is the name of a series of single-board computers made by the Raspberry Pi
foundation, a UK charity that aims to educate people in computing and create easier access to
computing education. It is useful in interfacing various devices for interoperability and for
developing integrated IOT system. The LED and buzzer are integrated with the GPIO [General
Purpose Input Output] pins of Raspberry Pi circuit. The circuit is booted over monitor with
Raspbian OS system. The code for controlling LED and buzzer over a switch is written in
Python.

PROCEDURE:
Connection with Raspberry Pi :
• Connect GPIO 11 of Raspberry Pi to LED through connecting jumperwires.
• Connect GPIO 13 to Raspberry Pi to LED through connecting jumperwires.
• Connect GPIO 15 of Raspberry Pi to buzzer pin through connecting, jumperwires.
• Connect GPIO 23 of Raspberry Pi to switch pin through connecting jumperwires.
• Using jumper wires connect the ground pin of Raspberry Pi and LED interfacing board.
• Now power up the Raspberry Pi and boot.

Register No: 2127210801015 9


IT18512- INTERNET OF THINGS LABORATORY

PIN DIAGRAM:

CODE:
import time
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP) try:
while True:
button_state = GPIO.input(23) if button_state == False:
GPIO.output(11,True) GPIO.output(13,True) print('Button Pressed...') time.sleep(0.2)

else:
GPIO.output(13,False) GPIO.output(11,False) print('Button released')
except:
GPIO.cleanup()

Register No: 2127210801015 10


IT18512- INTERNET OF THINGS LABORATORY

SAMPLE INPUT AND OUTPUT:

CODE: (EVEN COUNT)


import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOAR
D)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_U
P)count=0
try:
while True:
button_state = GPIO.input(23)
if button_state == False:
count = count + 1
if(count%2==0):
GPIO.output(11,True)
GPIO.output(13,True)
print(count)
time.sleep(1)
else:
GPIO.output(13,Fals
e)
GPIO.output(11,Fals
e)time.sleep(1)
except:
GPIO.cleanup()

Register No: 2127210801015 11


IT18512- INTERNET OF THINGS LABORATORY

SAMPLE INPUT AND OUTPUT:

CODE:
import time
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP)

try:
while True:
button_state = GPIO.input(23) if button_state == False:
for i in range(0,8): GPIO.output(11,True) GPIO.output(13,True) time.sleep(0.2)
GPIO.output(13,False) GPIO.output(11,False) time.sleep(0.2)
except:
GPIO.cleanup()

SAMPLE INPUT AND OUTPUT:

Register No: 2127210801015 12


IT18512- INTERNET OF THINGS LABORATORY

CODE:
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOAR
D)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP)
try:
while True:
button_state = GPIO.input(23)
if button_state == False:
for i in range(0,5):
GPIO.output(11,True)
GPIO.output(13,True)
time.sleep(1)
GPIO.output(13,False)
GPIO.output(11,False)
time.sleep(1)
GPIO.output(15,True)
GPIO.output(13,True)
time.sleep(1)
GPIO.output(15,False)
GPIO.output(13,False)
time.sleep(1)

except:
GPIO.cleanup()

Register No: 2127210801015 13


IT18512- INTERNET OF THINGS LABORATORY

SAMPLE INPUT AND OUTPUT:

RESULT:
Thus, the implementation of the LED, switch and buzzer with Raspberry Pi and interface
board using python has been successfully completed

Register No: 2127210801015 14


IT18512- INTERNET OF THINGS LABORATORY

Exp NO: BUZZER CONTROL USING BLUETOOTH


Date:

AIM:

To implement buzzer control using Bluetooth in IOT development kit

PIN CONFIG:

ESP32

GPIO 2 BUZZER

CODE:

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) ||
!defined(CONFIG_BLUEDROID_ENABLED)

#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it

#endif

#define BUZZER 2

BluetoothSerial SerialBT;

// Handle received and sent messages

String message = "";

char incomingChar;

void setup() {

pinMode(BUZZER, OUTPUT);

Serial.begin(115200);

SerialBT.begin("ESP32"); //Bluetooth device name

Register No: 2127210801015 15


IT18512- INTERNET OF THINGS LABORATORY

Serial.println("The device started, now you can pair it with bluetooth!");

void loop() {

if (SerialBT.available()){

char incomingChar = SerialBT.read();

if (incomingChar != '\n'){

message += String(incomingChar);

else{

message = "";

Serial.write(incomingChar);

// Check received message and control output accordingly

if (message =="on"){

digitalWrite(BUZZER, HIGH);

else if (message =="off"){

digitalWrite(BUZZER, LOW);

delay(20);

OUTPUT:

Register No: 2127210801015 16


IT18512- INTERNET OF THINGS LABORATORY

RESULT
Thus the buzzer using Bluetooth in IOT development it has been executed successfully.

Register No: 2127210801015 17


IT18512- INTERNET OF THINGS LABORATORY

Exp NO: COMMUNICATION WITH ESP32 THROUGH BLUETOOTH


Date:

AIM:

To implement communication with ESP32 through Bluetooth in IOT development kit.

CODE:

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) ||
!defined(CONFIG_BLUEDROID_ENABLED)

#errorBluetooth is not enabled! Please run `make menuconfig` to and enable it

#endif

BluetoothSerial SerialBT;

void setup() {

Serial.begin(115200);

SerialBT.begin("ESP32test"); //Bluetooth device name

Serial.println("The device started, now you can pairit with bluetooth!");

void loop() {

if (Serial.available()) {

SerialBT.write(Serial.read());

if (SerialBT.available()) {

Serial.write(SerialBT.read());

delay(20);

Register No: 2127210801015 18


IT18512- INTERNET OF THINGS LABORATORY

OUTPUT:

RESULT:
Thus the program to implement communication ESP32 through Bluetooth using IOT kit
development kit has been executed successfully.

Register No: 2127210801015 19


IT18512- INTERNET OF THINGS LABORATORY

Exp NO: TFT DISPLAY


Date:

AIM:

To implement TFT display using IOT KIT

PIN CONFISURATION:

ESP32 TFT

5V( RS232 TO TTL) LED

GND GND

GPIO 12 CS

GPIO 14 RES

GPIO 13 A0

GPIO 21 SDA

3.3V VCC

CODE:

#include <Adafruit_GFX.h>

#include <Adafruit_ST7735.h>

#include <SPI.h>

//**************************************************************************
*********

//define pins of TFT screen

#define TFT_CS 12

#define TFT_RST 14

#define TFT_DC 13

Register No: 2127210801015 20


IT18512- INTERNET OF THINGS LABORATORY

#define TFT_SCLK 22

#define TFT_MOSI 21

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK,


TFT_RST);

//**************************************************************************
*********

void setup(void) {

Serial.begin(115200); //initialise serial communication at 115200 bps

Serial.print("ST7735 TFT grafics test");

tft.initR(INITR_BLACKTAB); //initialize a ST7735S chip, black tab

Serial.println("Initializing...");

tft.setTextWrap(true);

void loop() {

tft.fillScreen(ST7735_BLACK);

tft.setCursor(0, 0);

tft.setTextColor(ST7735_RED);

tft.setTextSize(2);

tft.println("Hello!");

delay(2000);

tft.setTextColor(ST7735_YELLOW);

tft.setTextSize(2);

tft.println("IOT Dev Kit!");

delay(1000);

tft.setTextColor(ST7735_GREEN);

Register No: 2127210801015 21


IT18512- INTERNET OF THINGS LABORATORY

tft.setTextSize(3);

tft.println("BYE!");

delay(2000);

OUTPUT:

RESULT:

Thus the program to implement TFT display has been executed successfully.

Register No: 2127210801015 22


IT18512- INTERNET OF THINGS LABORATORY

Exp NO: TEMPERATURE AND HUMIDITY SENSOR


Date:

AIM:
To implement temperature and humidity sensor in IOT kit
PIN CONFIGURATION:

ESP32 DHT11

3.3V 3.3V

GPIO 4 I/O

GND GND

PROGRAM:

#include "DHT.h"

#define DHTPIN 4

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {

Serial.begin(9600);

Serial.println("DHTxx test!");

dht.begin();

void loop() {

delay(2000);

float h = dht.readHumidity();

float t = dht.readTemperature();

if (isnan(h) || isnan(t) ) {

Register No: 2127210801015 23


IT18512- INTERNET OF THINGS LABORATORY

Serial.println("Failed to read from DHT sensor!");

return;

Serial.print("Humidity: ");

Serial.print(h);

Serial.print("% Temperature: ");

Serial.print(t);

Serial.print("°C ");

Serial.println("");

OUTPUT:

RESULT:

Thus, the program to implement temperature and humidity sensor using IOT kit has been
executed successfully.

Register No: 2127210801015 24

You might also like