Industrial Training Report (Iot)
Industrial Training Report (Iot)
Industrial Training Report (Iot)
ON
IOT AND PYTHON
One of the most popular era of computer world is from the generation
5'. Here new trends like AI, Internet of things (IoT) etc are came into
force. Internet of Technology or simply IoT is considered as an Internet
technology which connects devices, nodes and other tools to the
internet by means of wireless technologies. By using the IoT one can
easily does a lot of things through internet without human interaction.
In this paper it is mainly focus on the relationship between IoT and one
of the important programming language used today, that is Python.This
report is fully based on the 6 -week of industrial training internship
completed on STATIC.INT EDUCARE
Contents :
Python:
1. Introduction of python.
2. How to install python.
3. Basic Building Blocks and of Python .
4. Control Flow Statements in python .
5. Data Structures in Python
6. Functions in Python.
7. File Handling and Exception Handling in programming.
8. Object oriented programming in Python
9. Raise and User Defined Exceptions in Python.
10.Benefits of learning python.
1. Introduction of iot.
2. Software used
3. Hardware used
Projects:
i. Blinking LED on Node MCU.
ii. Alternative blinking on Node MCU.
iii. Alarm using IR sensor.
PYTHON
1.INTRODUCTION :
What is Python?
Python is a popular programming language. It was created by Guido van
Rossum, and released in 1991. It was designed with an emphasis on
code readability, and its syntax allows programmers to express their
concepts in fewer lines of code.
Python is a programming language that lets you work quickly and
integrate systems more efficiently.
It is used for:
Installing python :
Many working frameworks, for instance, macOS and Linux, accompany
Python pre-introduced. The rendition of Python that accompanies your
operation framework is called your framework Python.
• They start with letter A-Z or a-z or underscore [ _ ]. Internally, they can
have digits but not to start with.
• Their length is not Limited. But referred to be meaningful.
• They should not contain whitespaces.
• They are case sensitive. That is 'num' and 'NUM' are different.
• They should not be keywords.(it will show error, saying "Syntax error:
Invalid syntax") .
Some example of valid and invalid identifiers :
• num #valid
• wordCount #valid
• account_number #valid
• x_co-ordinate #valid
• _4 #valid, but meaningless
• ErrorNumber4 #valid
• Plot#3 #invalid because of special symbol #
• account number #invalid because of space
• 255 #invalid because starts with digit
• empno. #invalid because of special symbol .
• and #invalid because and is a keyboard
Python keywords
Keywords are the words whose meaning are alread known to the
compiler and also called as reserved words.
Python Variables:
Variables are the reserved memory locations to store a runtime value
that has an identifier (name). It means when we create a variable, it
reserves a memory location. In previous programming languages, we
also said that variable is the type of memory block that allows changing
its value during runtime.
Based on the data type of a variable, the interpreter allocates memory
and decides what can be stored in variable's memory. Therefore, by
assigning different data types to variables, we can store integers,
decimals or characters in variable's memory.
The best part of Python variable is, It do not need explicit declaration of
variables. The declaration and creation happens automatically when we
assign a value to variable. i.e. the identifier that appears on left side of
assignment operator (=) creates memory location.
For example:
num = 45 # will make "integer" assignment to "num"
Python Comments:
Comments are very important while writing a program. It describes the
purpose and application of written code. So that anyone else, who is
updating or understanding the written code, does not have hard time to
figure it out. In Python we have two types of comments.
We know that comment is the section in Python code that will neither be
compiled nor executed. It is only for understanding and testing purpose.
1. Single-line comment
2. Multi-line comment
Example 1:
if n %2 ==0:
# means, if number is divisible by 2
print("This number is even")
Example 1:
Example 2:
Python Indentation:
Most of the previous programming languages uses pair of curly braces {
} to define a logical block. But Python uses indentation.
A logical block of code (such as, body of a function, loop, class, etc.)
starts with indentation and ends with the first unindented line.
if True:
print("Hello")
#can also be written as:
if True: print("Hello"); a=5
But the indenting style is more preferred and convenient. We
found many C++ and Java programmers giving additional spaces at the
beginning of any statement. But if you try do the same as java ,c++ in
Python, it will give you an error "Indetation-Error".
1. If statement
2. If … else statement
3. If … elif …else statement
4. Nested if statement
5. Loop – For Loop, While Loop
If condition statement :
Syntax of if
if test_expression:
statement(s)
If … else statement :
Syntax of if … else
if test_expression:
Body of if
else:
Body of else
if test_expression:
Body of if
elif test_expression:
Body of elif
else:
Body of else
9. The elif is short for else if. It allows us to check for multiple
expressions.
10. If the condition for if is False, it checks
the condition of the next elif block and so on.
11. If all the conditions are False, the body of
else is executed.
12. Only one block among the several
if...elif...else blocks is executed according to the condition.
13. The if block can have only one else block.
But it can have multiple elif blocks.
Nested if statement :
14. We can have a if...elif...else statement
inside another if...elif...else statement. This is called nesting in
computer programming.
Nested if Example:
num = 5
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
Output:
Positive Number
LOOP :
1. For Loop
2. While Loop
For Loop :
The for loop in Python is used to iterate over a sequence (list, tuple,
string) or other
Body of for
Here, var is the variable that takes the value of the item inside the
sequence on each iteration.
Loop continues until we reach the last item in the sequence. The body
of for loop is
While Loop :
Body of while
Lists:
Lists are used to store data of different data types in a sequential manner. There are
addresses assigned to every element of the list, which is called as Index. The index
value starts from 0 and goes on until the last element called the positive index. There
is also negative indexing which starts from -1 enabling you to access elements from
the last to first. Let us now understand lists better with the help of an example
program.
Creating a list
To create a list, you use the square brackets and add elements into it accordingly. If
you do not pass any elements inside the square brackets, you get an empty list as the
output.
1 my_list = [] #create empty list
2 print(my_list)
4 print(my_list)
Output:
[]
[1, 2, 3, ‘example’, 3.132]
Dictionary:
Dictionaries are used to store key-value pairs. To understand better, think of a phone
directory where hundreds and thousands of names and their corresponding numbers
have been added. Now the constant values here are Name and the Phone Numbers
which are called as the keys. And the various names and phone numbers are the
values that have been fed to the keys. If you access the values of the keys, you will
obtain all the names and phone numbers. So that is what a key-value pair is. And in
Python, this structure is stored using Dictionaries. Let us understand this better with
an example program.
Creating a Dictionary
Dictionaries can be created using the flower braces or using the dict() function. You
need to add the key-value pairs whenever you work with dictionaries.
2 print(my_dict)
4 print(my_dict)
Output:
{}
{1: ‘Python’, 2: ‘Java’}
TUPLES:
Tuples are the same as lists are with the exception that the data once entered into the
tuple cannot be changed no matter what. The only exception is when the data inside
the tuple is mutable, only then the tuple data can be changed. The example program
will help you understand better.
Creating a Tuple
You create a tuple using parenthesis or using the tuple() function.
2 print(my_tuple)
Output:
(1, 2, 3)
Sets:
Sets are a collection of unordered elements that are unique. Meaning that even if the
data is repeated more than one time, it would be entered into the set only once. It
resembles the sets that you have learnt in arithmetic. The operations also are the
same as is with the arithmetic sets. An example program would help you understand
better.
Creating a set
Sets are created using the flower braces but instead of adding key-value pairs, you
just pass values to it.
2 print(my_set)
Output:
{1, 2, 3, 4, 5}
FUNCTIONS IN PYTHON
Functions help break our program into smaller and modular chunks. As our
program grows larger and larger, functions make it more organized and
manageable.
Syntax of Function
def function_name(parameters):
"""docstring"""
statement(s)
Above shown is a function definition that consists of the following components.
6. One or more valid python statements that make up the function body. Statements
must have the same indentation level (usually 4 spaces).
def greet(name):
"""
This function greets to
the person passed in as
a parameter
"""
print("Hello, " + name + ". Good morning!")
File Handling :
Opening a file in Python:
Python has a built-in open() function to open a file. This function returns a file
object, also called a handle, as it is used to read or modify the file accordingly.
Python has a built-in open() function to open a file. This function returns a file
object, also
We can specify the mode while opening a file. In mode, we specify whether we
want to
read r, write w or append a to the file. We can also specify if we want to open the
file in text mode or binary mode.
The default is reading in text mode. In this mode, we get strings when reading from
the
file.
On the other hand, binary mode returns bytes and this is the mode to be used when
• "r" - Read - Default value. Opens a file for reading, error if the file does not exist.
• "a" - Append - Opens a file for appending, creates the file if it does not exist.
• "w" - Write - Opens a file for writing, creates the file if it does not exist.
• "x" - Create - Creates the specified file, returns an error if the file exists.
In addition you can specify if the file should be handled as binary or text mode
Exception Handling :
Python logical errors (Exceptions)
Errors that occur at runtime (after passing the syntax test) are called exceptions or
logical errors.
For instance, they occur when we try to open a file(for reading) that does not exist
(FileNotFoundError), try to divide a number by zero (ZeroDivisionError), or try to
import a module that does not exist (ImportError).
Whenever these types of runtime errors occur, Python creates an exception object.
If not handled properly, it prints a traceback to that error along with some details
about why that error occurred.
>>> 1 / 0
>>> open("imaginary.txt")
1.Inheritance:
Inheritance is the capability of one class to derive or inherit the
properties from another class. The benefits of inheritance are:
1. It represents real-world relationships well.
2. It provides reusability of a code. We don’t have to write the same
code again and again. Also, it allows us to add more features to a
class without modifying it.
3. It is transitive in nature, which means that if class B inherits from
another class A, then all the subclasses of B would automatically
inherit from class A.
`
2.Encapsulation:
Encapsulation is one of the fundamental concepts in object-oriented
programming (OOP). It describes the idea of wrapping data and the
methods that work on data within one unit. This puts restrictions on
accessing variables and methods directly and can prevent the accidental
modification of data. To prevent accidental change, an object’s variable
can only be changed by an object’s method. Those types of variables
are known as private variable.
A class is an example of encapsulation as it encapsulates all the data
that is member functions, variables, etc.
3. Polymorphism:
Polymorphism in python is used for a common function name
that can be used for different types. This concept is widely applied in
object-oriented based python programming. Like other programming
languages say Java, C+, polymorphism is also implemented in python
for different purpose commonly Duck Typing, Operator overloading
and Method overloading, and Method overriding. This polymorphism
process can be achieved in two main ways namely overloading and
overriding.
Python throws errors and exceptions when there is a code gone wrong,
which may cause the program to stop abruptly. Python also provides an
exception handling method with the help of try-except. Some of the
standard exceptions which are most frequent include IndexError,
ImportError, IOError, ZeroDivisionError, TypeError, and
FileNotFoundError. A user can create his own error using the exception
class.
class MyError(Exception):
# Constructor or Initializer
self.value = value
# __str__ is to print() the value
def __str__(self):
return(repr(self.value))
try:
raise(MyError(3*2))
Output:
('A New Exception occured: ', 6)
Benefits of learning :
1. Improved Productivity.
2. Interpreted Language
3. Dynamically Type
4. Free and Open source.
5. Vast libraries support.
6. Short code texts.
7. Readable (Interpretable).
8. Easy to learn
IOT (Internet Of Things)
INTRODUCTION:
SOFTWARE USED
Aurdino:
Arduino is an open-source hardware and software company, project,
and user community that designs and manufactures single-board
microcontrollers and microcontroller kits for building digital devices. Its
hardware products are licensed under a CC-BY-SA license, while
software is licensed under the GNU Lesser General Public
License (LGPL) or the GNU General Public License (GPL) permitting
the manufacture of Arduino boards and software distribution by anyone.
Arduino boards are available commercially from the official website or
through authorized distributors.
Arduino board designs use a variety of microprocessors and controllers.
The boards are equipped with sets of digital and
analog input/output (I/O) pins that may be interfaced to various
expansion boards ('shields') or breadboards (for prototyping) and other
circuits. The boards feature serial communications interfaces,
including Universal Serial Bus (USB) on some models, which are also
used for loading programs. The microcontrollers can be programmed
using the C and C++ programming languages, using a standard API
which is also known as the "Arduino language". In addition to using
traditional compiler toolchains, the Arduino project provides
an integrated development environment (IDE) and a command line tool
developed in Go.
The Arduino project began in 2005 as a tool for students at
the Interaction Design Institute Ivrea, Italy, aiming to provide a low-cost
and easy way for novices and professionals to create devices that interact
with their environment using sensors and actuators. Common examples
of such devices intended for beginner hobbyists include
simple robots, thermostats and motion detectors.
HARDWARE USED
NodeMCU:
.
The NodeMCU (Node MicroController Unit) is an open-source software
and hardware development environment built around an inexpensive
System-on-a-Chip (SoC) called the ESP8266. The ESP8266, designed
and manufactured by Espressif Systems, contains the crucial elements of
a computer: CPU, RAM, networking (WiFi), and even a modern
operating system and SDK. That makes it an excellent choice for
Internet of Things (IoT) projects of all kinds.
However, as a chip, the ESP8266 is also hard to access and use. You
must solder wires, with the appropriate analog voltage, to its pins for the
simplest tasks such as powering it on or sending a keystroke to the
“computer” on the chip. You also have to program it in low-level
machine instructions that can be interpreted by the chip hardware. This
level of integration is not a problem using the ESP8266 as an embedded
controller chip in mass-produced electronics. It is a huge burden for
hobbyists, hackers, or students who want to experiment with it in their
own IoT projects.
IR SENSOR:
.An infrared sensor (IR sensor) is a radiation-sensitive optoelectronic
component with a spectral sensitivity in the infrared wavelength range
780 nm … 50 µm. IR sensors are now widely used in motion detectors,
which are used in building services to switch on lamps or in alarm
systems to detect unwelcome
JUMPER WIRES:
LED’S:
A light-emitting diode (LED) is
a semiconductor light source that emits light when current flows through
it. Electrons in the semiconductor recombine with electron holes,
releasing energy in the form of photons. The color of the light
(corresponding to the energy of the photons) is determined by the energy
required for electrons to cross the band gap of the semiconductor. White
light is obtained by using multiple semiconductors or a layer of light-
emitting phosphor on the semiconductor device.
RESISTORS:
USB:
PROJECTS
Source code:
After burning the Code in NodeMCU you’ll see a small LED on
NodeMCU will start blinking. The Blinking speed can be controlled by
reducing the delay value in the code and reuploading it into NodeMCU
This project detects motion or obstacle and acts accordingly I.e., beeps
or can customize according to our will .the Components required for this
project are IR sensor .buzzer, wires and NODEMCU ESP8266. the
required code is given below.
SOURCE CODE:
END OF REPORT
____________________________________________________