Experiment No. 7: Objective

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

Experiment No.

7
Objective: A project to read analog signal and represent it digitally or in the form of
voltage.

Introduction
Microcontrollers are capable of detecting binary signals: is the button pressed or not? These are
digital signals. When a microcontroller is powered from five volts, it understands zero volts (0V) as a
binary 0 and a five volts (5V) as a binary 1. The world however is not so simple and likes to use
shades of grey. What if the signal is 2.72V? Is that a zero or a one? We often need to measure signals
that vary; these are called analog signals. A 5V analog sensor may output 0.01V or 4.99V or
anything in between. Luckily, nearly all microcontrollers have a device built into them that allows us
to convert these voltages into values that we can use in a program to make a decision.

An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a
pin to a digital number. By converting from the analog world to the digital world, we can begin to
use electronics to interface to the analog world around us.

Circuit Diagram

Instruments Required
1. Arduino
2. USBcables
3. wires
4. Potentiometer
Code
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// start serial port at 9600 bps:
Serial.begin(9600);
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.print(sensorValue); // print ADC value of analog reading
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);
}

Output
Experiment No. 8
Objective: Controlling a bulb using Wifi module using Blynk app.
Introduction
It is an Open-source, Interactive, Programmable, Low cost, Simple, Smart, WI-FI enabled board which
can help you to build IOT projects with ultra-fast prototyping. it works on 3V logic and you have to
make arrangements when connecting sensors which work on 5V. This board has 30 Pins.

Blynk is a Platform with iOS and Android apps to control Arduino, Raspberry Pi and the likes over
the Internet.

Blynk was designed for the Internet of Things. It can control hardware remotely, it can display
sensor data, it can store data, visualize it and do many other cool things.

It's a digital dashboard where you can build a graphic interface for your project by simply dragging
and dropping widgets. It's really simple to set everything up and you'll start tinkering in less than 5
mins. Blynk is not tied to some specific board or shield. Instead, it's supporting hardware of your choice.
Whether your Arduino or Raspberry Pi is linked to the Internet over Wifi, Ethernet or this new
ESP8266 chip, Blynk will get you online and ready for the Internet Of Your Things.

Component Required
1. Node MCU
2. Arduinouno
3. 5v 4 channel relay module
4. 5v adapter
5. jumper wires male to female
6. ac 220v/120v loads/home appliances
7. android phone
8. laptop/pc

Connecting Hardware with Arduino


Setting up Blynk Application
1. First install the Blynk app from google play store and then sign in

2. After that Press on click on New Project and you will get a screen (Refer Screen shots)

● Enter the name of your project, I have given it as led

● Then Select the Board as ESP8266

and then you will see below the authentication token no. If you want it in your email you can send it
through email also

● And then Finally click on to the create button

3. Now you will get your dashboard screen. Just click on the the top most button "+" on the right
corner to add widgets to your project.

4. In this project we add a simple button and then configure its settings as Digital GP13 pin.(Refer
Screen Shots)

5. Its your choice you can either have the button set as push type or as a switch

6. Then label the Button as ON and OFF in the settings

Code
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
charauth[] = "YourAuthToken";
charssid[] = "YourNetworkName";
char pass[] = "YourPassword";
void setup()
{
// Debug console
Serial.begin(9600);

Blynk.begin(auth, ssid, pass);


}
void loop()
{
Blynk.run();
}
}
Output
Experiment No. 9
Objective: A project to use RFID tag in Arduino.
Introduction
RFID tagging is an ID system that uses small radio frequency identification devices for identification
and tracking purposes. An RFID tagging system includes the tag itself, a read/write device, and a
host system application for data collection, processing, and transmission.

In simple words an RFID uses electromagnetic fields to transfer data over short distances. RFID is
useful to identify people, to make transactions, etc…

You can use an RFID system to open a door. For example, only the person with the right information
on his card is allowed to enter. An RFID system uses:

>>tags attached to the object to be identified.

Component Required
1. Arduino UNO
2. LED (Red, Green)
3. RFID sensor (MFRC522)
4. Servo
5. Jumpers
6. Breadboard

Connecting Hardware with Arduino

Code
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Approximate your card to the reader...");
Serial.println();
}
void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return; }
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i< mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "BD 31 15 2B") //change here the UID of the card/cards that
you want to give access
{
Serial.println("Authorized access");
Serial.println();
delay(3000);
}
else {
Serial.println(" Access denied");
delay(3000);
}
}

Output
Reading data from an RFID tag

After having the circuit ready, go to File > Examples > MFRC522 >DumpInfo and upload the code.

Then, open the serial monitor. You should see something like the figure below:
Approximate the RFID card or the keychain to the reader. Let the reader and the tag closer until all
the information is displayed.

This is the information that you can read from the card, including the card UID that is highlighted in
yellow. The information is stored in the memory that is divided into segments and blocks as you can
see in the previous picture.

You have 1024 bytes of data storage divided into 16 sectors and each sector is protected by two
different keys, A and B.

Write down your UID card because you’ll need it later. Upload the Arduino code that has been
suffixed here.

Demonstration
Approximate the card you’ve chosen to give access and you’ll see:

If you approximate another tag with another UID, the denial message will show up:
Experiment No 10

Aim: Study and Implement RFID, NFC using Arduino.

Objectives: Student should get the knowledge of RFID, NFC using


Arduino.

Outcomes: Student will be developed programs using Arduino IDE


and Arduino Board for RFID, NFC.

Hardware Requirements:

• 1 x Arduino UNO or 1 x Starter Kit for Raspberry Pi + Raspberry Pi


• 1 x Communication Shield
• 1 x RFID 13.56 MHz / NFC Module for Arduino and Raspberry Pi
• 1 x Mifare tag (card/keyring/sticker)
• 1 x PC

RFID:

RFID system is made up of two parts: a tag or label and a reader. RFID
tags or labels are embedded with a transmitter and a receiver. The
RFID component on the tags have two parts: a microchip that stores
and processes information, and an antenna to receive and transmit a
signal. The tag contains the specific serial number for one specific
object.

To read the information encoded on a tag, a two-way radio transmitter-


receiver called an interrogator or reader emits a signal to the tag using
an antenna. The tag responds with the information written in its
memory bank. The interrogator will then transmit the read results to
an RFID computer program.

How to Interface RFID Reader to Arduino

Let’s first wire the whole thing up. You may observe the circuit diagram
given below. Take note of the following stuffs.

Note 1:- Power supply requirement of RFID Readers vary from product
to product. The RFID reader I used in this tutorial is a 12 Volts one.
There are 5 Volts and 9 Volts versions available in the market.

Note 2:- You may ensure the RFID Reader and RFID Tags are
frequency compatible. Generally they are supposed to be 125Khz. You
may ensure this before purchasing them.

Note 3:- There are two possible outputs from an RFID Reader. One is
RS232 compatible output and other one is TTL compatible output. A
TTL compatible output pin can be connected directly to Arduino.
Whereas an RS232 compatible output must be converted to TTL using
an RS232 to TTL converter (You can design this yourself using
MAX232 IC)

Circuit diagram

Make connections as shown. Make sure you connect Ground Pin of


RFID reader to Ground Pin of Arduino. I am using the Software Serial
Library of Arduino which enables digital pins to be used in serial
communication. I have used pin 9 as the Rx of Arduino. (You can also
use the hardware Rx pin of Arduino uno – that’s pin 0). If you are new
to Software Serial Library, you may read my previous tutorial on
interfacing GSM module to Arduino (this article clearly explains how to
use Software Serial Library).

Programming

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);

void setup()
{
mySerial.begin(9600); // Setting the baud rate of
Software Serial Library
Serial.begin(9600); //Setting the baud rate of Serial
Monitor
}

void loop()
{
if(mySerial.available()>0)
{
Serial.write(mySerial.read());
}
}
mySerial.available() – checks for any data coming from RFID reader
module through the SoftwareSerial pin 9. Returns the number of bytes
available to read from software serial port. Returns a -1 if no data is
available to read.

mySerial.read() – Reads the incoming data through software serial port.

Serial.write() – Prints data to serial monitor of Arduino. So the function


Serial.write(mySerial.read()) – prints the data collected from software
serial port to serial monitor of Arduino.
Experiment No 11

Aim: Study and Implement MQTT Protocol using Arduino.

Objectives: Student should get the knowledge of MQTT Protocol using Arduino.

Outcomes: Student will be developed programs using Arduino IDE and Arduino
Board for MQTT Protocol

MQTT:

MQ Telemetry Transport (MQTT) is an open source protocol for constrained devices


and low-bandwidth, high-latency networks. It is a publish/subscribe messaging
transport that is extremely lightweight and ideal for connecting small devices to
constrained networks.
MQTT is bandwidth efficient, data agnostic, and has continuous session awareness.
It helps minimize the resource requirements for your IoT device, while also attempting
to ensure reliability and some degree of assurance of delivery with grades of service.
MQTT targets large networks of small devices that need to be monitored or controlled
from a back-end server on the Internet. It is not designed for device-to-device transfer.
Nor is it designed to “multicast” data to many receivers. MQTT is extremely simple,
offering few control options.

MQTT methods

MQTT defines methods (sometimes referred to as verbs) to indicate the desired action
to be performed on the identified resource. What this resource represents, whether
pre-existing data or data that is generated dynamically, depends on the
implementation of the server. Often, the resource corresponds to a file or the output
of an executable residing on the server.

Connect
Waits for a connection to be established with the server.
Disconnect
Waits for the MQTT client to finish any work it must do, and for the TCP/IP session

to disconnect.
Subscribe
Waits for completion of the Subscribe or UnSubscribe method.
UnSubscribe
Requests the server unsubscribe the client from one or more topics.
Publish
Returns immediately to the application thread after passing the request to the
MQTT client.
Experiment No 12

Aim: Study and Configure Raspberry Pi.

Objectives: Student should get the knowledge of Raspberry Pi.

Outcomes: Student will be get knowledge of Raspberry Pi

Raspberry Pi

The Raspberry Pi is a series of small single-board computers developed in the United


Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer
science in schools and in developing countries. The original model became far more
popular than anticipated, selling outside of its target market for uses such as robotics.
Peripherals (including keyboards, mice and cases) are not included with the Raspberry
Pi. Some accessories however have been included in several official and unofficial
bundles.

According to the Raspberry Pi Foundation, over 5 million Raspberry Pis have been sold
before February 2015, making it the best-selling British computer. By November 2016
they had sold 11 million units, reaching 12.5m in March 2017, making it the third
best-selling "general purpose computer" ever.

To get started with Raspberry Pi, you need an operating system. NOOBS (New Out Of Box
Software) is an easy operating system install manager for the Raspberry Pi.

How to get and install NOOBS

DOWNLOAD NOOBS OS FROM

We recommend using an SD card with a minimum capacity of 8GB.

1. GO to the https://www.raspberrypi.org/downloads/

2. Click on NOOBS, then click on the Download ZIP button under ‘NOOBS (offline and
network install)’ and select a folder to save it to.

3. Extract the files from the zip.

FORMAT YOUR SD CARD

It is best to format your SD card before copying the NOOBS files onto it. To do this:
1. Download SD Formatter 4.0 for either Windows or Mac.

2. Follow the instructions to install the software.

3. Insert your SD card into the computer or laptop’s SD card reader and make a note of the
drive letter allocated to it, e.g. G:/

4. In SD Formatter, select the drive letter for your SD card and format it.

DRAG AND DROP NOOBS FILES

1. Once your SD card has been formatted, drag all the files in the extracted NOOBS folder
and drop them onto the SD card drive.

2. The necessary files will then be transferred to your SD card.

3. When this process has finished, safely remove the SD card and insert it into your
Raspberry Pi.

FIRST BOOT

1. Plug in your keyboard, mouse, and monitor cables.

2. Now plug the USB power cable into your Pi.

3. Your Raspberry Pi will boot, and a window will appear with a list of different operating
systems that you can install. We recommend that you use Raspbian – tick the box next
to Raspbian and click on Install.

4. Raspbian will then run through its installation process. Note that this can take a while.

5. When the install process has completed, the Raspberry Pi configuration menu (raspi-
config) will load. Here you are able to set the time and date for your region, enable a
Raspberry Pi camera board, or even create users. You can exit this menu by using Tab on
your keyboard to move to Finish.

LOGGING IN AND ACCESSING THE GRAPHICAL USER INTERFACE

The default login for Raspbian is username pi with the password raspberry. Note that you
will not see any writing appear when you type the password. This is a security feature
in Linux.

To load the graphical user interface, type startx and press Enter.
Experiment No 13

Aim: WAP for LED blink using Raspberry Pi.

Objectives: Student should get the knowledge of LED blinking using Raspberry Pi.

Outcomes: Student will be developed program of LED bilking using Raspberry Pi.

Hardware Requirements:

• 1x Breadboard
• 1x Raspberry Pi
• 1x RGB LED
• 1x 330Ω Resistor
• 2x Jumper Wires

Semiconductor light-emitting diode is a type of component which can turn electric


energy into light energy via PN junctions. By wavelength, it can be categorized into laser
diode, infrared light-emitting diode and visible light-emitting diode which is usually
known as light-emitting diode (LED).
When 2V-3V forward voltage is supplied to an LED, it will blink only if forward currents
flow through the LED. Usually there are red, yellow, green, blue and color-changing
LEDs which change color with different voltages. LEDs are widely used due to their low
operating voltage, low current, luminescent stability and small size.
LEDs are diodes too. Hence they have a voltage drop which usually varies from 1V to
3V depending on their types. Generally they brighten if supplied with a 5mA-30mA
current and we usually use 10mA-20mA.Thus when an LED is used ,it is necessary to
connect a current-limiting resistor to protect it from being burnt.
In this experiment, connect a 220Ω resistor to the anode of the LED, then the resistor to 3.3 V
and connect the cathode of the LED to GPIO0 (See Raspberry Pi Pin Number Introduction).
Write 1 to GPIO0, and the LED will stay off; write 0 to GPIO0, and then the LED will blink, just
as indicated by the principle above
Step 1: Build the circuit given above

Step 2: Change directory


cd /home/pi/Sunfounder_SuperKit_ Python_code_for_RaspberryPi/

Step 3: Run
sudo python 01_led.py
Now, you should see the LED blink.

Python Code
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time

LedPin = 11 # pin11

def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output
GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led

def loop():
while True:
print '...led on'
GPIO.output(LedPin, GPIO.LOW) # led on
time.sleep(0.5)
print 'led off...'
GPIO.output(LedPin, GPIO.HIGH) # led off
time.sleep(0.5)

def destroy():
GPIO.output(LedPin, GPIO.HIGH) # led off
GPIO.cleanup() # Release resource
if name == ' main ': # Program start from
setup() here
try:
loop(
)
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program
destroy() will be executed.
destroy()
Experiment No 14

Study of ThingSpeak.

According to its developers, "ThingSpeak is an open-source Internet of Things (IoT)


application and API to store and retrieve data from things using the HTTP and MQTT
protocol over the Internet or via a Local Area Network. ThingSpeak enables the
creation of sensor logging applications, location tracking applications, and a social
network of things with status updates".ThingSpeak was originally launched by
ioBridge in 2010 as a service in support of IoT applications.ThingSpeak has
integrated support from the numerical computing software MATLAB from
MathWorks,allowing ThingSpeak users to analyze and visualize uploaded data using
Matlab without requiring the purchase of a Matlab license from Mathworks.
ThingSpeak has a close relationship with Mathworks, Inc. In fact, all of the
ThingSpeak documentation is incorporated into the Mathworks' Matlab
documentation site and even enabling registered Mathworks user accounts as valid
login credentials on the ThingSpeak website. The terms of service and privacy policy
of ThingSpeak.com are between the agreeing user and Mathworks, Inc.

Internet of Things

Things are either sensors or actuators. A sensor is something that tells us about our
environment. Think of a temperature sensor, or even the GPS receiver on your mobile
phone. Actuators are something that you want to control, things like thermostats,
lights, pumps, and outlets. The “Internet of Things” brings everything together and
allows us to interact with our things. For example, you could have
your thermostat control itself based on where you’re located.

ThingSpeak Basics

ThingSpeak is an application platform for the Internet of Things. ThingSpeak allows


you to build an application around data collected by sensors. Features of ThingSpeak
include real-time data collection, data processing, visualizations, apps, and plugins.
At the heart of ThingSpeak is a ThingSpeak Channel. A channel is where you send
your data to be stored. Each channel includes 8 fields for any type of data, 3 location
fields, and 1 status field. Once you have a ThingSpeak Channel you can publish data
to the channel, have ThingSpeak process the data, and then have your
application retrieve the data.
Experiment No 15
Study of Thinger.io

The Thinger.io platform is an Open Source platform for the Internet of Things, it
provides a ready to use scalable cloud infrastructure for connecting things. Makers
and companies can start controlling their devices from the internet in minutes,
without worrying about the required cloud infrastructure.

Thinger.io platform is formed by two main products a Backend (which is the actual
IoT server) and a web-based Frontend that simplifies working with all the features
using any computer or smartphone. The image below shows the main features
provides by this platform to create IoT projects.

• Connect devices: Fully compatible with every kind of device, no matter the
processor, the network or the manufacturer. Thinger.io allows to create
bidirectional communications with Linux, Arduino, Raspberry Pi, or MQTT
devices and even with edge technologies like Sigfox or LoRaWAN or other
internet API data resources.
• Store Device Data: Just a couple clicks to create a Data Bucket a store IoT
data in a scalable, efficient and affordable way, that also allows real-time data
aggregation.
• Display Real-time or Stored Data in multiple widgets such as time series,
donut charts, gauges, or even custom made representations to create awesome
dashboards within minutes.
• Trigger events and data values using an embedded Node-RED rule engine
• Extend with custom features with multiple plugins to integrate IoT projects
into your company's software or any other third-party Internet service.
• Custom the appearance thanks to our fully rebrandable frontend, that allows
introducing your branding colors, logotypes, and web domain.
Experiment No 16
Study of NodeMCU

NodeMCU is a low-cost open source IoT platform. It initially included firmware


which runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware
which was based on the ESP-12 module. Later, support for the ESP32 32-bit
MCU was added.NodeMCU is an open source firmware for which open source
prototyping board designs are available. The name "NodeMCU" combines "node"
and "MCU" (micro-controller unit). The term "NodeMCU" strictly speaking refers
to the firmware rather than the associated development kits.Both the firmware
and prototyping board designs are open source.

The firmware uses the Lua scripting language. The firmware is based on the
eLua project, and built on the Espressif Non-OS SDK for ESP8266. It uses
many open source projects, such as lua-cjson and SPIFFS. Due to resource
constraints, users need to select the modules relevant for their project and build
a firmware tailored to their needs. Support for the 32-bit ESP32 has also been
implemented.

The prototyping hardware typically used is a circuit board functioning as a dual


in-line package (DIP) which integrates a USB controller with a smaller surface-
mounted board containing the MCU and antenna. The choice of the DIP format
allows for easy prototyping on breadboards. The design was initially based on
the ESP-12 module of the ESP8266, which is a Wi-Fi SoC integrated with a
Tensilica Xtensa LX106 core, widely used in IoT applications.

NodeMCU has 128 KB RAM and 4MB of Flash memory to store data and
programs. Its high processing power with in-built Wi-Fi / Bluetooth and Deep
Sleep Operating features make it ideal for IoT projects. NodeMCU can be
powered using Micro USB jack and VIN pin (External Supply Pin). It supports
UART, SPI, and I2C interfaces.
Experiment No 17

Aim: Study and Implement Zigbee Protocol using Raspberry Pi.

Objectives: Student should get the knowledge of Zigbee Protocol using Raspberry
Pi.

Outcomes: Student will be developed program of Zigbee Protocol using Raspberry


Pi.

Hardware Requirements

• Raspberry Pi2
• XBee 1mW Wire Antenna- Series 1 (2 No:)
• XBee Explorer Dongle (2 No:)

ZigBee Communication Using Raspberry Pi:

ZigBee is a communication device used for the data transfer between the controllers,

computers, systems, really anything with a serial port. As it works with low power

consumption, the transmission distances is limited to 10–100 meters line-of-

sight. ZigBee devices can transmit data over long distances by passing data through

a mesh network of intermediate devices to reach more distant ones. ZigBee is typically

used in low data rate applications that require long battery life and secure networking.

Its main applications are in the field of wireless sensor network based on industries as

it requires short-range low-rate wireless data transfer. The technology defined by the

ZigBee specification is intended to be simpler and less expensive than

other wireless networks.

Here we make use of an interface of Zigbee with Raspberry Pi2 for a proper wireless

communication. Raspberry Pi2 has got four USB ports, so it is better to use a Zigbee Dongle for

this interface. Now we want to check the communication between the two paired ZigBee

modules.
The response showed inside a red box indicates the presence of a usb device in the module.

Write a python script to perform Zigbee communication which is given below.

import serial

# Enable USB Communication

ser = serial.Serial('/dev/ttyUSB0', 9600,timeout=.5)

while True:

ser.write('Hello User \r\n') # write a Data

incoming = ser.readline().strip()

print 'Received Data : '+ incoming

The two ZigBee must be in a line of sight and check the results in the Python shell and in the

hyper terminal of the computer.

You might also like