Be Mech Iot-1
Be Mech Iot-1
SEMESTER -VIII
Objectives:
1. To learn microcontroller programming using 8051 and Arduino Development Board.
2. To acquaint with interfacing of simple peripheral devices to a microcontroller.
3. To acquaint with exchange of data using wireless communication.
4. To familiarize with logging the data on cloud platform.
Outcomes: Learner will able to...
1. Develop simple applications using microcontrollers 8051 and Arduino.
2. Interface simple peripheral devices to a Microcontroller.
3. Use microcontroller based embedded platforms in IoT.
4. Use wireless peripherals for exchange of data.
5. Setup cloud platform and log sensor data.
List of Experiments:
1. Interfacing experiments using 8051 Trainer kit and interfacing modules
a. display (LCD/LED/Seven Segment)
b. Stepper / DC Motor
2. Introduction to Arduino platform and programming
3. Simple Applications using Arduino Development Board (Any two)
a. Simple LED Blinking using development board
b. Building IOT Smart Switch using IOT
c. Pulse Width Modulation
d. Analog to Digital / Digital to Analog Conversion
4. Interfacing Arduino with a Sensor (Any one): Temperature Sensor / PIR/ Ultrasonic sensor/ IR
1 MECH Dept
IOT Lab –MEL802
Sensor/ Flame Sensor/ MQ6 Sensor/ Humidity sensor/ Raindrop Sensor, magnetometers, cameras,
accelerometers etc.
5. Interfacing Arduino with an Actuator (Any One): Motors / solenoids / Controllers etc.
6. Communication using Wireless Medium (Any One): WiFi / Bluetooth / Zigbee / RFID etc.
7. Setting up and Cloud Platform and logging Sensor Data on the platform.
Assessment:
Term Work
Term work shall consist of the experiments as mentioned above.
The distribution of marks for term work shall be as follows:
1. Laboratory work (Experiments): 20 marks
2. Attendance: 05 marks
End Semester Practical/Oral Examination:
Pair of Internal and External Examiner should conduct practical examination followed by Oral.
VISION
To nurture the talents of Mechanical engineers, making them highly
competent for growth of the society.
MISSION
To deliver excellence in teaching - learning process.
Promote safe, orderly, caring and supportive environment to learners.
Development of skilled engineers to perform innovative Research for
betterment of the society.
2 MECH Dept
IOT Lab –MEL802
C334.2 Students will be able to have an in-depth knowledge on interfacing the external devices to the
controllers.
C334.3 Students will be able to design a microcontroller based system with the help of the interfacing
devices.
3 MECH Dept
IOT Lab –MEL802
C334.4 Students will be able to have an in-depth knowledge of applying the concepts on real- time
applications.
CO-PO MAPPING
C334.1 3 - 1 - - - - - - - - - - -
C334.2 3 - 1 - - - - - - - - - 2 -
C334.3 3 - 3 - - - - - - - - - 2 -
C334.4 3 - 2 - - - - - - - - - 2 -
LIST OF EXPERIMENTS
4 MECH Dept
IOT Lab –MEL802
6
7
10
11
12
13
14
15
16
17
18
19
The 8051 memory is organized in a Harvard Architecture. Both the code memory space
5 MECH Dept
IOT Lab –MEL802
and data memory space begin at location 0x00 for internal or external memory which is different
from the Princeton Architecture where code and data share same memory space. The advantage
of the Harvard Architecture is not only doubling the memory capacity of the microcontroller
with same number of address lines but also increases the reliability of the microcontroller, since
there are no instructions to write to the code memory which is read only.
6 MECH Dept
IOT Lab –MEL802
Timer means which can give the delay of particular time between some events. For
example on or off the lights after every 2 sec. This delay can be provided through some assembly
7 MECH Dept
IOT Lab –MEL802
program but in microcontroller two hardware pins are available for delay generation. These
hardware pins can be also used for counting some external events. How much times a number is
repeated in the given table is calculated by the counter.
In MC8051, two timer pins are available T0 and T1, by these timers we can give the
delay of particular time if we use these in timer mode. We can count external pulses at these
pins if we use these pins in counter mode. 16 bits timers are available. Means we can generate
delay between 0000H to FFFFH. Two special function registers are available. If we want to
load T0 with 16 bit data then we can load separate lower 8 bit in TL0 and higher 8 bit in TH0. In
the same way for T1. TMOD, TCON registers are used for controlling timer operation.
8 MECH Dept
IOT Lab –MEL802
2.5 Oscillator
It is used for providing the clock to MC8051 which decides the speed or baud rate of
MC. We use crystal which frequency vary from 4MHz to 30 MHz, normally we use 11.0592
MHz frequency.
2.6 Interrupts
Interrupts are defined as requests because they can be refused (masked) if they are not
used, that is when an interrupt is acknowledged. A special set of events or routines are followed
to handle the interrupts. These special routines are known as interrupt handler or interrupt service
routines (ISR). These are located at a special location in memory. • INT0 and INT1 are the pins
for external interrupts.
9 MECH Dept
IOT Lab –MEL802
is also 0. The ALE (Address Latch Enable) activates the port 0 joined with port 2 to provide 16
bit external address bus to access the external memory. The ALE multiplexes the P0: 1 for
latching address on P0 as A0-A7 in the 16 bit address buss, 0 for latching P0 as data I/O. P0.x
is named ADx because P0 is multiplexed for Address bus and Data bus at different clock time.
WR' provides the signal to write external data memory RD' provides the signal to read external
data and code memory.
PORT P1 (Pins 1 to 8): The port P1 is a port dedicated for general I/O purpose. The
other ports P0, P2 and P3 have dual roles in addition to their basic I/O function.
• PORT P0 (pins 32 to 39): When the external memory access is required then Port P0 is
multiplexed for address bus and data bus that can be used to access external memory in
conjunction with port P2. P0 acts as A0-A7 in address bus and D0-D7 for port data. It can be
used for general purpose I/O if no external memory presents.
• PORT P2 (pins 21 to 28): Similar to P0, the port P2 can also play a role (A8-A15) in the
address bus in conjunction with PORT P0 to access external memory.
PORT P3 (Pins 10 to 17): In addition to acting as a normal I/O port,
P3.0 can be used for serial receive input pin(RXD) • P3.1 can be used for serial
transmit output pin(TXD) in a serial port,
P3.2 and P3.3 can be used as external interrupt pins(INT0’ and INT1’),
P3.4 and P3.5 are used for external counter input pins(T0 and T1),
P3.6 and P3.7 can be used as external data memory write and read control signal
pins(WR’ and RD’)read and write pins for memory access.
10 MECH Dept
IOT Lab –MEL802
Date:
AIM: Write an assembly language program to for toggling the LED connected to one of the port
pins of 8051.
THEORY:
There are two ways which we can interface LED to the Microcontroller 8051. But the
connections and programming techniques will be different. This article provides the information
on LED interfacing with 8051 and LED blinking code for AT89C52/ AT89C51 Microcontroller.
11 MECH Dept
IOT Lab –MEL802
Observe carefully the interface LED 2 is in forward biased because the input voltage of 5v
connected to the positive terminal of the LED, So here the Microcontroller pin should be at
LOW level and vice versa with the interface 1 connections.
The resistor is important in LED interfacing to limit the flowing current and avoid damaging the
LED and/or MCU.
Interface 1 will glow LED, only if the PIN value of the MC is HIGH as current flows towards
the ground.
Interface 2 will glow LED, only if the PIN value of the MC is LOW as current flows
towards PIN due to its lower potential.
PROGRAM:
ORG 0000H
LOOP: SETB P1.0
ACALL DELAY
CLR P1.0
ACALL DELAY
SJMP LOOP
DELAY: MOV R0,#100
AGAIN: MOV R1,#200
BACK: DJNZ R1,BACK
DJNZ R0,AGAIN
RET
END
12 MECH Dept
IOT Lab –MEL802
SCHEMATIC DIAGRAM:
INFERENCE:
13 MECH Dept
IOT Lab –MEL802
AIM: Write an assembly language program for displaying the decimal numbers in 7 Segment
display.
THEORY:
The 7-segment display, also written as “seven segment display”, consists of seven LEDs
(hence its name) arranged in a rectangular fashion as shown. Each of the seven LEDs is called a
segment because when illuminated the segment forms part of a numerical digit (both Decimal
and Hex) to be displayed. An additional 8th LED is sometimes used within the same package
thus allowing the indication of a decimal point, (DP) when two or more 7-segment displays are
connected together to display numbers greater than ten.
Each one of the seven LEDs in the display is given a positional segment with one of its
connection pins being brought straight out of the rectangular plastic package. These individually
LED pins are labelled from a through to g representing each individual LED. The other LED
pins are connected together and wired to form a common pin.So by forward biasing the
appropriate pins of the LED segments in a particular order, some segments will be light and
others will be dark allowing the desired character pattern of the number to be generated on the
display. This then allows us to display each of the ten decimal digits 0 through to 9 on the same
7-segment display.
The displays common pin is generally used to identify which type of 7-segment display it
is. As each LED has two connecting pins, one called the “Anode” and the other called the
“Cathode”, there are therefore two types of LED 7-segment display called: Common
Cathode (CC) and Common Anode (CA).
The difference between the two displays, as their name suggests, is that the common
cathode has all the cathodes of the 7-segments connected directly together and the common
anode has all the anodes of the 7-segments connected together and is illuminated as follows.The
Common Cathode (CC) – In the common cathode display, all the cathode connections of the
LED segments are joined together to logic “0” or ground. The individual segments are
14 MECH Dept
IOT Lab –MEL802
illuminated by application of a “HIGH”, or logic “1” signal via a current limiting resistor to
forward bias the individual Anode terminals (a-g).
PROGRAM:
ORG 0000H
LOOP:MOV DPTR,#0100H
MOV R1,#0AH
BACK:CLR A
MOVC A,@A+DPTR
MOV P2,A
ACALL DELAY
INC DPTR
DJNZ R1,BACK
SJMP LOOP
DELAY:MOV R5,#05
BACK2: MOV R3,#255
15 MECH Dept
IOT Lab –MEL802
SCHEMATIC DIAGRAM:
INFERENCE:
16 MECH Dept
IOT Lab –MEL802
Date:
AIM: Write an assembly language program for interfacing stepper motor with
8051.
THEORY:
A Stepper Motor or a step motor is a brushless, synchronous motor which divides a full
rotation into a number of steps. Unlike a brushless DC motor which rotates continuously when a
fixed DC voltage is applied to it, a step motor rotates in discrete step angles. The Stepper
Motors therefore are manufactured with steps per revolution of 12, 24, 72, 144, 180, and 200,
resulting in stepping angles of 30, 15, 5, 2.5, 2, and 1.8 degrees per step. The stepper motor can
be controlled with or without feedback. Stepper motors work on the principle of
electromagnetism. There is a soft iron or magnetic rotor shaft surrounded by the electromagnetic
stators. The rotor and stator have poles which may be teethed or not depending upon the type of
stepper. When the stators are energized the rotor moves to align itself along with the stator (in
case of a permanent magnet type stepper) or moves to have a minimum gap with the stator (in
case of a variable reluctance stepper). This way the stators are energized in a sequence to rotate
the stepper motor..
17 MECH Dept
IOT Lab –MEL802
PROGRAM:
ORG 0000H
MOV A,#66H
LOOP:MOV P2,A
ACALL DELAY
RR A
SJMP LOOP
DELAY:MOV R5,#0AH
AGAIN:MOV R3,#0FFH
BACK:DJNZ R3,BACK
DJNZ R5,AGAIN
RET
END
SCHEMATIC DIAGRAM:
INFERENCE:
18 MECH Dept
IOT Lab –MEL802
THEORY:
Arduino is a prototype platform (open-source) based on an easy-to-use hardware and software. It
consists of a circuit board, which can be programed (referred to as a microcontroller) and a
ready-made software called Arduino IDE (Integrated Development Environment), which is used
to write and upload the computer code to the physical board.
Arduino provides a standard form factor that breaks the functions of the micro-controller into a
more accessible package.
19 MECH Dept
IOT Lab –MEL802
Arduino UNO
Board Details
20 MECH Dept
IOT Lab –MEL802
Power USB
Arduino board can be powered by using the USB cable from your computer. All you
need to do is connect the USB cable to the USB connection (1).
21 MECH Dept
IOT Lab –MEL802
Voltage Regulator
The function of the voltage regulator is to control the voltage given to the Arduino
board and stabilize the DC voltages used by the processor and other elements.
Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does Arduino
calculate time? The answer is, by using the crystal oscillator. The number printed on
top of the Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000
Hertz or 16 MHz.
Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning. You
can reset the UNO board in two ways. First, by using the reset button (17) on the
board. Second, you can connect an external reset button to the Arduino pin labelled
RESET (5).
Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These pins can
read the signal from an analog sensor like the humidity sensor or temperature sensor
and convert it into a digital value that can be read by the microprocessor.
Main microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as the brain
of your board. The main IC (integrated circuit) on the Arduino is slightly different
from board to board. The microcontrollers are usually of the ATMEL Company. You
must know what IC your board has before loading up a new program from the
Arduino IDE. This information is available on the top of the IC. For more details
about the IC construction and functions, you can refer to the data sheet.
22 MECH Dept
IOT Lab –MEL802
ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting
of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI
(Serial Peripheral Interface), which could be considered as an "expansion" of the
output. Actually, you are slaving the output device to the master of the SPI bus.
TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive). They appear
in two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate
the pins responsible for serial communication. Second, the TX and RX led (13). The
TX led flashes with different speed while sending the serial data. The speed of
flashing depends on the baud rate used by the board. RX flashes during the receiving
process.
Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM
(Pulse Width Modulation) output. These pins can be configured to work as input
digital pins to read logic values (0 or 1) or as digital output pins to drive different
modules like LEDs, relays, etc. The pins labeled “~” can be used to generate PWM.
AREF
AREF stands for Analog Reference. It is sometimes, used to set an external reference
voltage (between 0 and 5 Volts) as the upper limit for the analog input pins.
Arduino IDE
Arduino IDE is an open source software that is used to program the Arduino controller
board
Based on variations of the C and C++ programming language
It can be downloaded from Arduino's official website and installed into PC
23 MECH Dept
IOT Lab –MEL802
Set Up
Power the board by connecting it to a PC via USB cable
Launch the Arduino IDE
Set the board type and the port for the board
TOOLS -> BOARD -> select your board
TOOLS -> PORT -> select your port
24 MECH Dept
IOT Lab –MEL802
Sketch Structure
A sketch can be divided into two parts :
- Setup ( )
- Loop ( )
The function setup( ) is the point where the code starts , just like the main ( ) function in
C and C++
I/O Variables, pin modes are initialized in the Setup( ) function
Loop( ) function, as the name suggests, iterates the specified task in the program
25 MECH Dept
IOT Lab –MEL802
Conclusion:
Arduino IDE
Step 1 − First you must have your Arduino board (you can choose your favorite board) and a
USB cable. In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino Mega 2560,
or Diecimila, you will need a standard USB cable (A plug to B plug), the kind you would
connect to a USB printer as shown in the following image.
In case you use Arduino Nano, you will need an A to Mini-B cable instead as shown in the
following image.
26 MECH Dept
IOT Lab –MEL802
27 MECH Dept
IOT Lab –MEL802
28 MECH Dept
IOT Lab –MEL802
29 MECH Dept
IOT Lab –MEL802
Here, we are selecting just one of the examples with the name Blink. It turns the LED on and off
with some time delay. You can select any other example from the list.
Step 6 − Select your Arduino board.
To avoid any error while uploading your program to the board, you must select the correct
Arduino board name, which matches with the board connected to your computer.
Go to Tools → Board and select your board.
Here, we have selected Arduino Uno board according to our tutorial, but you must select the
name matching the board that you are using.
30 MECH Dept
IOT Lab –MEL802
31 MECH Dept
IOT Lab –MEL802
he Arduino software is open-source. The source code for the Java environment is released under
the GPL and the C/C++ microcontroller libraries are under the LGPL.
Sketch − The first new terminology is the Arduino program called “sketch”.
Structure
Arduino programs can be divided in three main parts: Structure, Values (variables and
constants), and Functions. In this tutorial, we will learn about the Arduino software program,
step by step, and how we can write the program without any syntax or compilation error.
Let us start with the Structure. Software structure consist of two main functions −
Setup( ) function
Loop( ) function
32 MECH Dept
IOT Lab –MEL802
Void setup ( ) {
}
PURPOSE − The setup() function is called when a sketch starts. Use it to initialize the
variables, pin modes, start using libraries, etc. The setup function will only run once, after
each power up or reset of the Arduino board.
INPUT − -
OUTPUT − -
RETURN − -
Void Loop ( ) {
}
PURPOSE − After creating a setup() function, which initializes and sets the initial
values, the loop() function does precisely what its name suggests, and loops
consecutively, allowing your program to change and respond. Use it to actively control
the Arduino board.
INPUT − -
OUTPUT − -
RETURN − -
33 MECH Dept
IOT Lab –MEL802
Conclusion:
Experiment No. 5 Simple Applications using Arduino Development Board
(Any two)
AIM:
To write a program to make LED blink using Arduino.
COMPONENTS REQUIRED:
1. Arduino Uno, LED
2. Jumper wires.
3. Connecting cable or USB cable.
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start ->Arduino IDE -2.0.3
STEP 3: Then enter the coding in Arduino Software.
STEP 4: Compile the coding in Arduino Software.
STEP 5: In Arduino board, connect VCC to power supply 5V and connect to
ground
STEP 6: Connect the Arduino board with USB cable to the system.
STEP 7: Select tools -> select board ->Arduino UNO -> select processor -> AT
Mega 328 p and the select port.
STEP 8: Upload the coding in Arduino board and now for the LED to blink.
STEP 9: Then, the output will be displayed in the serial monitor.
STEP 10: Stop the process.
Circuit Diagram:
34 MECH Dept
IOT Lab –MEL802
Coding:
35 MECH Dept
IOT Lab –MEL802
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0) {
entry= Serial.read();
if(entry== '1'){
digitalWrite(led1,HIGH);
{
Serial.println("LED High");
}
}
else if (entry == '0'){
digitalWrite(led1,LOW);
{
Serial.println("LED LOW");
}
}
else{
Serial.println("Invalid input");
}
}
}
Result :
Conclusion :
36 MECH Dept
IOT Lab –MEL802
BLOCK DIAGRAM:
37 MECH Dept
IOT Lab –MEL802
CODING:
#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to dht DHT;
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600); delay(500);
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);
}
void loop()
{
DHT.read11(dht_apin);
Serial.print("THS:th01:None:");
Serial.print(DHT.humidity); Serial.print("%,");
//Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("degC");
delay(2000);//Wait 5 seconds before accessing sensor again.
}
38 MECH Dept
IOT Lab –MEL802
OUTPUT:
Conclusion:
Thus the output to get temperature notification using Arduino has
successfully executed.
39 MECH Dept
IOT Lab –MEL802
500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite () is on a
scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and
analogWrite(127) is a 50% duty cycle (on half the time) for example.
Waveform:
On some microcontrollers PWM is only available on selected pins. Please consider the pinout
diagram of your board to find out which ones you can use for PWM. They are denoted with a
tilde sign (~).
Once you get this example running, grab your Arduino and shake it back and forth. What you
are doing here is essentially mapping time across the space. To our eyes, the movement blurs
each LED blink into a line. As the LED fades in and out, those little lines will grow and shrink
in length.
Circuit Diagram:
40 MECH Dept
IOT Lab –MEL802
Coding:
int ledPin = 6;
int brightness = 0;
int fadeAmount = 5;
41 MECH Dept
IOT Lab –MEL802
42 MECH Dept