1 8051 Assembly Language Experiments Using Simulator
1 8051 Assembly Language Experiments Using Simulator
1 8051 Assembly Language Experiments Using Simulator
AIM:
To write 8051 assembly language program for arithmetic operations like
(addition,subtraction,multiplication and division) and verify the output of the experiment
using simulator.
Apparatus required:
1.computer
2.keil vision 5 simulator
Procedure:
1.Double click the keil icon on the desktop.
2. Close any previous projects that were opened using – Project -> Close.
3.Go to project ->New μ vision project.
4.Name the file and save.
5.Search and select AT89C51 and then click ok.
6.Copy’startup,A51’ to project folder and add file to project will be displayed.click No.
7.Create a source file using File->New and type the program and save as (filename.asm).
8.Set the target option by clicking the + symbol in target1.
9.Right click on the source file and add existing file to group ‘source group 1’.
10.Select file.asm and add,close.
11.Build the project using project->Build target.
12. Any errors in the code are indicated by – “Target not created” in the Build window, along
with the error line. Correct the errors and save it.
13. Go to Debug->Start/Stop debug session.
14.Then running with code size limit 2k will be displayed.Click OK.
15. The program is run using the Debug->Run command.
PROGRAM:
org 0000h
mov a,#02h
add a,#03h
mov r1,a
clr a
clr c
mov a,#05h
subb a,#02h
mov r2,a
mov a,#03h
mov b,#04h
mul ab
mov r3,a
mov r4,b
clr a
mov a,#95h
mov b,#10h
div ab
mov r5,a
mov r6,b
end
ALGORITHM :
CALCULATION:
OUTPUT:
Addition
r1=
Subtraction
r2=
Multiplication
r3=
r4=
Division
r5=
r6=
Result:Thus the 8051 assembly language program for arithmetic operations like
(addition,subtraction,multiplication and division) was written and verified using Keil
simulator.
EX No:2 TEST DATA TRANSFER BETWEEN REGISTER AND MEMORY
Aim:
To test the data transfer between register and memory using simulator.
Apparatus required:
1.computer
2.keil vision 5 simulator
Procedure:
1.Double click the keil icon on the desktop.
2. Close any previous projects that were opened using – Project -> Close.
3.Go to project ->New μ vision project.
4.Name the file and save.
5.Search and select AT89C51 and then click ok.
6.Copy’startup,A51’ to project folder and add file to project will be displayed.click No.
7.Create a source file using File->New and type the program and save as (filename.asm).
8.Set the target option by clicking the + symbol in target1.
9.Right click on the source file and add existing file to group ‘source group 1’.
10.Select file.asm and add,close
11.Build the project using project->Build target.
12. Any errors in the code are indicated by – “Target not created” in the Build window, along
with the error line. Correct the errors and save it.
13. Go to Debug->Start/Stop debug session.
14.Then running with code size limit 2k will be displayed.Click OK.
15.Go to view -> Memory windows ->select the memory 2 (or)any memory.
16.Type the memory address as Memory 2 I:0x20 and then press enter.
17.Right click on the first memory data 00 and click modify memory.
20.To see the output in the memory address change as Memory 2 I:0x40 and then press
enter.
PROGRAM:
mov r0,#20h //source address
OUTPUT:
I:0X40 20,30,40,6, 5,8,50
RESULT:
Apparatus required:
1.computer
2.keil vision 5 simulator
Procedure:
1.Double click the keil icon on the desktop.
2. Close any previous projects that were opened using – Project -> Close.
3.Go to project ->New μ vision project.
4.Name the file and save.
5.Search and select AT89C51 and then click ok.
6.Copy’startup,A51’ to project folder and add file to project will be displayed.click No.
7.Create a source file using File->New and type the program and save as (filename.C).
8.Set the target option by clicking the + symbol in target1.
9.Right click on the source file and add existing file to group ‘source group 1’.
10.Select file.C and add ,close.
11.Build the project using project->Build target.
12. Any errors in the code are indicated by – “Target not created” in the Build window, along
with the error line. Correct the errors and save it.
13. Go to Debug->Start/Stop debug session.
14.Then running with code size limit 2k will be displayed.Click OK.
15.Go to peripherals->select the corresponding I/O ports and perform the arithmetic and
logical operations.
16.Press F11 to see the output.
PROGRAM:
Addition:
#include<reg51.h>
Void main(Void)
{
Unsigned char a,b,c;
While(1)
{
P1=0xff; // declare as input port
P2=0xff; //declare as input port
a=P1;
b=P2;
c=a+b;
P3=c;
}
}
Subtraction:
#include<reg51.h>
Void main(Void)
{
Unsigned char a,b,c;
While(1)
{
P1=0xff;
P2=0xff;
a=P1;
b=P2;
c=a-b;
P3=c;
}
}
Multiplication:
#include<reg51.h>
Void main(Void)
{
Unsigned char a,b,c;
While(1)
{
P1=0xff;
P2=0xff;
a=P1;
b=P2;
c=a*b;
P3=c;
}
}
Division:
#include<reg51.h>
Void main(Void)
{
Unsigned char a,b,c;
While(1)
{
P1=0xff; // declare as input port
P2=0xff; //declare as input port
a=P1;
b=P2;
c=a/b;
P3=c;
}
}
Logical operations Program:
#include<reg51.h>
Void main(Void)
{
P0=0x35&0x0F;
P1=0x04|0x68;
P2=0x54^0x78;
P3=~0x55;
}
Manual calculations:
OUTPUT:(Arithmetic operation)
P0=
P1=
P2=
P3=
OUTPUT:(Logical operation)
P0=
P1=
P2=
P3=
RESULT:
Thus the program for arithmetic operations like (addition,subtraction,multiplication and
division) and logical operations like(AND,OR,EX-OR,NOT) using embedded C was written and
the output is executed.
ADDITION(FLOWCHART)
Start
Increment DPTR
Check
Yes Increment R0-
whether CF =0 register
No
Increment DPTR and
store the sum
(A-register) in
memory
Stop
Expt. No. 4 a)
PERFORM ALU OPERATIONS USING 8051
ADDITION OF TWO 8 BIT NUMBERS
AIM:
To write an assembly language program to perform addition of two 8-bit numbers with and
without carry using 8051 Microcontroller.
APPARATUS REQUIRED:
2. Keyboard.
PROGRAM:
INPUT OUTPUT
CALCULATION:
WITHOUT CARRY
INPUT OUTPUT
ADDRE DATA ADDRE DATA
SS
4500
SS
4502
4501
4503
9001
CALCULATION:
RESULT:
Thus the assembly language program to perform addition of two 8-bit numbers with and without carry using
8051 Microcontroller was executed successfully and output verified.
SUBTRACTION OF TWO 8 BIT NUMBERS(FLOW CHART)
Start
Clear R0 for
carry
Load address of
data
in DPTR
Increment DPTR
Yes Increment
Check R0-register
whether CF =0
No
Increment DPTR
and store the sum
(A-register) in
memory
Increment DPTR
and
store the
carry (R0-
register) in
Stop
Expt. No. 4 b)
SUBTRACTION OF TWO 8 BIT NUMBERS
AIM:
To write an assembly language program to perform subtraction of
two 8-bit numbers with and without borrow using 8051 Microcontroller.
APPARATUS REQUIRED:
2. Keyboard.
PROGRAM:
INPUT OUTPUT
CALCULATION:
RESULT:
Thus the assembly language program to perform Subtraction of two 8-bit numbers with and without carry
using 8051 Microcontroller was executed successfully and output verified
MULTIPLICATION OF TW0 8 BIT NUMBERS(FLOW CHART)
Start
Increment DPTR
Stop
Expt. No. 4 c)
AIM:
To write an assembly language program to perform multiplication of
two 8-bit numbers using 8051 Microcontroller.
APPARATUS REQUIRED:
2. Keyboard.
PROGRAM:
CALCULATION:
RESULT:
Thus the assembly language program to perform multiplications of two 8-bit numbers with and without
carry using 8051 Microcontroller was executed successfully and output verified
DIVISION OF TW0 8 BIT NUMBER(FLOW CHART)
Start
Increment DPTR
Stop
Expt. No. 4 d)
DIVISION OF TW0 8 BIT NUMBERS
AIM:
To write an assembly language program to perform division of two 8-
bit numbers using 8051 Microcontroller.
APPARATUS REQUIRED:
2. Keyboard.
PROGRAM:
ADDRESS DATA
ADDRESS DATA
4500
4502
4501
4503
CALCULATION
RESULT:
Thus the assembly language program to perform division of two 8-bit numbers with and without carry using
8051 Microcontroller was executed successfully and output verified.
LOGICAL OPERATIONS(FLOW CHART)
Start
Perform AND
Operation
Perform OR
Operation
Perform XOR
Operation
Perform NOT
Operation
Stop
Expt. No. 4 e)
LOGICAL OPERATIONS
AIM:
To write an assembly language program to perform logical operations of two 8-bit
numbers using 8051 Microcontroller.
APPARATUS REQUIRED:
2. Keyboard.
PROGRAM:
INPUT OUTPUT
ADDRESS DATA
ADDRESS DATA
4500
4502
4501
4503
4504
4505
CALCULATION:
RESULT:
Thus the assembly language program to perform logical operations like (AND,OR,XOR,NOT)operations
using 8051 Microcontroller was executed successfully and output verified.
TWO’S COMPLEMENT OF A NUMBER(FLOWCHART)
Start
Stop
Expt. No. 4 f)
TWO’S COMPLEMENT OF A NUMBER
AIM:
To write an assembly language program to find the 2’s complement
of an 8-bit number using 8051 Microcontroller.
APPARATUS REQUIRED:
2. Keyboard.
PROGRAM:
CALCULATION:
RESULT:
Thus the assembly language program to perform two’s complement of a number using 8051
microcontroller was executed successfully and output verified.
SQUARE OF A NUMBER(FLOW CHART)
Start
Increment DPTR
Increment DPTR
Stop
Expt. No. 4 g)
SQUARE OF A NUMBER
AIM:
To write an assembly language program to find the square of a given
8-bit number using 8051 Microcontroller.
APPARATUS REQUIRED:
2. Keyboard.
PROGRAM:
ADDRESS DATA
ADDRESS DATA 4502
4500 4503
CALCULATION:
RESULT:
Thus the assembly language program to perform square of a number using 8051 microcontroller was
executed successfully and output verified.
Ex.No.5
INTRODUCTION TO ARDUINO PLATFORM AND PROGRAMMING
AIM :
To give an introduction to Arduino platform , learn the ports and program using Arduino IDE .
THEORY:
THEORY:
Arduino is an open-source prototyping platform in electronics based on easy-to-use hardware and
software. Arduino is a microcontroller based prototyping board which can be used in developing
digital devices that can read inputs like finger on a button, touch on a screen, light on a sensor
etc. and turning it in to output like switching on an LED, rotating a motor, playing songs through
a speaker etc.The Arduino board can be programmed to do anything by simply programming
the microcontroller on board using a set of instructions for which, the Arduino board consists of a
USB plug to communicate with your computer and a bunch of connection sockets that can be
wired to external devices like motors, LEDs etc.Arduino is based on open source electronics
project i.e. all the design specifications, schematics, software are available openly to all the users.
Hence, Arduino boards can bought from vendors as they are commercially available or else you
can make your own board by if you wish i.e. you can download the schematic from Arduino’s
official website, buy all the components as per the design specification, assemble all the
components, and make your own board.
Arduino boards are generally based on microcontrollers from Atmel Corporation like 8, 16 or 32
bit AVR architecture based microcontrollers.The important feature of the Arduino boards is the
standard connectors. Using these connectors, we can connect the Arduino board to other devices
like LEDs or add-on modules called Shields.The Arduino boards also consists of on board
voltage regulator and crystal oscillator. They also consist of USB to serial adapter using which
the Arduino board can be programmed using USB connection.In order to program the Arduino
board, we need to use IDE provided by Arduino. The Arduino IDE is based on Processing
programming language and supports C and C++.
There are many types of Arduino boards available in the market but all the boards have one thing
in common: they can be programmed using the Arduino IDE. The reasons for different types of
boards are different power supply requirements, connectivity options, their applications
etc.Arduino boards are available in different sizes, form factors, different no. of I/O pins etc.
Some of the commonly known and frequently used Arduino boards are Arduino UNO, here are
many types of Arduino boards available in the market but all the boards have one thing in
common: they can be programmed using the Arduino IDE. The reasons for different types of
boards are different power supply requirements, connectivity options, their applications
etc.Arduino boards are available in different sizes, form factors, different no. of I/O pins etc.
Some of the commonly known and frequently used Arduino boards are Arduino UNO, Arduino
Mega, Arduino Nano, Arduino Micro and Arduino Lilypad.
Arduino Shields:
Shields are boards that can be plugged on top of the Arduino PCB extending its capabilities. The
different shields follow the same philosophy as the original toolkit: They are easy to mount and
cheap to produce.
🞂 Arduino Wi-Fi Shield - This is the Arduino Ethernet Shield sans wires.This
shield can get your Arduino connected to a WiFi router, so it can host
webpages and scour the Internet.
🞂 Cellular Shield w/ SM5100B - Turn your Arduino into a cellular
phone! Send SMS text messages, or hook up a microphone and
speaker and use it to replace your iPhone.
🞂 GPS Shield - GPS isn’t as complicated as you might think. With a GPS
Shield, your Arduino will always know where it is.
Arduino UNO
Arduino UNO is a basic and inexpensive Arduino board and is the most popular of all the
Arduino boards with a market share of over 50%. Arduino UNO is considered to be the best
prototyping board for beginners in electronics and coding. UNO is based on ATmega328P
microcontroller. There are two variants of the Arduino UNO: one which consists of through –
hole microcontroller connection and other with surface mount type. Through-hole model will be
beneficial as we can take the chip out in case of any problem and swap in with a new one.
Arduino UNO comes with different features and capabilities. The microcontroller used in UNO is
ATmega328P, which is an 8-bit microcontroller based on the AVR architecture.UNO has 14
digital input – output (I/O) pins which can be used as either input or output by connecting them
with different external devices and components. Out of these 14 pins, 6 pins are capable of
producing PWM signal. All the digital pins operate at 5V and can output a current of 20mA.
Some of the digital I/O pins have special functions which are describe below.
Pins 0 and 1 are used for serial communication. They are used to receive and transmit
serial data which can be used in several ways like programming the Arduino board and
communicating with the user through serial monitor.
Pins 2 and 3 are used for external interrupts. An external event can be triggered using
these pins by detecting low value, change in value or falling or rising edge on a signal.
As mentioned earlier, 6 of the 14 digital I/O Pins i.e. 3, 5, 6, 9, 10, and 11 can provide 8-
bit PWM output.
Pins 10, 11, 12 and 13 (SS, MOSI, MISO AND SCK respectively) are used for SPI
communication.
Pin 13 has a built-in LED connected to it. When the pin is HIGH, the LED is turned on
and when the pin is LOW, it is turned off.
Arduino Uno has 6 analog input pins which can provide 10 bits of resolution i.e. 1024 different
values. The analog pins on the Arduino UNO are labelled A0 to A5.By default, all the analog
pins can measure from ground to 5V. Arduino UNO has a feature, where it is possible to change
the upper end of the range by using the AREF pin but the value should be less than 5V. There are
different ways in which we can power the Arduino UNO board. The USB cable, which is used to
program the microcontroller, can be used as a source of power.There is a power jack, using
which an external regulated power supply in the range of 7V – 12V can be supplied.
Additionally, the power can also be supplied from a battery through the VIN pin.The UNO board
has on-board voltage regulators for 5V and 3.3V, which can be used as power supply for small
external devices like LEDs.
o Arduino programming is a simplified version of C++, which makes the learning process
easy.
o The Arduino IDE is used to control the functions of boards. It further sends the set of
specifications to the microcontroller.
o Arduino does not need an extra board or piece to load new code.
o Arduino can read analog and digital input signals.
o The hardware and software platform is easy to use and implement.
Arduino, natively, supports a language that we call the Arduino Programming Language, or Arduino Language.
When we work with Arduino we commonly use the Arduino IDE (Integrated Development Environment), a
software available for all the major desktop platforms (macOS, Linux, Windows), which gives us 2 things: a
programming editor with integrated libraries support, and a way to easily compile and load our Arduino
programs to a board connected to the computer. The Arduino Programming Language is basically a framework
built on top of C++. A program written in the Arduino Programming Language is called sketch. A sketch is
normally saved with the .ino extension (from Arduino).
The main difference from “normal” C or C++ is that you wrap all your code into 2 main functions. You can
have more than 2, of course, but any Arduino program must provide at least those 2.
One is called setup( ), the other is called loop( ). The first is called once, when the program starts, the second is
repeatedly called while your program is running. Once you compile your sketch, the IDE will make sure the end
result is a correct C++ program and will basically add the missing glue by preprocessing it. art of the Arduino
Programming Language is the built-in libraries that allow you to easily integrate with the functionality provided
by the Arduino board.
Your first Arduino program will surely involve making a led turn on the light, and then turn off. To do so, you
will use the pinMode( ), delay( ) and digitalWrite( ) functions, along with some constants
like HIGH, LOW, OUTPUT.
Arduino sets two constants we can use to HIGH equates to a high level of voltage, which can differ depending
on the hardware (>2V on 3.3V boards like Arduino Nano, >3V on 5V boards like Arduino Uno) LOW equates
to a low level of voltage. Again, the exact value depends on the board used
Then we have 3 constants we can use in combination with the pinMode( ) function:
INPUT sets the pin as an input pin
OUTPUT sets the pin as an output pin
INPUT_PULLUP sets the pin as an internal pull-up resistor
The other constant we have is LED_BUILTIN, which points to the number of the on-board pin, which usually
equates to the number 13.
Program lifecycle
setup( ) this function is called once, when the program starts, and when the Arduino is shut down and restarted.
loop( ) this function is repeatedly called while the Arduino program is running.
Handling I/O
The following functions help with handling input and output from your Arduino device.
Digital I/O
digitalRead( ) reads the value from a digital pin. Accepts a pin number as a parameter, and returns
the HIGH or LOW constant.
digitalWrite( ) writes a HIGH or LOW value to a digital output pin. You pass the pin number
and HIGH or LOW as parameters.
pinMode ( ) sets a pin to be an input, or an output. You pass the pin number and
the INPUT or OUTPUT value as parameters.
pulseIn( ) reads a digital pulse from LOW to HIGH and then to LOW again, or from HIGH to LOW and
to HIGH again on a pin. The program will block until the pulse is detected. You specify the pin number and the
kind of pulse you want to detect (LHL or HLH). You can specify an optional timeout to stop waiting for that
pulse.
pulseInLong( ) is same as pulseIn( ), except it is implemented differently and it can’t be used if interrupts are
turned off. Interrupts are commonly turned off to get a more accurate result.
shiftIn( ) reads a byte of data one bit at a time from a pin.
shiftOut( ) writes a byte of data one bit at a time to a pin.
tone( ) sends a square wave on a pin, used for buzzers/speakers to play tones. You can specify the pin, and the
frequency. It works on both digital and analog pins.
noTone( ) stops the tone( ) generated wave on a pin.
Analog I/O
Time functions
delay( ) pauses the program for a number of milliseconds specified as parameter
delayMicroseconds( ) pauses the program for a number of microseconds specified as parameter
micros( ) the number of microseconds since the start of the program. Resets after ~70 minutes due to overflow
millis( ) the number of milliseconds since the start of the program. Resets after ~50 days due to overflow
Math functions
abs( ) the absolute value of a number
constrain( ) constrains a number to be within a range
map( ) re-maps a number from one range to another
max( ) the maximum of two numbers
min( ) the minimum of two numbers
pow( ) the value of a number raised to a power
sq( ) the square of a number
sqrt( ) the square root of a number
cos( ) the cosine of an angle
sin( ) the sine of an angle
tan( ) the tangent of an angle
Interrupts
RESULT:
Thus the introduction of Arduino platform and programming was studied.
EX NO:5b Introduction to Arduino platform and programming
AIM:
To learn the ports and write a program to blink the builtin LED in the Arduino Uno board using
Arduino IDE.
APPARATUS REQUIRED:
1 ARDUINO UNO 1
BOARD
2 USB CABLE 1
PROCEDURE:
1.Connect the USB Cable from computer to Arduino USB port.
2. Go to device manager and view the Arduino Uno port COM.
3.Go to tools and then select Arduino Uno and Arduino COM port .
4. Click the Arduino IDE in the desktop to open.
5. Go to File and then to new Sketch.
6. Type the program and save.
7. Compile the program and check the error.If error occurs correct it.
8. Upload the program
9. See the output ON/OFF (builtin LED) in Arduino UNO board .
PROGRAM:
//Set up function runs once when you press reset or power the board.
Void setup( ) {
PinMode(LED_ BUILTIN,HIGH);
}
//The loop function runs over and over again forever
Void loop( ) {
digitalWrite(LED_BUILTIN,HIGH);
delay(1000);
digitalWrite(LED_BUILTIN,LOW);
delay(1000);
}
ALGORITHM:
1.Intialize digital pin LED_BUILDIN as an output.
2.Turn the LED on(High is the voltage level)
3.Wait for 1000 seconds.
4.Turn the LED off by making the voltage low.
5.Wait for 1000 seconds.
RESULT:
Thus the blink of builtin LED in the Arduino Uno board is performed using Arduino IDE platform.
EX NO:6 EXPLORE DIFFERENT COMMUNICATION METHODS
WITH IOT DEVICES(BLUETOOTH)
AIM:
To interface the bluetooth HC-05 terminal with arduino uno and switch ON/OFF LED
using the wireless communication protocol Bluetooth.
APPARATUS REQUIRED:
PROCEDURE:
.Connect the USB Cable from computer to Arduino USB port.
Go to device manager and view the Arduino Uno port COM.
Connect the VCC of Bluetooth module with +5v in Arduino Uno board using male
and female connector.
Connect the GND pin of Bluetooth module with GND pin of Arduino Uno board
using male and female connector.
Connect the TXD pin of Bluetooth module with RX(0th pin) of Arduino Uno board
using male and female connector.
Connect the RXD pin of Bluetooth module with TX(1st pin ) of Arduino Uno Board
using male and female connector.
.Download the HC-05 bluetooth app from playstore to your mobile phone.
Click the Arduino IDE in the desktop to open it.
Go to File and then to new Sketch.
Type the program and save.
Go to tools and then select Arduino Uno and Arduino COM port
Compile the program and check the error.If error occurs correct it.
Upload the program.
If error occurs in uploading disconnect the TX and RX connection to the Arduino
Uno board and upload the program .After uploading connect the RX and TX pin in
the Arduino Uno board.
Connect directly LED pin positive to 13th pin of Arduino Uno board and negative
of LED pin to ground of Arduino Uno board
(or)
Fix the LED in bread board.Connect the positive of LED with a resistor of 1K ohms
and then connect from resistor to 13th pin of Arduino using male and female
connector.Connect the negative of LED to the GND pin of Arduino Uno board using
male and female connector.
Pair the HC-05 of the arduino board with HC-05 app in your mobile phone.
Go to terminal and give the command 1 the LED will be giow(ON).When we give
the command as 0 the LED will be OFF.
PROGRAM:
char Incoming_value= 0;
Void setup( ) {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
Void loop ( ) {
if ( Serial.available( ) > 0) {
Incoming_value=Serial.read( );
Serial.print(Incoming_value);
Serial.print(“/n”);
if(Incoming_value= =’1’)
digitalWrite(13,HIGH);
else if(Incoming_value= =’0’)
digitalWrite(13,LOW);
}
}
ALGORITHM:
1. 1.Declare a character as incoming value=0
2. 2.Open serial port and set the baud rate as 9600 bps.
3. 3.Set 13th pin as output.
4. Listen for the data.
5. Read the numbers from serial port.
6. Print out the received number.
7. Print a new line character.
8. If the incoming value is greater than zero the LED will be turned ON.
9. If the incoming Value is equal to zero the LED will be turned OFF
RESULT:
Thus the Bluetooth module is interfaced with Arduino Uno board and the LED is turned ON/OFF
using Bluetooth wireless communication protocol.
EX NO:7 Introduction of RashBerry PI platform and python Programming
AIM:
To give an introduction to Rashberry Pi connections and write a program using python in
rashberry pi.
APPARATUS REQUIRED:
PROCEDURE:
Connection procedure:
1. Connect the VGA cable of CPU to rashberrypi VGA connector.
2. Connect the rashberrypi VGA connector to HDMI cable and then connect a
connector and then connect a micro HDMI cable and connect to rashberry pi.
3. Connect the USB plug mouse and keyboard to rashberry pi.
4. Connect the charge cable(C type) to rashberry pi.
5. Take a bread board and fix a LED.Use the jumper pin and connect the positive of
LED to GPIO 14(8th pin) of rashberrypi and negative of LED to GND connection (6th
pin) of rashberry pi.
Procedure to run the program:
1. Click the rashberry pi symbol →programming→Thonny
2. Select new and type the program.
3. Go to File→save as→name.py(extension)
4. Click ok.
5. Run the program.
6. In the breadboard we can see LED ON for certain seconds and OFF for certain
seconds and so on.
Pin diagram of Rashberry pi:
PROGRAM:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(14,GPIO.OUT)
while True:
GPIO.output(14,True)
time.sleep(1)
GPIO.output(14,False)
time.sleep(1)
ALGORTHM:
1. Import rashberrypi general purpose Input/Output.
2. Import time for including delay.
3. Set BCM mode for setting the pin in rashberry pi.
4. Set the GPIO 14 as output.
5. Create while loop.
6. If GPIO 14 is true means LED will glow.
7. Give a time delay of one second.
8. If GPIO 14 is False means LED will not glow.
9. Give a time delay of one second.
RESULT:
Thus the Rashberry pi connection was given and a program was written in python
to turn LED ON/OFF and the output was executed successfully.
EX NO:8 INTERFACING SENSORS WITH RASPBERRY PI
AIM :
To interface IR sensor with Raspberry pi and write a program to switch on the LED
when IR Sensor detects an object.
APPARATUS REQUIRED:
PROCEDURE:
Connection to rashberrypi:
1. Connect the VGA cable of CPU to rashperrypi VGA connector.
2. Connect the rashperrypi VGA connector to HDMI cable and then connect a
connector and then connect a micro HDMI cable and connect to rashperry pi.
3. Connect the USB plug mouse and keyboard to rashperrypi.
4. Connect the charge cable(C type) to rashperry pi.
5. Take a bread board and fix a LED.Use the jumper pin and connect the positive of
LED to GPIO 14(8th pin) of rashperrypi and negative of LED to GND connection (6 th
pin) of rashperry pi.
Connection to IR Sensor:
1. Connect Vcc of IR Sensor to the 2nd pin of rashberrypi(Vcc)
2. Connect the GND of IR sensor to 6th pin of rashberrypi.
3. Connect the output of IR Sensor with 16th pin of rashberrypi.
4. Fix the LED in the bread board.Positive of Led is connected with resistor.The resistor is
connected with to 18th pin in Rashberrypi.The negative of LED is connected to 9 th pin
of rashberrypi.
Programming Procedure:
1. Click the rashperry pi symbol →programming→Thonny
2. Select new and type the program.
3. Go to File→save as→name.py(extension)
4. Click ok.
5. Run the program.
6. If you show your hand or any object near IR Sensor then in the breadboard we can
see LED ON and if no object is detected means LED will be OFF .
PROGRAM:
import RPi.GPIO as GPIO
import time
sensor=16
led=18
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.IN)
GPIO.setup(led,GPIO.OUT)
GPIO.output(led,False)
print ("IR sensor ready")
print (" ")
try:
while True:
if GPIO.input(sensor):
GPIO.output(led,False)
print ("object is detected")
while GPIO.input(sensor):
time.sleep(0.2)
else:
GPIO.output(led,True)
except keyboardInterrupt:
GPIO.cleanup( )
ALGORITHM:
1. Import rashberry pi general purpose input/output.
2. Import time for time sleep.
3. Set sensor output as 16 and LED output as 18.
4. Set BOARD for setting the pin in rashberry pi.
5. Set GPIO such as IR Sensor output act as inputbto rashberry pi.
6. Set LED as output.
7. Assume if GPIO output is False object is detected.
8. Create while loop.
9. If object is detected LED will be ON.
10. If object is not detected LED will be OFF.
RESULT:
Thus the IR Sensor is interfaced with Rashberry pi and the LED was switched on when object
was detected.
EX NO:9 COMMUNICATE BETWEEN ARDUINO AND RASPBERRY
PI USING ANY WIRELLESS MEDIUM(BLUETOOTH)
AIM:
To Communicate between Arduino and raspberry pi using Bluetooth(HC-05) wireless
medium and write a program to switch ON/OFF LED.
APPARATUS REQUIRED:
4 Keyboard -
5 Bread board - 1
6 Arduino Uno
board
7 Mouse 1
8 LED 1
9 Bluetooth HC-05 1
module
PROCEDURE:
Connection between Bluetooth module(HC-05) with Arduino Uno:
1. Connect the USB Cable from Arduino USB port to Rashberry pi .
2. Connect the VCC of Bluetooth module with +5v in Arduino Uno board
using male and female connector.
3. Connect the GND pin of Bluetooth module with GND pin of Arduino
Uno board using male and female connector.
4. Connect the TXD pin of Bluetooth module with RX(0 th pin) of Arduino
Uno board using male and female connector.
5. Connect the RXD pin of Bluetooth module with TX(1 st pin ) of Arduino
Uno Board using male and female connector.
6. Connect directly LED pin positive to 13th pin of Arduino Uno board and
negative of LED pin to ground of Arduino Uno board
7. Download the HC-05 bluetooth app from playstore to your mobile phone.
Connection to rashberry pi:
8. Connect the VGA cable of CPU to rashberrypi VGA connector.
9. Connect the rashberrypi VGA connector to HDMI cable and then
connect a connector and then connect a micro HDMI cable and connect
to rashberry pi.
10. Connect the USB plug mouse and keyboard to rashberry pi.
11. Connect the charge cable(C type) to rashberry pi.
PROGRAMMING PROCEDURE:
1. Open the terminal >- in the rashberry pi which is on the top of the screen.
2. Copy and paste the link which is given below
wget -qO- https://raw.githubusercontent.com/Botspot/pi-apps/master/install | bash
3.press enter.
(It will automatically install Piapps)
4.Go to menu→accessaries→piapps
5.Go to All apps→arduino→install
6.start or File→programming→arduino ide
7.Type the program.
8.Go to file and save as HC-05 (or) any name.
9.Go to tools → select arduino uno board.
10.Go to tools→port→select /devtyACMO(Arduino board)
9.Then disconnect the transmitter and receiver pin from Arduino and compile and
upload the program.
10 After uploading the program connect the transmitter and receiver pin to Arduino
Uno.
11.Open the terminal >-
Type as :sudo bluetoothctl
12.press enter
Agent registered(It will be shown in the monitor)
13.Type as: agent on
14.press enter
15.Type as : scan on
16.Press enter
(It will scan all the devices near by)
17.It will show the addresses of all Bluetooth devices nearby.copy the address of HC-05 and
paste it in a text file and save it.
(Press ctrl z and type as :clear)
18.In the terminal type as :sudo rfcomm - -help
19.press enter
20.Type as: sudo rfcomm bind 7 Copy the address of Hc-05 and paste it here
21.press enter
22.Switch to regular mode.
23.Click rashberry symbol→Programming→thonny
24.Type the program.
25.save as name.py(extension)
26.In your mobile open the app Bluetooth module(HC-05) and scan
27. Then go to bluetooth which is on the top of the screen.
28.Click add device
29.click HC-05
30.Click pair.
(It will ask for code)
31.Enter as 1234 and then click ok.
32.It will show paired successfully.click ok.
33.Click the ardino on the top of the screen.
34.Go to serial monitor and open it.
35.Run the program.
36.It will show enter:- (Type as)100.The LED will glow.
37.press enter
38. It will show enter:- (Type as)200.The Led will be OFF.
39.In the serial monitor you can see 100 and 200
(or)
The command can be given using mobile phone also.In Bluetooth module go to terminal and
give command as 100 Led will be ON. When we give the command as 200 the Led will be
OFF.
40.To release the connection go to terminal and type: sudo rfcomm release 7 Copy the
address of Hc-05 and paste it here
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
int a=Serial.parseInt();
Serial.println(a);
if(a==100)
{digitalWrite(led,HIGH);
}
if(a==200)
{
digitalWrite(led,LOW);
}
}
}
PROGRAM FOR RASHBERRY PI:
import serial
import time
bluetooth=serial.Serial("/dev/rfcomm7",9600)
while True:
a=input("enter:-")
string='X{0}'.format(a)
bluetooth.write(string.encode("utf-8"))
APPARATUS REQUIRED:
S.NO APPARATUS/COMPONENTS QUANTITY
1 Bread board 1
2 LED 1
3 Resistor 1
4 NodeMcu(ESP8266) 1
5 Charge cable(B type) 1
6 Computer with internet 1
7 Arduino Uno board 1
8 Jumper pins As required
PROCEDURE:
In www.google.com search Blynk IoT
Click
Blynk: a low-code IoT software platform for businesses and
No account for blynk means create account. If you have already login account means
log in using user name and password.
Click start free.
Click personal project
Create new template.
Name:control Led, Hardware:ESP 8266,Connection type:Wi-Fi
Click done.
Click data streams,click new data stream,options→virtual pin
Name:Led 1,pin:V0,Data type:Integer,Colour:any colour you want
Click create
Click web dashboard
Click widget box
Drag one time switch
Click switch
Go to settings
Datastream choose led1(V0)
ON value OFF value
0 1
Show on/off label→enable it
Label position
Right
Save
Click save (in the top)
Devices→new devices
From template
Template:control led
Device name:control led
Click create
When creating a new device you will receive a template which contains the
authentication token .Copy and paste in word and save it.
Go Arduino ide and click open
Type the program.After typing Paste the authentication token.Type your
user name and password of your Wi-Fi device.
Connect the NodeMCu (ESP8266) to the Arduino using Charge cable(B
type).
Go tools select the board as Ardino Uno.
Download the NodeMcu(ESP8266Wi-Fi-master) driver and blynk library
from google and then go to C drive→program
file(x86)→Arduino→libraries→paste ESP8266Wi-Fi-Master and blynk
library.
Go sketch include→Manage library
In Search type as Blynk simple ESP8266.h.Two files will be shown.Install
any one(Net connection needed).
Take a bread board and fix the Led.Connect the positive of Led to D0 of
NodeMcu.Connect the negative of Led to GND of NodeMcu.
Open the blynk app in mobile phone and connect the Wi-Fi which you have
written as username and password.
Before uploading the program go to Tools→Board→NodeMcu1.0(ESP 12E
module).Then upload the program
Go to setting in mobile phone and select the switch button ON and OFF.
Then using mobile switch ON and OFF the Led will glow on ON and Led
will be turned off when the switch is OFF.
Note:If already switches are selected in blynk in your account means directly you can go to
Arduino ide and proceed the remaining steps.
PROGRAM:
//Include the library files
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
void setup() {
Serial.begin(9600);
delay(100);
//Set the Led pin as output pin
pinMode(light1, OUTPUT);
void loop() {
//Run the Blynk library
Blynk.run();
}
ALGORITHM:
1. Include the library files.
2. Define the Led pin.
3. Define the blynk authentication token.
4. Enter your Wi-Fi name.
5. Enter your Wi-Fi password.
6. Get the button Values.
7. Check the button values and turn the Led On/OFF.
8. If value 1 is equal to one then Led will be OFF.
9. If Value 1 is Zero then Led will glow.
10. Set the baud rate.
11. Give the delay as 100 seconds.
12. Set the Led pin as output pin.
13. Turn off the Led.
14. Initialize the blynk library.
15. Run the blynk library.
RESULT:
Thus using the cloud app blynk the Led light 1 was switched ON/OFF using internet(Wi-Fi)
successfully.
EX NO:11 SET A CLOUD PLATFORM TO LOG ON DATA USING ARDUINO
AIM:
To set a Arduino cloud platform to log on data.
APPARATUS REQUIRED:
S.NO APPARATUS/COMPONENTS QUANTITY
Program:
#include "arduino_secrets.h"
CloudRelativeHumidity humidity;
String msg;
CloudTemperatureSensor temperature;
#include "thingProperties.h"
#include "DHT.h"
#define DHTpin 2 // D4 on the nodemcu ESP8266
#define DHTTYPE DHT11
DHT dht(DHTpin,DHTTYPE);
void setup( ) {
Serial.begin(9600);
delay(1500);
initProperties( );
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo( );
}
void loop() {
ArduinoCloud.update( );
float hm= dht.readHumidity( );
Serial.print("Humidity ");
Serial.println(hm);
float temp=dht.readTemperature();
Serial.print("Temperature ");
Serial.println(temp);
humidity=hm;
temperature=temp;
message="Temperature = " + String (temperature)+" Humidity = " + String(humidity);
}
void onHumidityChange( ) {
}
void onMsgChange( ) {
}
void dht_sensor_getdata( )
{
float hm= dht.readHumidity( );
Serial.print("Humidity ");
Serial.println(hm);
float temp=dht.readTemperature( );
Serial.print("Temperature ");
Serial.println(temp);
humidity=hm;
temperature=temp;
message="Temperature = " + String (temperature)+" Humidity = " + String(humidity);
}
ALGORITHM:
1.Include Sketch generated by the Arduino IoT Cloud Thing "Temperature and Humidity
monitoring”.
2 The following variables are automatically generated and updated when changes are made to
the Thing
CloudRelativeHumidity humidity;
String msg;
CloudTemperatureSensor temperature;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard. These functions are
generated with the Thing and added at the end of this sketch.
3.Include sensor.
4.Define DHT outputpin and NodeMCu output pin.
5.Define DHT type.
6. Initialize serial and wait for port to open(This delay gives the chance to wait for a Serial
Monitor without blocking if none is found)
7. Defined in thingProperties.h
8. Connect to Arduino IoT Cloud.
9.The function allows to obtain more information related to the state of network and IoT
Cloud connection.
10.Type the code.
11. Add the code here to act upon Humidity change.
12.Since Humidity is READ_WRITE variable, onHumidityChange( ) is
executed every time a new value is received from IoT Cloud.
13. Add the code here to act upon Message change.
RESULT:
Thus the datas are logged using Arduino IoT cloud successfully.