Experiment No. 7: Objective
Experiment No. 7: Objective
Experiment No. 7: Objective
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
2. After that Press on click on New Project and you will get a screen (Refer Screen shots)
and then you will see below the authentication token no. If you want it in your email you can send it
through email also
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
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);
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:
Component Required
1. Arduino UNO
2. LED (Red, Green)
3. RFID sensor (MFRC522)
4. Servo
5. Jumpers
6. Breadboard
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
Hardware Requirements:
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.
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
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.
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:
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
Raspberry Pi
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.
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.
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.
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.
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.
3. When this process has finished, safely remove the SD card and insert it into your
Raspberry Pi.
FIRST BOOT
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.
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
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
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.
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
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
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.
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
Objectives: Student should get the knowledge of Zigbee Protocol using Raspberry
Pi.
Hardware Requirements
• Raspberry Pi2
• XBee 1mW Wire Antenna- Series 1 (2 No:)
• XBee Explorer Dongle (2 No:)
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
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
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.
import serial
while True:
incoming = ser.readline().strip()
The two ZigBee must be in a line of sight and check the results in the Python shell and in the