You are on page 1of 36

SRI KRISHNA COLLEGE OF TECHNOLOGY

(AN AUTONOMOUS INSTITUTION)


KOVAIPUDUR, COIMBATORE - 641042.
Affiliated to Anna University and Approved by AICTE
Accredited by NBA - AICTE and NAAC - UGC

16CS211 / MICROPROCESSOR & MICROCONTROLLER


LAB MANUAL

Prepared By Approved By
Mr.Ajith.B.Singh
Ms.M.Jayalaxmi HOD
Mr.K.Saravanakumar

REVISION 2018
Table of Contents

Ex. No Name of the Experiment Page No


1. Assembly Language programs using 8086 1

2. Stepper motor control using 8086 Microprocessor 4

3. Assembly Language programs using 8051 7

4. Interfacing 8051 with ADC 12

5. Sensor Interfacing using 8051 Micro controller 14

6. Basic programming using ARM Processor. 17

7. Interfacing with seven segment display using ARM. 20

8. Basic Programming with Arduino Kit 24

9. Design of a Traffic light controller with Arduino. 28

10. Design a Simple chat Server using Arduino. 32


Ex No.1 Assembly Language Programming in 8086

Date:

Objective : To write an ALP to sort N 8 bit elements stored in memory Location starting from
1300H using 8086 Microprocessor

APPARATUS :

 8086 Microprocessor kit with Keyboard and LCD display

Pre Lab work:

Algorithm:

Step 1 : Load the array count in register CH


Step 2: Load the iteration count in register CL
Step 3: get the first two number ,one in accumulator and using indirect addressing
Step 4: Compare the numbers and swap if the accumulator number is small
Step 5: Get the next number from array and repeat the process until CL is zero
Step 6: Repeat the iteration until the count CH is zero

Flow chart: Start

Initialize the number of elements and number of


comparison iterations in counter register

Get the first number in accumulator

Is
Accumator content
> pointer of next
number?

Interchange contents
Decrement comparison counter

Is counter =0? No

Yes

Decrement element counter

No
Is counter =0?

Yes
End 1
Program:
MOV CL,0AH
Loop3 : MOV CH, 0AH
MOV BX,2000H
Loop 2: MOV AL,[BX]
INC BX
CMP AL,[BX]
JB Loop1
JE Loop1
MOV AH,[BX]
MOV [BX],AL
DEC BX
MOV [BX],AH
INC BX
Loop1:DEC CH
JNZ Loop2
DEC CL
JNZ Loop3
HLT
Input :

Memory Input
Location
4200 20
4201 55
4202 62
4203 23
4204 11
4205 85
4206 28
4207 69
4208 43
4209 69
Output:
Memory Input
Location
4200 11
4201 20
4202 23
4203 28
4204 43
4205 55
4206 62
4207 69
4208 69
4209 85
2
Result:

Thus, an ALP to sort N 8 bit elements stored in memory Location starting from 1300H using 8086
Microprocessor was executed successfully

List of questions to be solved:

1. Write an ALP to store the first number in 1200h memory location and the second
number in 1300h memory location. Store the sum of the two numbers in 1400h and also
calculate the difference, product, quotient and remainder in consecutive memory
locations from 1401h.
2. Write an ALP to store 16 bit Hexadecimal numbers starting from memory location 1200h
and to find the least number from the stored list and store in 1500h and 1501h
3. Write an ALP to store a 4 digit decimal number in memory location 110h and perform
the hexadecimal sum of individual digits and store the result in 1200h and 1201h
memory location.
4. Write an ALP to store N 8bit Hexadecimal number in consecutive memory locations
starting from 2000h. Find sum of all N element and store in 2100h and also find the
average and store in successive memory location.
5. Write an ALP to store a 8 bit hexadecimal number in memory location and convert into
decimal and find the sum of all natural numbers from 1 till the converted decimal
number.

Viva question:

1. How many bit 8086 microprocessor has?


2. What is the size of data bus of 8086?
3. What is the size of address bus of 8086?
4. What is the max memory addressing capacity of 8086?
5. Which are the basic parts of 8086?
6. What is the purpose of EU?
7. What is the significance of ALE
8. How is 20 bit address stored in 16 bit registers of 8086?

3
Ex No.2

Stepper motor control using 8086 Microprocessor

Date:

Objective : To write an Assembly Language Program to rotate the Stepper Motor in different
Speed

APPARATUS :
 8086 Microprocessor kit with Keyboard and LCD display

 Motor Interface Card,


 Stepper Motor,

Pre Lab work:

Procedure:
1. Connect the 26 core FRC connector to the 8086 trainer at connector no CN4 and the
interface module.
2. Connect the power mate connector to the interface module and the other side of the

connector to the power supply. The connections to the power supply are given below.
connections: (power supply)
Black & Red: Gnd.
Blue & Green: +5V

3. 5- Way power mate is wired to the motor. This power mate is to be inserted into the
male socket provided on the interface. Care should be taken such that, below given code
for the particular colored wire coincides with the code on the interface.
A- GREEN

C- RED & WHITE B-


GREEN & WHITE D-
RED
VDD- BLACK & WHITE.
4. After the completion of the program and connections enter the program as given in the
listing below.
G0< STARTING ADDRESS< ENTER (on the key board of trainer).

4
Algorithm:

Step 1 : Load the steps of stepper motor as input table using pointer DI
Step 2: Load the step count in register CL
Step 3: Move the content pointed by DI to accumulator and output the content to port connecting the
stepper motor interface
Step 4: Load DX register with the delay count and decrement to provide a delay in the output of
stepper motor
Step 5:Increment DI to point the next step value
Step 6: Decrement the step count and if not zero repeat from step 3
Step 7: Go to start.

Program:
START: MOV DI,2000H

L1: MOV CL.04H

L2: MOV AL,[DI]

OUT PORT1,AL

MOV DX,1010H

DELAY: DEC DX

JNZ DELAY

INC DI

DEC CL

JNZ L2

LOOP L1

JMP START

Result:

Thus, the speed of Stepper Motor is controlled by varying the delay and verified using 8086
Microprocessor

5
List of questions to be solved:

1. Write an ALP to run the stepper motor interfaced with 8086 at the desired speed in
Forward and Reverse direction.
2. Write an ALP to control conveyer belt using stepper motor using 8086 microprocessor.
Belt moves continuously at the rate of 1 step/sec, but steps for 5sec. When external
interrupt occurs then continue to move.
3. Write an ALP to control a stepper motor using 8086 at half step excitation sequence in
forward direction alone.

Viva question:

1. How is the step value of stepper motor assigned?


2. How can u vary the direction of the stepper motor?
3. What does the stepper motor interface board consists of?
4. How is the speed of the stepper motor varied?
5. What is DI in the program?
6. What is the need of delay routine in the program?

6
Ex No. 3 Assembly language Programming in 8051

Date:

Objective : To write an assembly language program to add, subtract, multiply and divide
two 8-bit & 16-bit numbers using 8051 microcontroller.

SYSTEM AND SOFTWARE TOOL REQUIRED:

 8051 microcontroller kit


 Keyboard

PRE LAB WORK


ALGORITHM FOR ADDITION
1. Start the program.
2. Move the first number to A register.
3. Add the second number with the contents of the accumulator.
4. Initialize data pointer address.
5. Move the result from the accumulator to the data pointer.
6. Stop the program.
ALGORITHM FOR 8 BIT SUBTRACTION
1. Start the program.
2. Move the first number to A register.
3. Subtract the second number with the contents of the accumulator.
4. Initialize data pointer address.
5. Move the result from the accumulator to the data pointer.
6. Stop the program.
Flow chart:
a) ADDITION Start

Move the first number to A register

Add the second number with the contents of the accumulator

Initialize data pointer.

A
7
A

Move the result from the accumulator to the data pointer.

Stop

b) Subtraction

8
Program for Addition:
START CLR C
MOV A,#04
ADDC A,#05
MOV DPTR,#4500
MOVX @DPTR,A
STOP SJMP 4109
Program for Subtraction:
START CLR C
MOV A,#08
MOV R1,#04
SUBB A,R1
MOV DPTR,#4500
MOVX @DPTR,A
STOP SJMP 410A

Addition
Memory Input Subtraction
Location
Memory Input
4500 Location
4501 4550

Memory Output
Location
4501

Result:

Thus, an ALP to add & subtract two numbers using 8051 Microcontroller was executed successfully.

10
List of questions to be solved:

1. Write an ALP to generate a BCD up counter and send ach count value to memory
location 4500H to verify.
2. Write an ALP to store N hexadecimal numbers in consecutive memory location
starting from 4500H and to store an element x in memory location 4300H. Check
whether element x is available in the list of elements stored from 4500H. If yes, store
FFH in 4600H else 00H in 4600H.
3. Write an ALP to store a decimal number in memory location 4200H and to calculate the
factorial of the number in decimal and store in 4300H.
4. Write an ALP to transfer N 8 bit elements from one block of memory to another, i.e;
Move the elements stored in memory location starting from 4200H to 4300H
consecutively.
5. Write an 8051 ALP to copy a value from memory location 4500H into accumulator and
complement 70 times and find the equivalent decimal value.

Viva questions:
1. Why 8051 is called 8 bit microcontroller?
2. What is the width of data bus?
3. What is the width of address bus?
4. List out the features of 8051 micro controller?
5. How much on chip RAM is available?
6. What are the register set available in 8051?
7. Differentiate Microprocessor & Microcontrollers
8. What is the purpose of DPTR?

11
Ex No.4
Interfacing 8051 with ADC.
Date:

Objective :

To program starts from memory location 4100H. The program is executed for various
values of analog voltage which are set with the help of a potentiometer. The LED display is
verified with the digital value that is stored in the memory location 4150H.

APPARATUS
 Microcontroller kit
 ADC Interface board

THEORY

An ADC usually has two additional control lines: the SOC input to tell the ADC when to
start the conversion and the EOC output to announce when the conversion is complete. The
following program initiates the conversion process, checks the EOC pin of ADC 0419 as to
whether the conversion is over and then inputs the data to the processor. It also instructs the
processor to store the converted digital data at RAM 4200H.

ALGORITHM:
1. Select the channel and latch the address.
2. Send the start conversion pulse.
3. Read EOC signal.
4. If EOC =1 continue else go to step (3)
5. Read the digital output.
6. Store it in a memory location.

PROGRAM:

Program

MOV DPTR, #FFC8


MOV A,#10 Select Channel 0 and make ALE Low
MOVX @DPTR, A
MOV A,#18 make ALE High
MOVX @DPTR, A
MOV DPTR, #FFD0
MOV A,#01 SOC signal High
MOVX @DPTR, A
12
MOV A,#00 SOC signal low
MOVX @DPTR, A
MOV DPTR, #FFD8
WAIT MOVX A,@DPTR
JNB E0,WAIT Check for EOC
MOV DPTR,#FFC0 Read ADC data
MOVX A,@DPTR
MOV DPTR,#4150 Store the data in memory location
MOVX @DPTR, A
HERE SJMP HERE

INPUT OUTPUT

Analog Voltage 0 V 4150 00


Analog Voltage 5V 4150 FF

RESULT:

Thus, the analog voltage is varied using potentiometer and measured to store the
corresponding digital value.

List of questions to be solved:

DAC
1. Write an ALP to generate a saw tooth waveform by using DAC 0800 interfacing with 8051.
2. Write an ALP to generate a triangular waveform by using DAC 0800 interfacing with 8051.
ADC
1. Write an ALP to fetch the position from the potentiometer and store in memory location 4150H
using microcontroller 8051.
2. Write an ALP to measure analog voltage present across any terminal and displays the data using
ADC0809 converter IC interfacing with 8051.

Viva Questions:

1. What is transducer?
2. What is the form of the transducer output?
3. What is Preprocessing of transducer signals to be fed into an ADC called?
3. Explain signal conditioning and its role in data acquisition.
4. What is the purpose of ADC ?
5. How is ADC connected to 8051 ?
13
Ex No.5 Sensor Interfacing using 8051 Micro controller

Date:

Objective : To measure the temperature and store the digital value in memory using 8051
microcontroller.

APPARATUS :

 8051 kit
 ADC board
 LM35 (temperature sensor)

Pre Lab work:

Theory:

The LM35 series sensors are precision integrated-circuit temperature sensors, whose output
voltage is linearly proportional to the Centigrade temperature. It gives 10mV of output voltage
for every 10C. The LM35 does not require any external calibration or trimming to provide
typical accuracies of ±¼°C at room temperature and ±¾°C over a full -55 to +150°C temperature
range. The LM35's low output impedance, linear output, and precise inherent make
interfacing to readout or control circuitry especially easy. It can be used with single power
supplies, or with dual supplies. As it draws only 60 µA from its supply, it has very low self-
heating, less than 0.1°C in still air. The LM35 is rated to operate over a -55° to +150°C
temperature range. The LM35 IC sensor is available at a Low cost .LM35 is a three terminal IC
with ,Vcc ,Ground & Vout .

The LM 35 IC gives a 10mV analog output voltage for every degree Celsius change in
temperature. The Output of the temperature sensor is analog in nature so we need an analog
to digital converter for converting the analog input to its equivalent binary output.

14
Since the output of LM35 is analog voltage, it should be converted into digital before it is
applied to a microcontroller port pin.

Circuit:

Program:
MOV DPTR, #FFC8
MOV A,#10
MOVX @DPTR, A
MOV A,#18
MOVX @DPTR, A
MOV DPTR, #FFD0
MOV A,#01
MOVX @DPTR, A
MOV A,#00
MOVX @DPTR, A
MOV DPTR, #FFD8
WAIT MOVX A,@DPTR
JNB E0,WAIT
MOV DPTR,#FFC0
MOVX A,@DPTR
MOV DPTR,#4150
MOVX @DPTR, A
HERE SJMP HERE

15
INPUT : OUTPUT:
Temperature Value : 98 4150 : 62

Result:

Thus, the temperature is measured and stored in memory using 8051.

List of questions to be solved:

Write an ALP to fetch the temperature continuously and store in consecutive memory
location starting from 4150H using microcontroller 8051.

Viva Questions:

1. Why interfacing is needed for I/0 devices?


2. Define sensor.
3. What is a port?
4. List the types of sensor.

16
Ex No.6 : Basic programming using ARM Processor.

Date:

Objective : To write a basic C program for LED interfacing with ARM LPC 2148 processor.

APPARATUS :

 Keil uVision software.

Pre Lab work:

Procedure:

Step 1 : Click Project  New Project  Create new file


Step 2: Go to Target+ Source group  Startup.A51
Step 3: Type the program and save as .C
Step 4: Right Click source group1 and Add file
Step 5: Right click on the file and select build target
Step 6: Select Debug tab Start running  click Ok
Step 7: Click Peripheral  select the I/O ports
Step 8: Click RunStop
Step 9: To convert object file to hex file, Select Menutarget+create hexok.

Flow chart: Start

Initialize the value for pins of the port

Set the value for IO port

If it is 1
NO

YES

Set the pins of LED port as ON state. Call the delay


module

Then set the pins as OFF. Call the delay module.

No
End
Y

17
Program:
#include <lpc 214x.h>
void delay();
void main()
{
PINSETL0 = 0x00000000;
IO0DIR = 0xFFFFFFFF;
while(1)
{
IOSET0 = 0xFFFFFFFF;
delay();
IOCLR0 = 0xFFFFFFFF;
delay();
}
}
void delay()
{
int i;
for(i=0;i<200;i++)
{
}
}

Output:

ON & OFF state of LED.

Result:

Thus, a C program for interfacing LED with Arm processor was executed successfully.

18
List of questions to be solved:

1. Write a program to glow 4 LEDs alternatively Interfacing With ARM7 (LPC2148).


2. Write a program to provide a scrolling display in 4 LEDs

Viva questions:

1. What is meant by ARM7?


2. What is an ARM chip?
3. Is ARM7 a processor or microcontroller?
4. Give the purpose of RTC oscillator circuit.
5. What is the purpose of delay subroutine?

19
Ex No.7 Interfacing with seven segment display using ARM

Date:

Objective : To write a basic C program of 0 To 9 Counter On Cathode 7 segment display


interfacing with ARM7 (LPC2148).

APPARATUS :

 Keil uVision software.

Pre Lab work:

Description:

A seven-segment display is a form of electronic display device for


displaying decimal numbers (and some alphabets too). SSD may use a liquid crystal
display (LCD), a light-emitting diode (LED) for each segment, or other light-generating or
controlling techniques such as cold cathode gas discharge, vacuum fluorescent, incandescent
filaments, and other.

Operation – In a simple LED package common cathode SSD, there has 10 pin out of which 2 is
ground and rest is LED segments . Particular LED segment is glow(ON) by giving logic 1 to it
and rests at logic 0 .
So we need to program this 8 pin to display our number on SSD. In following table,
we convert this 8 pin s 8 bit binary data into hex code and shows the hex code of displaying
digits below.
Digit Hex code A B C D E F G

0 0x3F 1 1 1 1 1 1 0

1 0x06 0 1 1 0 0 0 0

2 0x5B 1 1 0 1 1 0 1

3 0x4F 1 1 1 1 0 0 1

4 0x66 0 1 1 0 0 1 1

5 0x6D 1 0 1 1 0 1 1

20
6 0x7D 1 0 1 1 1 1 1

7 0x07 1 1 1 0 0 0 0

8 0x7F 1 1 1 1 1 1 1

9 0x6F 1 1 1 1 0 1 1

Procedure:

Step 1 : Click Project  New Project  Create new file


Step 2: Go to Target+ Source group  Startup.A51
Step 3: Type the program and save as .C
Step 4: Right Click source group1 and Add file
Step 5: Right click on the file and select build target
Step 6: Select Debug tab Start running  click Ok
Step 7: Click Peripheral  select the I/O ports
Step 8: Click RunStop
Step 9: To convert object file to hex file, Select Menutarget+create hexok.

Flow chart: Start

select port0 as gpio mode

Make starting 8 pin as output and other as input of

If it is 1
NO

YES

Set the pins of LED port as array data. Call the delay
module

Then set the pins as OFF. Call the delay module.


No

End Y

21
Program:
#include<LPC214X.h> // header file for lpc2148

void delay(); // delay function

unsigned int i,j,k; // globle variable


unsigned int ar[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 }; // array data

int main()
{
PINSEL0=0X00000000; // select port0 as gpio mode
IO0DIR =0X000000FF; // make starting 8 pin as output and other as input of port0
while(1)
{
for(i=0;i<10;i++)
{
IO0SET =ar[i];
delay();
IO0CLR =ar[i];
}
}
return 0;
}

void delay()
{
for(j=0;j<1000;j++)
for(k=0;k<400;k++);
}

Output:

LED ON state from 0 to 9.

Result:

Thus, a C program for interfacing seven segment display with Arm processor was executed
successfully.

22
List of questions to be solved:

1. Write a C program to display the word GOOD in SSD using ARM7 processor and execute it.

2. Write a C program to display the current time in SSD using ARM7 processor.

3. Write a C program to scroll “hello “ in SSD using ARM7 processor

Viva:

1. What is a port?
2. Name the exceptions supported by ARM7.
3. What are the comparison instructions in ARM7.
4. Define CPSR.
5. How to display F in a SSD?

23
Ex No.8 Basic Programming with Arduino Kit

Date:

Objective : To write a basic C program for LED blinking using arduino.

APPARATUS :

 Arduino or Genuino Board


 LED
 220 ohm resistor

Pre Lab work:

Theory:

In this we use the built-in LED that most Arduino and Genuino boards have. This LED is
connected to a digital pin and its number may vary from board type to board type. To make your life
easier, we have a constant that is specified in every board descriptor file. This constant
is LED_BUILTIN and allows you to control the built-in LED easily. Here is the correspondence between
the constant and the digital pin.

 D13 - 101
 D13 - Due
 D1 - Gemma
 D13 - Intel Edison
 D13 - Intel Galileo Gen2
 D13 - Leonardo and Micro
 D13 - LilyPad
 D13 - LilyPad USB
 D13 - MEGA2560
 D13 - Mini
 D6 - MKR1000
 D13 - Nano
 D13 - Pro
 D13 - Pro Mini
 D13 - UNO
 D13 - Yún
 D13 - Zero

If need to lit an external LED with this sketch, then build this circuit, where connect one end of the
resistor to the digital pin correspondent to the LED_BUILTIN constant. Connect the long leg of the LED
(the positive leg, called the anode) to the other end of the resistor. Connect the short leg of the LED (the
negative leg, called the cathode) to the GND. In the diagram below we show an UNO board that has D13
as the LED_BUILTIN value.

24
The value of the resistor in series with the LED may be of a different value than 220 ohm; the LED will
lit up also with values up to 1K ohm.

Schematic

25
Program:
void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop()
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Output

LED ON & OFF state

Result:

Thus, a C program for LED blinking using Arduino was executed successfully.

26
List of questions to be solved:

1. Write a C program to connect 4 LEDs and display 4 bit count value from 0000 to 1111 using
Arduino kit.
2. Write a C program to show the scrolling display by connecting 4 LEDs.

Viva:

1. What are the variance of arduino board?


2. What processor is used in arduino kit?
3. How many analog ports in arduino?
4. Write a code to display in serial monitor?
5. What is the purpose of loop() ?

27
Ex No.9 Design of a Traffic light controller with Arduino

Date:

Objective : To write a basic C program to design a traffic light controller system using arduino.

Apparatus :

 Arduino UNO
 KΩ Resistor X
 Red LEDs X 4
 Yellow LEDs X 4
 Green LEDs X 4
 Connecting wires
 Prototyping board
 Power adapter

Pre Lab work:

Circuit Design:

Since the project is a traffic light controller, the circuit consists of many LEDs (12 as a
matter of fact) as we are implementing traffic lights at a 4 way intersection. The project is a
simple representation of traffic light controller and hence no other extra components are
used.

We need three LEDs of Red, Yellow and Green colors at each intersection. The
intersection is divided in to four lanes: Lane1, Lane 2 Lane 3 and Lane 4. All the LEDs are
connected to the Arduino UNO s digital I/O pins through respective current limiting resistors
of KΩ.All the co ectio s are ade as per the circuit diagra . The co plete wiri g diagra
of the circuit is shown below.

28
Program:
int Lane1[] = {13,12,11}; // Lane 1 Red, Yellow and Green
int Lane2[] = {10,9,8};// Lane 2 Red, Yellow and Green
int Lane3[] = {7,6,5};// Lane 3 Red, Yellow and Green
int Lane4[] = {4,3,2};// Lane 4 Red, Yellow and Green
void setup() {
for (int i = 0; i < 3; i++)
{
pinMode(Lane1[i], OUTPUT);
pinMode(Lane2[i], OUTPUT);
pinMode(Lane3[i], OUTPUT);
pinMode(Lane4[i], OUTPUT);
}
for (int i = 0; i < 3; i++)
{
digitalWrite(Lane1[i], LOW);
digitalWrite(Lane2[i], LOW);
digitalWrite(Lane3[i], LOW);
digitalWrite(Lane4[i], LOW);
}
}
void loop()
{
digitalWrite(Lane1[2], HIGH);
digitalWrite(Lane3[0], HIGH);
29
digitalWrite(Lane4[0], HIGH);
digitalWrite(Lane2[0], HIGH);
delay(7000);
digitalWrite(Lane1[2], LOW);
digitalWrite(Lane3[0], LOW);
digitalWrite(Lane1[1], HIGH);
digitalWrite(Lane3[1], HIGH);
delay(3000);
digitalWrite(Lane1[1], LOW);
digitalWrite(Lane3[1], LOW);
digitalWrite(Lane1[0], HIGH);
digitalWrite(Lane3[2], HIGH);
delay(7000);
digitalWrite(Lane3[2], LOW);
digitalWrite(Lane4[0], LOW);
digitalWrite(Lane3[1], HIGH);
digitalWrite(Lane4[1], HIGH);
delay(3000);
digitalWrite(Lane3[1], LOW);
digitalWrite(Lane4[1], LOW);
digitalWrite(Lane3[0], HIGH);
digitalWrite(Lane4[2], HIGH);
delay(7000);
digitalWrite(Lane4[2], LOW);
digitalWrite(Lane2[0], LOW);
digitalWrite(Lane4[1], HIGH);
digitalWrite(Lane2[1], HIGH);
delay(3000);
digitalWrite(Lane4[1], LOW);
digitalWrite(Lane2[1], LOW);
digitalWrite(Lane4[0], HIGH);
digitalWrite(Lane2[2], HIGH);
delay(7000);
digitalWrite(Lane1[0], LOW);
digitalWrite(Lane2[2], LOW);
digitalWrite(Lane1[1], HIGH);
digitalWrite(Lane2[1], HIGH);
delay(3000);
digitalWrite(Lane2[1], LOW);
digitalWrite(Lane1[1], LOW);
}

Result:

Thus, a traffic light controller using arduino kit was designed successfully.
30
Viva Questions:

1. What are the variance of arduino board?


2. What processor is used in arduino kit?
3. How many analog ports in arduino?
4. Write a code to display in serial monitor?
5. What is the purpose of loop() ?

31
Ex No.10 Design of a Simple chat Server using Arduino

Date:

Objective : To write a basic C program to chat server using arduino.

Apparatus :

 Arduino or Genuino Board


 Arduino Ethernet Shield

Pre Lab work:

Circuit Design:

The Ethernet shield allows you to connect a WizNet Ethernet controller to the Arduino or
Genuino boards via the SPI bus. It uses pins 10, 11, 12, and 13 for the SPI connection to
the WizNet. Later models of the Ethernet shield also have an SD Card on board. Digital pin 4 is
used to control the slave select pin on the SD card.

The shield should be connected to a network with an ethernet cable. We have change the
network settings in the program to correspond to our network.

In the above image, the Arduino or Genuino board would be stacked below the Ethernet shield.

32
Schematic:

Program:
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.


// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192,168,1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
33
// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously
void setup() {
// initialize the ethernet device
Ethernet.begin(mac, ip, myDns, gateway, subnet);
// start listening for clients
server.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Chat server address:");
Serial.println(Ethernet.localIP());
}
void loop() {
// wait for a new client:
EthernetClient client = server.available();

// when the client sends the first byte, say hello:


if (client) {
if (!alreadyConnected) {
// clear out the input buffer:
client.flush();
Serial.println("We have a new client");
client.println("Hello, client!");
alreadyConnected = true;
}
if (client.available() > 0) {
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.write(thisChar);
} } }

Result:

Thus, a chat server was implemented successfully using arduino kit.

34
Viva Question:
1. What is Ethernet shield?
2. What are the components required to chat using arduino?
3. What are the header protocol files need to be included?
4. What is the purpose of DHCP protocol?
5. What is meant by SPI?

35

You might also like