IoT Lab Manual Removed Removed
IoT Lab Manual Removed Removed
Aim: Study and Install Python in Eclipse and WAP for data types in python.
Objectives: Student should get the knowledge of Python and Eclipse background.
What is Python:
Python is Interactive − You can actually sit at a Python prompt and interact
with the interpreter directly to write your programs.
History of Python
Python was developed by Guido van Rossum in the late eighties and early nineties
at the National Research Institute for Mathematics and Computer Science in the
Netherlands.
Python is derived from many other languages, including ABC, Modula-3, C, C++,
Algol-68, SmallTalk, and Unix shell and other scripting languages.
Python is copyrighted. Like Perl, Python source code is now available under the
GNU General Public License (GPL).
Python Features
Easy-to-read − Python code is more clearly defined and visible to the eyes.
A broad standard library − Python's bulk of the library is very portable and
cross-platform compatible on UNIX, Windows, and Macintosh.
Interactive Mode − Python has support for an interactive mode which allows
interactive testing and debugging of snippets of code.
Portable − Python can run on a wide variety of hardware platforms and has
the same interface on all platforms.
It provides very high-level dynamic data types and supports dynamic type
checking.
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
The following assume that you have already Eclipse installed. For an
installation description of Eclipse please see Eclipse IDE for Java.
For Python development under Eclipse you can use the PyDev Plugin which
is an open source project. Install PyDev via the Eclipse update manager via
the following update site: http://pydev.org/updates.
Configuration of Eclipse
You also have to maintain in Eclipse the location of your Python installation.
Open in theWindow ▸ Preference ▸ Pydev ▸ Interpreter Python menu.
Press the New button and enter the path to python.exe in your Python
installation directory. For Linux and Mac OS X users this is normally
/usr/bin/python.
Variables are nothing but reserved memory locations to store values. This
means that when you create a variable you reserve some space in memory.
Based on the data type of a variable, the interpreter allocates memory and
decides what can be stored in the reserved memory. Therefore, by assigning
different data types to variables, you can store integers, decimals or
characters in these variables.
The operand to the left of the = operator is the name of the variable and the
operand to the right of the = operator is the value stored in the variable. For
example −
#!/usr/bin/python
# An integer
counter = 100 assignment
print counter
print miles
print name
Here, 100, 1000.0 and "John" are the values assigned to counter, miles, and
name variables, respectively. This produces the following result −
100
1000.0
John
Multiple Assignment
Experiment No 2
Operators
Operators are the constructs which can manipulate the value of operands.
Types of Operator
Python language supports the following types of operators.
Arithmetic Operators
Comparison (Relational)
Operators Assignment Operators
Logical
Operators
Bitwise
Operators
Membership
Operators Identity
Operators
Let us have a look on all operators one by one.
Example
#!/usr/bin/python
a = 21
b = 10
c=0
Experiment No 3
Programming languages provide various control structures that allow for more
complicated execution paths.
1 while loop
for
2 loop
nested
3 loops
You can use one or more loop inside any another while, for
or
do..while loop.
Loop control statements change execution from its normal sequence. When
execution leaves a scope, all automatic objects that were created in that scope
are destroyed.
Python supports the following control statements. Click the following links to
check their detail.
Sr.No
. Control Statement & Description
1 break statement
3 pass statement
It has the ability to iterate over the items of any sequence, such as a list or a string.
Syntax
statements(s)
If a sequence contains an expression list, it is evaluated first. Then, the first item in
the sequence is assigned to the iterating variable iterating_var. Next, the
statements block is executed. Each item in the list is assigned to iterating_var, and
the statement(s) block is executed until the entire sequence is exhausted.
Flow Diagram
Example
#!/usr/bin/python
Current Letter : P
Current Letter : y
Current Letter : t
Experiment No 4
Aim: Study and Install IDE of Arduino and different types of Arduino
Objectives: Student should get the knowledge of Arduino IDE and different
types of Arduino Board
Outcomes: Student will be get knowledge of Arduino IDE and different types
of Arduino Board
Arduino:
Arduino provides a standard form factor that breaks the functions of the micro-
controller into a more accessible package.
Arduino boards are able to read analog or digital input signals from different
sensors and turn it into an output such as activating a motor, turning LED
on/off, connect to the cloud and many other actions.
You can control your board functions by sending a set of instructions to the
microcontroller on the board via Arduino IDE (referred to as uploading
software).
Unlike most previous programmable circuit boards, Arduino does not need
an extra piece of hardware (called a programmer) in order to load a new
code onto the board. You can simply use a USB cable.
Additionally, the Arduino IDE uses a simplified version of C++, making it
easier to learn to program.
Finally, Arduino provides a standard form factor that breaks the functions of
the micro-controller into a more accessible package.
2.Arduino NG REV-C
Arduino Bluetooth
Arduino Mega
Arduino NANO
The Arduino Nano 3.0 has an ATmega328 and a two-layer PCB. The
power LED moved to the top of the board.
Experiment No 5
Aim: Write program using Arduino IDE for Blink LED
Objectives: Student should get the knowledge of Arduino Board and different
types of LED
Outcomes: Student will be Write program using Arduino IDE for Blink LED
Hardware Requirements:
1x Breadboard
1x Arduino Uno R3
1x RGB LED
1x 330Ω Resistor
2x Jumper
Wires Blinking the
RGB LED
With a simple modification of the breadboard, we could attach the LED to an
output pin of the Arduino. Move the red jumper wire from the Arduino 5V
connector to D13, as shown below:
Now load the 'Blink' example sketch from Lesson 1. You will notice that both
the built-in 'L' LED and the external LED should now blink.
1. /*
2. Blink
3. Turns on an LED on for one second, then off for one second, repeatedly.
4.
5. This example code is in the public domain.
6. */
7.
8. // Pin 13 has an LED connected on most Arduino boards.
9. // give it a name:
10. int led = 13;
11.
12. // the setup routine runs once when you press reset:
13. void setup() {
14. // initialize the digital pin as an output.
15. pinMode(led, OUTPUT);
16. }
17.
18. // the loop routine runs over and over again forever:
19. void loop() {
20. digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
21. delay(1000); // wait for a second
22. digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
23. delay(1000); // wait for a second
24. }
Lets try using a different pin of the Arduino – say D7. Move the red jumper lead
from pin D13 to pin D7 and modify the following line near the top of the sketch:
so that it reads:
1. int led = 7;
Upload the modified sketch to your Arduino board and the LED should still
be blinking, but this time using pin D7.
Experiment No 6
Aim: Write Program for RGB LED using Arduino.
Objectives: Student should get the knowledge of Arduino IDE and RGB Led
Hardware Requirements:
1x Breadboard
1x Arduino Uno R3
1x LED
1x 330Ω Resistor
2x Jumper
Wires Blinking the
LED
With a simple modification of the breadboard, we could attach the LED to an
output pin of the Arduino. Move the red jumper wire from the Arduino 5V
connector to D13, as shown below:
Now load the 'Blink' example sketch from Lesson 1. You will notice that both
the built-in 'L' LED and the external LED should now blink.
The following test sketch will cycle through the colors red, green, blue,
yellow, purple, and aqua. These colors being some of the standard Internet
colors.
1. /*
2. Adafruit Arduino - Lesson 3. RGB LED
3. */
4.
5. int redPin = 11;
6. int greenPin = 10;
7. int bluePin = 9;
8.
9. //uncomment this line if using a Common Anode LED
10. //#define COMMON_ANODE
11.
12. void setup()
13. {
14. pinMode(redPin, OUTPUT);
15. pinMode(greenPin, OUTPUT);
16. pinMode(bluePin, OUTPUT);
17. }
18.
19. void loop()
20. {
21. setColor(255, 0, 0); // red
22. delay(1000);
23. setColor(0, 255, 0); // green
24. delay(1000);
25. setColor(0, 0, 255); // blue
26. delay(1000);
27. setColor(255, 255, 0); // yellow
28. delay(1000);
29. setColor(80, 0, 80); // purple
30. delay(1000);
31. setColor(0, 255, 255); // aqua
32. delay(1000);
33. }
34.
35. void setColor(int red, int green, int blue)
36. {
37. #ifdef COMMON_ANODE
38. red = 255 - red;
39. green = 255 - green;
40. blue = 255 - blue;
41. #endif
42. analogWrite(redPin, red);
43. analogWrite(greenPin, green);
44. analogWrite(bluePin, blue);
45. }
The sketch starts by specifying which pins are going to be used for each of the colors:
Download file
Copy Code
1. int redPin = 11;
2. int greenPin = 10;
3. int bluePin = 9;
The next step is to write the 'setup' function. As we have learnt in earlier
lessons, the setup function runs just once after the Arduino has reset. In this
case, all it has to do is define the three pins we are using as being outputs.
1. void setup()
2. {
3. pinMode(redPin, OUTPUT);
4. pinMode(greenPin, OUTPUT);
5. pinMode(bluePin, OUTPUT);
6. }
Before we take a look at the 'loop' function, lets look at the last function in
the sketch.
Download file
Copy Code
This function takes three arguments, one for the brightness of the red,
green and blue LEDs. In each case the number will be in the range 0 to 255,
where 0 means off and 255 means maximum brightness. The function then
calls 'analogWrite' to set the brightness of each LED.
If you look at the 'loop' function you can see that we are setting the amount
of red, green and blue light that we want to display and then pausing for a
second before moving on to the next color.
1. void loop()
2. {
3. setColor(255, 0, 0); // red
4. delay(1000);
5. setColor(0, 255, 0); // green
6. delay(1000);
7. setColor(0, 0, 255); // blue
8. delay(1000);
9. setColor(255, 255, 0);// yellow
10. delay(1000);
Experiment No 7
Aim: Study the Temperature sensor and Write Program foe monitor
temperature using Arduino.
They come in a "TO-92" package which means the chip is housed in a plastic hemi-
cylinder with three legs. The legs can be bent easily to allow the sensor to be
plugged into a breadboard. You can also solder to the pins to connect long wires.
If you need to waterproof the sensor, you can see below for an Instructable for
how to make an excellent case.
Reading the Analog Temperature Data
Unlike the FSR or photocell sensors we have looked at, the TMP36 and friends
doesn't act like a resistor. Because of that, there is really only one way to read the
temperature value from the sensor, and that is plugging the output pin directly
into an Analog (ADC) input.
Remember that you can use anywhere between 2.7V and 5.5V as the power
supply. For this example I'm showing it with a 5V supply but note that you can
use this with a 3.3v supply just as easily. No matter what supply you use, the
analog voltage reading will range from about 0V (ground) to about 1.75V.
If you're using a 5V Arduino, and connecting the sensor directly into an
Analog pin, you can use these formulas to turn the 10-bit analog reading into a
temperature:
Voltage at pin in milliVolts = (reading from ADC) * (5000/1024)
This formula converts the number 0-1023 from the ADC into 0-5000mV (= 5V)
If you're using a 3.3V Arduino, you'll want to use this:
Voltage at pin in milliVolts = (reading from ADC) * (3300/1024)
This formula converts the number 0-1023 from the ADC into 0-3300mV (= 3.3V)
Then, to convert millivolts into temperature, use this formula:
Centigrade temperature = [(analog voltage in mV) - 500] / 10
Simple Thermometer
This example code for Arduino shows a quick way to create a temperature
sensor, it simply prints to the serial port what the current temperature is in
both Celsius and Fahrenheit.
1. //TMP36 Pin Variables
2. int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
3. //the resolution is 10 mV / degree centigrade with a
4. //500 mV offset to allow for negative temperatures
5.
6. /*
7. * setup() - this function runs once when you turn your Arduino on
8. * We initialize the serial connection with the computer
9. */
10. void setup()
11. {
12. Serial.begin(9600); //Start the serial connection with the computer
13. //to view the result open the serial monitor
14. }
15.
16. void loop() // run over and over again
17. {
18. //getting the voltage reading from the temperature sensor
19. int reading = analogRead(sensorPin);
20.
21. // converting that reading to voltage, for 3.3v arduino use 3.3
22. float voltage = reading * 5.0;
23. voltage /= 1024.0;
24.
25. // print out the voltage
26. Serial.print(voltage); Serial.println(" volts");
27.
28. // now print out the temperature
29. float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree
wit 500 mV offset
30. //to degrees ((voltage - 500mV)
times 100)
31. Serial.print(temperatureC); Serial.println(" degrees C");
32.
33. // now convert to Fahrenheit
34. float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
35. Serial.print(temperatureF); Serial.println(" degrees F");
36.
37. delay(1000);
38. }
Experiment No 8
Aim: Study and Implement RFID, NFC using Arduino.
Objectives: Student should get the knowledge of RFID, NFC using Arduino.
Hardware Requirements:
Lets 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.
Experiment No 9
Aim: Study and Implement MQTT Protocol using Arduino.
MQTT:
MQTT methods
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.
Experiment No 10
Aim: Study and Configure Raspberry Pi.
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.[8] By
November 2016 they had sold 11 million units[9][10], 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:
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.