Assignmnent Isanka
Assignmnent Isanka
(Batch 004)
5CC002
By
W.A.I Dilshan
1
Acknowledgment
1
Abstract
This document proposes the design and development of three systems which using the Arduino
platform. Projects developed due to the requirement of gaining knowledge and as a Portfolio
exercises. Portfolios are lead to understand basic coding and hardware fixing to developing
encrypted communication using Xbee modules. At the beginning following the assignment
guidance developed the traffic light system, then impalement Morse code communication
method with the resources in internet. Each project incrementally helps to get hand on
awareness of Arduino platform. Those are Traffic Light System, Morse Encoder / Decoder and
encrypted communication using XBee
2
TABLE OF CONTENTS
Acknowledgment ………………………………………………………………... 01
Abstract ……….………………………………………………………………... 01
Table of Figures …………………………………………………………………. 05
1.0 Apparatus used in portfolios ………………………………………………. 06
1.1 Arduino Uno ………………………………………………………………... 06
1.2 Liquid Crystal Display (LCD) …………………………………………… 07
1.3 Buzzer …….……………………………………………………………….. 08
1.4 XBee module.…………………………………………………………….. 09
2. Implementation of Traffic Light…………………………………………… 11
2.1 Aims ……….………………………………………………………………. 11
2.2 Objectives …………………………………………………………………... 11
2.3 Apparatus…….……………………………………………………………… 11
2.4 Operation of 1st Part……………………………………………………….. 12
2.4.1 Flow Chart………………………………………………………… 12
2.4.2. Design and Implementation……………………………………... 13
2.4.3 Code ….…………………………………………………………… 14
2.4.4 Operation of code.………………………………………………… 14
2.5 Operation of 2nd Part………………………………………………………… 15
2.5.1 Flow Chart ………………………………………………………… 16
2.5.2. Design ……………………………………………………………… 16
2.5.3 Code ……….……………………………………………………… 17
2.5.4 Operation of code …………………………………………………… 18
2.6 conclusion ……….…………………………………………………………… 19
2.7 Further Implementation ……………………………………………………… 19
3.0 Implementation of Morse Encoder/Decoder………………………………… 20
3.1 Aims ……….………………………………………………………………... 20
3.2 Objectives ……….…………………………………………………………… 20
3.3 Apparatus……….……………………………………………………………… 20
3.4 Flowchart ……….…………………………………………………………… 21
3.4.1 Encoder .……………………………………………………………. 23
3.4.2 Decoder .……………………………………………………………. 23
3.5 Design and Implementation………………………………………………... 23
3.5.1 Encoder Design.……………………………………………………. 23
3.5.2 Decoder Design.……………………………………………………. 24
3.5.3 Morse code and symbols………………………………………….. 25
3.6 Code ……….………………………………………………………………... 26
3.6.1 Encoder Code.………………………………………………….…. 26
3.6.2 Decoder Code.…………………………………………………...…. 27
3.7 Operation of code ……….…………………………………………………... 28
3.7.1 Operation of encoder coding……………………………………….. 28
3.7.2 Operation of decoder coding……………………………………….. 28
3.8 conclusion ……….…………………………………………………………….. 29
3.9 Further Implementation.………………………………………………………. 29
3
4.0 Xbee Module Operations …………………………………………………….. 30
4.1 Aims …………………..………………………………………………………… 30
4.2 Objectives …………………..……………………………………………………. 30
4.3 Apparatus …………………..……………………………………………………... 30
4.4 Flowchart …………………..……………………………………………………... 31
4.4.1 Coordinator…………………………………………………………………
32
4.4.1 End Point…………………………………………………………………… 32
4.5 Design …………………..………………………………………………………… 33
4.5.1 Coordinator ………………………………………………………………... 33
4.5.2 End Point…………………………………………………………………… 34
4.6 Algorithm…………..……………………………………………………………….. 36
4.7 Code …………………..……………………………………………………………. 37
4.7.1 Coordinator ………………………………………………………………… 37
4.7.2 End Point ………………………………………………………………….. 37
4.8 Operation of code ………..………………………………………………………… 39
4.8.1 Coordinator ………………………………………………………………... 39
4.8.2 End Point…………………………………………………………………… 39
4.9 conclusion ……………..…………………………………………………………… 40
4.10Further Implementation…..………………………………………………………... 41
5.0 Resources ……………..…………………………………………………………… 42
4
TABLE OF FIGURES
5
1.Apparatus used in portfolios
6
1.2 Liquid Crystal Display (LCD)
LCDs are providing cost effective way to put a text output unit for a
microcontroller. LCD display commonly use 16 * 2 and 16 *4. In this project carryout by 16 * 2
display. It has 2 lines and can display 16 characters on each line. When it is interfaced with the
microcontroller, can scroll the messages with software to display information which is more
than 16 characters in length.
The LCD is a simple device to use but the internal details are complex. Most of the 16x2
LCDs use a Hitachi HD44780 or a compatible controller. A microcontroller is present inside a
Liquid crystal display. The Display Controller takes commands and data from a external
microcontroller and drivers the LCD panel. It takes a ASCII value as input and generate a patter
for the dot matrix.
7
The wiring diagram mention in Figure 03
1.3 Buzzer
In Arduino implementations Buzzer use to generate the sounds. In here Buzzer applied to make
the Beep tone according to the Morse encoder.
8
Figure 04- Buzzer
and Electronics Engineers). ZigBee aim to have lower data rate compared to Bluetooth, at 250Kbps.
More importantly, ZigBee aims for lower power applications which can operation on non-rechargeable
battery and it can connect to more nodes. While Bluetooth only offers 8 devices connection. ZigBee
designed for control and monitor while Bluetooth for cable replacement. ZigBee uses RF (Radio
Frequency) to communicate. There are 3 frequencies available, 2.4GHz, 915MHz & 868MHz.
The module connects to the Arduino board using a connecter and XTCU application use to
configure and communicate with each other modules in network.
9
Figure 05 mention the XBee module.
Figure 06 mention basement for connect the module and Arduino board.
10
Figure 06-Xbee module basement
2.1 Aims
2.2 Objectives
11
Develop an Arduino code which is integration with above systems.
Design a hardware units which can achieve required Aims.
2.3 Apparatus
Arduino Uno board
3 Light Emitting Diodes (LED) Red, Yellow, Green Colors
Connecting jumpers & breadboard
Build a circuit with three LEDs, a red, a yellow and a green. Create a sketch that
ripples through the LEDs such that, In order to the red LED ONLY lights up for half a second,
then Yellow after that Green LED lights up for half a second.
12
Figure 07-Flow chart 01
13
14
Figure 08- LED Connection
2.4.3 Code
int LED1 = 6; // 1 DIGITAL PIN-OUT
int LED2 = 8; // 2 DIGITAL PIN-OUT
int LED3 = 9; // 3 DIGITAL PIN-OUT
int DL=500;
void setup() {
pinMode(LED1 , OUTPUT);
pinMode(LED2 , OUTPUT);
pinMode(LED3 , OUTPUT);}
void loop() {
for ( int t=1; t<=1; t=t+1)
{ digitalWrite(LED1,HIGH); //start for loop
delay (DL);
digitalWrite(LED1,LOW);
delay (DL); }
{ //start for loop
digitalWrite(LED2,HIGH);
delay (DL);
digitalWrite(LED2,LOW);
delay (DL);}
{digitalWrite(LED3,HIGH);
delay (DL);
digitalWrite(LED3,LOW);
delay (DL);
}}
15
2.4.4 Operation of Code
void setup() {
pinMode(LED1 , OUTPUT);
pinMode(LED2 , OUTPUT);
pinMode(LED3 , OUTPUT);}
3. Loop part of the coding
This will repeat until the for loop exceed the condition t<=1, The increment will take
according to the t=t+1. According to the workshop bulbs are ON and OFF times has
defined. Each bulb ON and OFF time in 500 milliseconds.
void loop() {
for ( int t=1; t<=1; t=t+1)
{ digitalWrite(LED1,HIGH); //start for loop
delay (DL);
digitalWrite(LED1,LOW);
delay (DL); }
{ //start for loop
digitalWrite(LED2,HIGH);
delay (DL);
digitalWrite(LED2,LOW);
delay (DL);}
{digitalWrite(LED3,HIGH);
delay (DL);
digitalWrite(LED3,LOW);
delay (DL);
}}
16
2.5 Operation of 2nd Part
Build a circuit for traffic lights, with three LEDs Red, Amber, and Green.
The traffic light sequence is Red, Red and Amber, Green, Amber.
This loop starts again.
17
Figure 10- Flowchart 02
2.5.2 Design
Circuit was connected using the bread board and the connecting jumpers.
Hardware connection was kept as above part, and few changes were done to code for get the
required output.
2.5.3 Code
18
int LED1 = 6; // RED CONFIG DIGITAL PIN-OUT
int LED2 = 8; // AMBER CONFIG DIGITAL PIN-OUT
int LED3 = 9; // GREEN CONFIG DIGITAL PIN-OUT
int DL1=3000;
int DL2=500;
void setup() {
pinMode(LED1 , OUTPUT);
pinMode(LED2 , OUTPUT);
pinMode(LED3 , OUTPUT);
}
void loop() {
for ( int t=1; t<=1; t=t+1)
{ //start for loop
digitalWrite(LED1,HIGH); //RED LIGHT ON
delay (DL1);
digitalWrite(LED1,LOW);
delay (DL2);
}
{ //start for loop
digitalWrite(LED1,HIGH); //RED LIGHT ON
digitalWrite(LED2,HIGH);// AMBER LIGHT ON
delay (DL2);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
delay (DL2);
}
{
digitalWrite(LED3,HIGH);// GREEN LIGHT ON
delay (DL1);
digitalWrite(LED3,LOW);
delay (DL2);
}
{
digitalWrite(LED2,HIGH);// AMBER LIGHT ON
delay (DL2);
digitalWrite(LED2,LOW);
delay (DL2);
}
}
19
1 Initialization of the code
This part will setup pins in coding and the declarations that used in the coding.
Here used Digital Pin 6,8,9 as output pins and there are two delays are available.
DL1 delay of 3000 milliseconds and DL2 500 milliseconds.
void setup() {
pinMode(LED1 , OUTPUT);
pinMode(LED2 , OUTPUT);
pinMode(LED3 , OUTPUT);}
Practical in Traffic light system seconds of operation Green, Amber & Red are different.
DL1,DL2 basically used here short and long delay times.This will repeat until the for loop
exceed the condition t<=1, The increment will take according to the t=t+1.
void loop() {
for ( int t=1; t<=1; t=t+1)
{ //start for loop
digitalWrite(LED1,HIGH); //RED LIGHT ON
delay (DL1);
digitalWrite(LED1,LOW);
delay (DL2);
}
2.6 Conclusion
20
In summary this lab was helped to observe basics of Arduino coding. Mainly for identify
which part contribute to setup and operate as loop in the operation. In this Traffic light
scenario can use to one-way vehicles control with the pedestrian crossing. It hasn’t
mentioned clearly time delays for each operation. If it is possible to modulate the code to
operate this loop in only rush hours that would be more effective otherwise vehicles would
have to wait without any traffic or pedestrians.
This for loop, delay can have used as many as industrial operations which operate in
production lines combining more sensors, contactors, motors and actuators. Mostly in
production lines conveyer belt operations timers are most important. But the limited input,
output and not possible to communicate industrial protocols such as PPI, MPI, Profibus
leads to Arduino swap PLC in industrial operations.
3.2 Objectives
Get awareness about how serial monitor and LCD monitor operate in Arduino platform.
Develop an Arduino code which is possible to encode and decode Morse code.
How to connect LCD display without i2c converter using variable resistor
To decode the character according to buzzer sound or request as per lecture using push
button
3.3 Apparatus
3.4 Flowchart
22
3.4.1Encoder
Figure 11-Flowchart 03
23
3.4.2 Decoder
Figure 12--Flowchart 04
24
3.5 Design and Implementation
3.5.1 Encoder Design
25
3.5.2Decoder Design
26
Figure 16- Diagram
In this portfolio setup of initial connection for LCD display was completed according to
the given diagram. Encoder and Decoder setup was completed as above figures. 5V
power supply was given to power up LCD. Buzzer pin was separately connected to
Arduino board. In decoder side, push button was connected using voltage divider mode.
This voltage dividing operation was done by using a resistor.
27
voice communications and two-way radios were able to do the job better.
3.6 Code for Encoder and Decoder
{ lcd.print(dotOrDash);
delay(dotDelay); // To LCD print
28
{delay(dotDelay * 3); }
digitalWrite(ledPin, LOW); delay(dotDelay);}}
3.6.2 Decoder Code
29
3.7Operation of Code
3.7.1 Operation of Encoder Coding
1. Define Arduino libraries for LCD Display
2. In void setup
Define Morse code characters for each letter and number
Define Buzzer pin to output and communication start with serial monitor
3. In void loop
Define input latter as “I” and check the condition which category the “l” should include in to A
Simple letter, capital letter, Number or else Ignore
4.Appling Void LSequence and While loop check remaining letters that user input and convert in to the
Morse code
5.Then print the converted Morse code dot or dash on LCD and Generate the Buzzer sound according to
dot or dash
1.Define Arduino libraries for LCD Display, Define Switch pin to input signal
2.In void setup
Communicate start with Serial monitor and LCD
3.In void loop
Define t1 and t2 times and calculate signal length by t2-t1. According to conditions if time gap
below 50 ignore
Define LCD display to show all characters that input by press button
4.Char radio
define the time gap to identify dot or dash. If time length below 600 milliseconds that will be a
dot. If time length above the 600 milliseconds that will be a dash.
5.Void convertor
Define i = 0 and select the letter using ASCII values. Input characters has matched with Letters by
static string, identified letters will print on LCD
if there is any wrong input that will indicate as wrong
30
3.8Conclusion
In the practical, separately developed the both encoder and decoder. Encoder side use to transmit
the message using LCD monitor and Buzzer sounds, Decoder side code decoded in to Letters by
pressing the push button according to characters.
There were some features that tried to be added in decoder side. If mic can identify the sound of
Buzzer, it will decode the Morse message without push button. Although in the implementation
mic not able to properly detect sound lengths and gaps.
Another main problem was bouncing issue in push button, implementing push button to input the
Morse code. Push button was unable to input the signal properly.
All switches are not created equal, and some will fluctuate between both state LOW to HIGH
when pressing the switch and this can introduce multiple detected presses on the Arduino.
To control this issue debouncing was implemented in code. It will avoid the messages that
below 50 milliseconds.
Internal Pull-up resistor was used to ignore the delay from when the button is pressed until the
state of the pin actually changes. And stop the pin’s value will seem to randomly fluctuate from
HIGH to LOW
3.9Further Implementations
At the invented period of Morse code use to communicate with Navy, Pilots and Morse Code
was used during World War II. SOS signal use to communicate through Morse code when they
are in trouble. SOS mean international code to help.
There are many things that have Morse code used. SOS signal can flash using flashlights, smoke,
mirrors. Radio operators use Morse code to communicate when they are hosting contest to
communicate fast.
Morse Code has also been used as an alternative form of communication for people with
disabilities or whom have their abilities to communicate imparied by stroke, heart attack, or
31
paralysis. It remains popular among amateur radio operators.
4.2 Objectives
4.3 Apparatus
32
Two Arduino boards
Two Xbee modules
LCD display with i2c converter
Connecting jumpers
33
Figure 18-Xbee TX Flowchart
4.4.2 End Point (Receiver)
34
Figure 19-Xbee RX Flowchart
4.5 Design
35
Xbee module connected to Arduino board as below diagram
36
Figure 22- End point
37
Figure 24- End point XCTU
38
4.6 Algorithm
Caesar Cipher
The Caesar Cipher technique is one of the earliest and simplest method of encryption technique.
Each letter of a given text is replaced by a letter some fixed number of positions down the
alphabet.
Example with a shift of 1, A - B, B - C.
In this method to cipher a given text we need an integer value, known as shift which indicates the
number of position each letter of the text has been moved down.
The encryption can be represented using modular arithmetic by first transforming the letters into
numbers, according to the scheme, A = 0, B = 1,…, Z = 25.
In coding it can achieve by below equation
39
4.7 Code
4.7.1 Coordinator
#include <SoftwareSerial.h>
String result ="";
String text="";
String FN="";
int s =0;
SoftwareSerial cipertx(2,3);
void setup() {
Serial.begin(9600);
cipertx.begin(9600);
}
void loop() {
ENCODE();
}
void ENCODE(){
Serial.println("Enter Plain Text.");
while (Serial.available()==0){}
text = Serial.readString();
delay(500);
Serial.println("Enter Key.");
while (Serial.available()==0){}
s = Serial.parseInt();
int n =text.length();
String result ="";
for (int i=0;i<n;i++){
if (isupper(text[i])){
result += char(int(text[i]+s-65)%26 +65);
FN = result;}
else if(isWhitespace(text[i])){
result += char(int(text[i])); }
else
result += char(int(text[i]+s-97)%26 +97);
FN = result; }
cipertx.print(FN);
}
40
void setup()
{Serial.begin(9600);
cipertx.begin(9600);
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight(); // Print on LCD.
lcd.setCursor(0,0);
lcd.print("Begining....");}
void loop()
{while (cipertx.available()==0){}
text1 = cipertx.readString();
lcd.setCursor(0,0);
lcd.print("Encrypted Text ");
lcd.setCursor(0,1);
delay(50);
Serial.print("Encrypted Text ");
Serial.println(text1);
lcd.print(text1);
delay(50);
DECODE(); }
void DECODE(){
Serial.println("Key to show original text.");
while (Serial.available()==0){}
p = Serial.parseInt();
delay(500);
int n =text1.length();
String result ="";
for (int i=0;i<n;i++){
if (isupper(text1[i])){
result += char(int(text1[i]-p-65)%26 +65);
FN1 = result;}
else if(isWhitespace(text1[i])){
result += char(int(text1[i])); }
else
result += char(int(text1[i]-p-97)%26 +97);
FN1 = result; }
Serial.print(FN1);
delay(50);
lcd.setCursor(0,0);
lcd.clear();
lcd.print("Original Text.");
lcd.setCursor(0,1);
lcd.print(FN1);}
41
4.8 Operation of Code
4.8.1 Coordinator
1.SoftwareSerial library define to communicate between Xbee module
3.Void Setup
4.Void Encode
5.Then considering length of text "n" convert the text in to cipher text
It separately considers Capital letters, Space and simple letters using if condition
1.SoftwareSerial library define to communicate between Xbee module, Define libraries for i2c converter
and LCD display
3.Void Setup
Serial.begin use to communicate with serial display
Cipertx.begin use to communicate with serial in confidentially
Display on LCD as beginning
4.Void Loop
Display Encrypted text after received to end point
5.Void Decode
Display as asking the key to decrypt the encrypted message, then enter the key
After that consider length of text "n" of cipher text.
It separately considers Capital letters, Space and simple letters using if condition
Finally Display the Text as original Text
42
4.9 Conclusion
In this portfolio it was observed about XBee communication setup and how to configure
hardware devices. It was used two interface XBee module with Arduino Uno board. The XBee
connected with Arduino board will act as a receiver and Transmitter. The configurations for
receiver and transmitter were configured using the XCTU.
In this communication plain text should not be transmitted, Chiper text only should be transmit.
Issue was occurred in serial communication which plain text also get transmitting. To avoid this
separate communication build as a solution (cipertx.begin(9600);).
At the receiving end problem were occurred because of LCD and Xbee module both required
Transmit (TX) and Receive (RX) port, to overcome the problem separately two ports configured
to communication in Arduino board.
In coding part issue occurred due to space, space also identified as a character by Arduino. If
condition was applied to avoid it.
43
4.10 Further Implementation
In the lab we used to XBee modules to transmit the encrypted text from one location and it
decrypted in other end. This can develop to use in Local Area Network to exchange confidential
data like Banks, Stock market or any other Security related companies.
Xbee module can develop in both industrial and home automation applications.
44
5.Resources
https://tutorial.cytron.io/2011/03/06/is-xbee-zigbee/
http://shallowsky.com/arduino/class/buzzer.html
https://diagrams.visual-paradigm.com/#
https://prezi.com/k1lmgvmet0zh/the-industrial-revolution-morse-code/
http://wikid.io.tudelft.nl/WikID/index.php/XBee
https://www.geeksforgeeks.org/caesar-cipher/
45