Arduino Based Embedded Systems Interfacing Simulation and Labview Gui 1nbsped 9781138060784 Compress
Arduino Based Embedded Systems Interfacing Simulation and Labview Gui 1nbsped 9781138060784 Compress
Systems
Arduino-Based Embedded
Systems
Interfacing, Simulation, and LabVIEW GUI
Rajesh Singh
Anita Gehlot
Bhupendra Singh
Sushabhan Choudhury
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts
have been made to publish reliable data and information, but the author and publisher cannot assume
responsibility for the validity of all materials or the consequences of their use. The authors and publishers
have attempted to trace the copyright holders of all material reproduced in this publication and apologize
to copyright holders if permission to publish in this form has not been obtained. If any copyright material
has not been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter
invented, including photocopying, microfilming, and recording, or in any information storage or retrieval
system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.
com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood
Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and
registration for a variety of users. For organizations that have been granted a photocopy license by the
CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are
used only for identification and explanation without intent to infringe.
Section I Introduction
v
vi Contents
Section IV Projects
11. 2.4 GHz RF Modem-Based Security System for Restricted Area ..... 145
11.1 Introduction ..................................................................................... 145
11.2 Circuit Diagram .............................................................................. 146
11.3 Program ............................................................................................ 149
11.3.1 Transmitter Section ......................................................... 149
11.3.2 Receiver Section ............................................................... 150
11.4 Proteus Simulation Model ............................................................. 151
11.5 LabVIEW GUI ................................................................................. 152
12. Campus Fire Monitoring System with a 2.4 GHz RF Modem .......... 155
12.1 Introduction ..................................................................................... 155
12.2 Circuit Diagram .............................................................................. 156
12.2.1 Transmitter Section ......................................................... 156
12.2.2 Receiver Section ............................................................... 157
12.3 Program ............................................................................................ 158
12.3.1 Transmitter Section ......................................................... 158
12.3.2 Receiver Section ............................................................... 159
12.4 Proteus Simulation Model ............................................................. 160
12.5 LabVIEW GUI ................................................................................. 161
15. Stepper Motor Control System with LabVIEW GUI ........................... 185
15.1 Introduction ..................................................................................... 185
15.2 Circuit Diagram .............................................................................. 187
15.2.1 Transmitter Section ......................................................... 187
15.2.2 Receiver Section ............................................................... 187
15.3 Program ............................................................................................ 190
15.3.1 Transmitter Section ......................................................... 190
15.3.2 Receiver Program ............................................................ 191
15.4 Proteus Simulation Model ............................................................. 193
15.5 LabVIEW GUI .................................................................................. 195
Index .....................................................................................................................305
Preface
Rajesh Singh
Anita Gehlot
Bhupendra Singh
Sushabhan Choudhury
xiii
About the Authors
xv
xvi About the Authors
Introduction
1
Introduction to Arduino
Low cost: Arduino boards are of relatively low cost as compared to other
microcontroller platforms.
Cross-platform: The Arduino software (IDE) is compatible with the
Windows, Macintosh OSX, and Linux operating systems.
User friendly: The Arduino software (IDE) is user friendly and easy to
use for beginners and very flexible for skilled programmers.
Open source: The Arduino is an open-source software and can be pro-
grammed with C, C++, or AVR-C languages. So, a variety of mod-
ules can be designed by the users.
3
4 Arduino-Based Embedded Systems
FIGURE 1.1
Arduino Uno board.
TABLE 1.1
Pin Description of Arduino Uno
Pin Description
FIGURE 1.2
Arduino Mega board.
TABLE 1.2
Pin Description of Arduino Mega
Pin Description
FIGURE 1.3
Arduino Nano board.
TABLE 1.3
Pin Description of Arduino Nano
Pin Description
This chapter describes the steps to write and compile a program with
Arduino integrated development environment (IDE). The Arduino IDE is an
open-source software which makes it user friendly for writing the code and
then upload directly on Arduino board.
FIGURE 2.1
Window Arduino IDE.
7
8 Arduino-Based Embedded Systems
FIGURE 2.2
Window to select type of Arduino.
FIGURE 2.3
Compile the program.
Steps to Write a Program with Arduino IDE 9
FIGURE 2.4
Window to check port of Arduino.
10 Arduino-Based Embedded Systems
FIGURE 2.5
The serial port of board.
FIGURE 2.6
Window to upload the program in Arduino.
Steps to Write a Program with Arduino IDE 11
LCD Commands
This chapter describes the steps to design a Proteus simulation model for a
system and simulate it to check the feasibility of the designed system.
FIGURE 3.1
“New Design” window.
13
14 Arduino-Based Embedded Systems
FIGURE 3.2
Select “Default” template.
FIGURE 3.3
Window for New Design.
Steps to Design a Proteus Simulation Model 15
FIGURE 3.4
Window for “Pick from libraries.”
16 Arduino-Based Embedded Systems
FIGURE 3.5
Select components from the list.
FIGURE 3.6
Window showing selected components.
Steps to Design a Proteus Simulation Model 17
FIGURE 3.7
Proteus simulation model.
18 Arduino-Based Embedded Systems
FIGURE 3.8
Proteus simulation working model.
4
Introduction to LabVIEW GUI
This chapter describes the design steps for LabVIEW graphical user interface
(GUI) with a brief introduction to the basic blocks that are used to design
the GUI. LabVIEW GUI has two components: (1) the front panel and (2) the
block diagram. Control can be customized for different work environment.
Front panel is a window in which the final GUI will appear and at its back
end the “block diagram” runs, which is basically a graphical programming
language. Block diagram is designed with some predefined blocks and GUI
is developed by connecting the blocks.
19
20 Arduino-Based Embedded Systems
FIGURE 4.1
LabVIEW window to “Create project.”
Select Blank VI from the list of items and click on the Finish button
(Figure 4.2). A blank front panel window and block diagram win-
dow will appear (Figure 4.3).
Step 3: Running and Debugging VIs
To run a VI, connect all the sub VIs, functions, and structures as per the
data types for the terminals.
Introduction to LabVIEW GUI 21
FIGURE 4.2
Select “Blank VI” window.
(a) (b)
FIGURE 4.3
(a) Blank “block diagram” and (b) “front panel” window.
22 Arduino-Based Embedded Systems
FIGURE 4.4
Window to design “front panel.”
Introduction to LabVIEW GUI 23
FIGURE 4.5
Example of front panel.
FIGURE 4.6
Select components for “front panel.”
FIGURE 4.7
Example of “block diagram.”
FIGURE 4.8
VISA serial port.
VISA resource name (COM number): Right click on it and select create,
then select control to choose an appropriate COM port.
Baud rate: Choose 9600
Data bits: Choose 8 bits
Parity: Choose none
Stop bit: Choose 1
Flow control: Choose none
VISA resource name out: Connect this pin to VISA resource name of the
VISA serial read block.
Error out: Connect this pin to error pin of the VISA serial read.
VISA serial read: It reads the identified number of bytes from the device
or an interface identified by the VISA resource name and sends the
data in the read buffer. It reads the data available at the serial port
from the device linked (Figure 4.9).
FIGURE 4.9
VISA serial read.
26 Arduino-Based Embedded Systems
Byte count: Right click on it and select create to the indicator to count the
byte at the serial port.
Read buffer: Right click on it and select create to the indicator to check the
string value at the serial port.
Visa resource name out: Connect this pin to VISA resource name of VISA
close block.
Error out: Connect this pin to the error pin of VISA close.
Error in: Connect this pin to error out the pin of VISA configure serial
port.
Match pattern: It searches for an expression in the string beginning at
offset, and when it gets the string it matches the string with the pre-
defined data (Figure 4.10).
FIGURE 4.10
Match pattern.
String: Connect this pin to read buffer pin of the VISA read.
Regular expression: Right click on it and select create to the constant.
After substring: Connect this pin to the string of Decimal String to Number
block and create to constant.
Decimal string to number: It converts the numeric characters in the
string, starting at offset, to a decimal integer and returns it in number
(Figure 4.11).
FIGURE 4.11
Decimal string to number converter.
FIGURE 4.12
VISA close.
VISA serial write: Writes the data from write buffer to the device or
interface that is identified by the VISA resource name (Figure 4.13).
FIGURE 4.13
Defining VISA resource name.
VISA configure serial port: It sets the serial port identified by the VISA
resource name to the specified settings (Figure 4.14).
FIGURE 4.14
VISA configure serial port.
28 Arduino-Based Embedded Systems
VISA resource name (COM number): Right click on it, select create, and
then select the control to choose an appropriate COM port.
Baud rate: Choose 9600
Data bits: Choose 8 bits
Parity: Choose none
Stop bit: Choose 1
Flow control: Choose none
VISA resource name out: Connect this pin to the VISA resource name of
VISA serial read block.
Error out: Connect this pin to error pin of the VISA serial read.
VISA serial write: It writes the data from the write buffer to the device or
interface as stated by the VISA resource name (Figure 4.15).
FIGURE 4.15
VISA serial write.
VISA resource name: Connect this pin to the VISA resource name out pin
of VISA configure serial port.
Write buffer: It comprises the data to be written to the device. Right click
on it and select create to the constant to send string at the serial port.
VISA resource name out: Connect this pin to the Visa resource name of the
VISA close block.
Error out: Connect this pin to the error pin of VISA close.
Error in: Connect this pin to the error out pin of VISA configure serial
port.
VISA close: Closes a device session or an event object that is specified by
the VISA resource name (Figure 4.16).
FIGURE 4.16
VISA close.
5
LabVIEW Interfacing with the
Proteus Simulation Software
29
30 Arduino-Based Embedded Systems
Figure 5.1 shows the VSPE window that opens on clicking the software
icon.
FIGURE 5.1
VSPE window.
Figure 5.2 shows the VSPE window for pairing the two virtual ports.
FIGURE 5.2
VSPE window for pairing two virtual ports.
LabVIEW Interfacing with the Proteus Simulation Software 31
Figure 5.3 shows how to assign COM ports and then finish the pairing
process.
FIGURE 5.3
VSPE window for assigning COM port number.
Figure 5.4 shows the paired COM ports in VSPE. Let us assume that
COM1 is with the Proteus model and COM2 is with LabVIEW.
FIGURE 5.4
VSPE window showing paired COM ports.
32 Arduino-Based Embedded Systems
Figure 5.5 shows how to interface COMPIM with the controller in Proteus
model.
FIGURE 5.5
COMPIM and Arduino connection in Proteus.
FIGURE 5.6
Configure the COMPIM in Proteus to interface with LabVIEW.
Figure 5.7 shows the Proteus simulation model displaying the sensor value
on the virtual terminal after COM port pairing with VSPE. Figure 5.8 is picto-
rial representation of the complete process of interfacing Proteus Simulation
Software with LabVIEW.
FIGURE 5.7
Proteus simulation model showing sensor value at virtual terminal.
34 Arduino-Based Embedded Systems
FIGURE 5.8
Arduino interfacing with the LabVIEW.
Section II
This chapter describes the Arduino interfacing with the display devices such
as the light emitting diode (LED) and the liquid crystal display (LCD). The
working of the devices is discussed with the help of an interfacing circuit,
program, and Proteus simulation models.
FIGURE 6.1
Light emitting diode.
37
38 Arduino-Based Embedded Systems
TABLE 6.1
LED Characteristics
Semiconductor
S.No. Material Wavelength Color V F@20 mA
1 GaAs 850–940 nm Infrared 1.2 V
2 GaAsP 630–660 nm Red 1.8 V
3 GaAsP 605–620 nm Amber 2.0 V
4 GaAsP:N 585–595 nm Yellow 2.2 V
5 AlGaP 550–570 nm Green 3.5 V
6 SiC 430–505 nm Blue 3.5 V
7 GaInN 450 nm White 4.0 V
Source: http://www.electronics-tutorials.ws/diode/diode_8.html
TABLE 6.2
Components List to Study the Working of LED
Component/Specification Quantity
Power supply/+5 V/500 mA 1
Arduino Uno 1
LED 1
Connecting wires (M–M, M–F, F–F) 20 each
Zero-size PCB or bread board or a designed PCB 1
Figure 6.2 shows the circuit diagram of the Arduino interfacing with the
LED.
Arduino and Display Devices 39
FIGURE 6.2
Circuit diagram to read LED.
40 Arduino-Based Embedded Systems
6.1.2 Program
int LED_PIN=7;
void setup()
{
pinMode(LED_PIN, OUTPUT);// initialize pin 7 as output pin
}
void loop()
{
digitalWrite(LED_PIN, HIGH); // Make pin 7 HIGH
delay(1000); // 1000 mS delay
digitalWrite(LED_PIN, LOW); // Make pin 7 HIGH
delay(1000); // 1000 mS delay
}
FIGURE 6.3
Proteus simulation model to read LED.
Arduino and Display Devices 41
FIGURE 6.4
Liquid crystal display (16 × 2).
FIGURE 6.5
Liquid crystal display (20 × 4).
42 Arduino-Based Embedded Systems
TABLE 6.3
Pin Description of a LCD
Pin Description
1. (Ground) Ground (0 V)
2. (VCC) Power supply (5 V)
3. (VEE) Contrast adjustment with a variable resistor
4. (Register select) Selects command register when low and selects data register when high
5. (Read/write) Low to write to the register and high to read the register
6. (Enable) Send data to the data line when high to low pulse is given
7. (DB0) 8 bit data lines
8. (DB1)
9. (DB2)
10. (DB3)
11. (DB4)
12. (DB5)
13. (DB6)
14. (DB7)
15. (LED+) Backlight Vcc (5 V)
16. (LED−) Backlight ground (0 V)
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 6.6 shows the circuit diagram of the Arduino interfacing with the
LCD.
Arduino and Display Devices 43
FIGURE 6.6
Circuit diagram to read LCD.
6.2.2 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10,9,8);
void setup()
{
lcd.begin(20, 4);// Initialize LCD
lcd.print("WELCOME_UPES");// Print string on LCD
delay(2000);// Delay 2000mS
lcd.clear();
}
44 Arduino-Based Embedded Systems
void loop()
{
lcd.setCursor(0, 1);// set cursor of LCD
lcd.print("EIC Department");// Print string on LCD
delay(2000);// Delay 2000mS
lcd.setCursor(0, 2);// set cursor of LCD
lcd.print("UPES Dehradun");// Print string on LCD
delay(2000);// Delay 2000mS
}
FIGURE 6.7
Proteus simulation model to read LCD.
7
Arduino and Digital Input/Output Devices
This chapter describes the Arduino interfacing with digital I/O devices such
as a push button, fire sensor, passive infrared (PIR) sensor, and an alcohol
sensor. The working of the devices is discussed with the help of interfacing
circuit, program and proteus simulation models.
FIGURE 7.1
Push buttons.
45
46 Arduino-Based Embedded Systems
TABLE.7.1
Components List to Study the Working of a Push Button
Component/Specification Quantity
Figure 7.2 shows the block diagram to study the working of a push button
with Arduino, which comprises Arduino, power supply, liquid crystal display
(LCD), light emitting diode (LED), and a push button. LCD is connected to
display the required content that corresponds to the action taken. LEDs are
connected to show which action is taken, for example, if the button is not
pressed “blue” LED will glow and if it is pressed then “red” LED will glow.
The programmer can read a push button by two methods: (1) digital low
and (2) digital high.
Liquid crystal
display
(LCD)
LED
1
Power supply Arduino
LED
2
Push
button
FIGURE 7.2
Block diagram for Arduino interfacing with the push button.
Arduino and Digital Input/Output Devices 47
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
LED connection
• Arduino digital pin 3-RED-LED
• Arduino digital pin 2-BLUE-LED
Figure 7.3 shows the circuit diagram interfacing the push button with the
Arduino.
48
FIGURE 7.3
Arduino-Based Embedded Systems
7.2.2 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);// initialize the LCD
Library w.r t. RS,E,D4,D5,D6,D7
int BUTTON_LOW=5;
int RED_LED=3;
int BLUE_LED=2;
void setup()
{
pinMode(BUTTON_LOW, INPUT_PULLUP);//configure pin5 as an input
and enable the internal pull-up resistor
pinMode(RED_LED,OUTPUT);//
configure pin4 as outputpinMode(BLUE_LED,OUTPUT);//
configure pin3 as output
lcd.begin(20, 4);// set the type of LCD by number of
columns and rows
lcd.setCursor(0, 0);// set cursor to column0 and row1
lcd.print("DIGTAL LOW BUTTON ");// Print a message to
the LCD.
lcd.setCursor(0, 1);// set cursor to column0 and row1
lcd.print("READ SYSTEM.......");// Print a message to the LCD.
delay(1000);
}
void loop()
{
int BUTTON_LOW_READ = digitalRead(BUTTON_LOW);//read the
pushbutton value into a variable
if (BUTTON_LOW_READ == LOW)// Read PIN 5 as LOW PIN
{
lcd.clear();
lcd.setCursor(0, 2);// set cursor to column0 and row2
lcd.print("BUTTON_PRESSED ");// Print a message to the LCD.
digitalWrite(RED_LED, HIGH);//High PIN3
digitalWrite(BLUE_LED, LOW);// Low PIN2
delay(20);
}
else //otherwise
{
lcd.clear();
lcd.setCursor(0, 2);// set cursor to column0 and row2
lcd.print("BUTTON_NOT_PRESSED ");// Print a message to
the LCD.
digitalWrite(BLUE_LED, HIGH);//High PIN2
digitalWrite(RED_LED,LOW);//Low PIN3
delay(20);
}
}
50 Arduino-Based Embedded Systems
FIGURE 7.4
Proteus simulation model showing that the push button is not pressed.
Arduino and Digital Input/Output Devices 51
FIGURE 7.5
Proteus simulation model showing that the push button is pressed.
FIGURE 7.6
Circuit diagram to read the push button as digital “HIGH.”
Arduino-Based Embedded Systems
Arduino and Digital Input/Output Devices 53
7.3.1 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);// initialize the LCD
Library w.r t. RS,E,D4,D5,D6,D7
int BUTTON_HIGH=5;
int RED_LED=3;
int BLUE_LED=2;
void setup()
{
pinMode(BUTTON_HIGH, INPUT);//configure pin5 as an input and
enable the internal pull-up resistor
pinMode(RED_LED,OUTPUT);//configure pin4 as output
pinMode(BLUE_LED,OUTPUT);//configure pin3 as output
lcd.begin(20, 4);// set up the LCD's number of columns
and rows
lcd.setCursor(0, 0);// set cursor to column0 and row1
lcd.print("DIGTAL HIGH BUTTON ");// Print a message to
the LCD.
lcd.setCursor(0, 1);// set cursor to column0 and row1
lcd.print("READ SYSTEM.......");// Print a message to the LCD.
delay(1000);
}
void loop()
{
FIGURE 7.7
Proteus simulation model to read the push button as digital “HIGH” (button not pressed).
Arduino and Digital Input/Output Devices 55
FIGURE 7.8
Proteus simulation model to read the push button as digital “HIGH” (button pressed).
TABLE 7.2
Components List to Study the Working of a Fire Sensor
Component/Specification Quantity
FIGURE 7.9
Fire detector sensor module (Robosoft systems).
Liquid crystal
display
(LCD)
LED
Power Arduino 1
supply Uno
LED
2
Fire
sensor
FIGURE 7.10
Block diagram to study the fire sensor.
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
LED connection
• Arduino digital pin 7-RED-LED
• Arduino digital pin 6-BLUE-LED
Figure 7.11 shows the circuit diagram to study the working of the fire sensor.
Connect all the components as described in Section 7.4.1. Red LED will glow,
when it will detect fire or else Blue LED will glow.
58
FIGURE 7.11
Arduino-Based Embedded Systems
7.4.2 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);// initialize the
LCD Library w.r t. RS,E,D4,D5,D6,D7
int FIRE_SENSOR_LOW=2;
int RED_LED=7;
int GREEN_LED=6;
void setup()
{
pinMode(FIRE_SENSOR_LOW, INPUT_PULLUP);//configure pin5 as
an input and enable the internal pull-up resistor
pinMode(RED_LED,OUTPUT);//configure pin4 as output
pinMode(GREEN_LED,OUTPUT);//configure pin3 as output
lcd.begin(20, 4);// set up the LCD's number of columns and rows
lcd.setCursor(0, 0);// set cursor to column0 and row1
lcd.print("FIRE SENSOR BASED ");// Print a message to the LCD.
lcd.setCursor(0, 1);// set cursor to column0 and row1
lcd.print(" FIRE DETECTION SYSTEM...");// Print a message to
the LCD.
delay(1000);
}
void loop()
{
FIGURE 7.12
Proteus simulation model to study the fire sensor (fire not detected).
FIGURE 7.13
Proteus simulation model to study the fire sensor (fire detected).
FIGURE 7.14
PIR sensor (sunrom-1133).
Liquid crystal
display
(LCD)
LED
Power 1
Arduino
supply Uno LED
2
PIR
sensor
FIGURE 7.15
Block diagram to study the working of a PIR sensor.
TABLE 7.3
Components List to Study the Working of a PIR Sensor
Component/Specification Quantity
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
LED connection
• Arduino digital pin 7-RED-LED
• Arduino digital pin 6-BLUE-LED
Figure 7.16 shows the circuit diagram of the system to study the working fire
sensor, comprising Arduino, power supply, LEDs, and the fire sensor.
7.5.2 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);// initialize
the LCD Library w.r t. RS,E,D4,D5,D6,D7
int PIR_SENSOR_LOW=5;
int RED_LED=7;
int BLUE_LED=6;
void setup()
{
pinMode(PIR_SENSOR_LOW, INPUT_PULLUP);//configure pin5 as
an input and enable the internal pull-up resistor
pinMode(RED_LED,OUTPUT);//configure pin4 as output
pinMode(BLUE_LED,OUTPUT);//configure pin3 as output
64
FIGURE 7.16
Circuit diagram to study the working of a PIR sensor.
Arduino-Based Embedded Systems
Arduino and Digital Input/Output Devices 65
void loop()
{
FIGURE 7.17
Proteus simulation model for a PIR sensor (motion detected).
FIGURE 7.18
Proteus simulation model for a PIR sensor (motion not detected).
Arduino and Digital Input/Output Devices 67
FIGURE 7.19
Alcohol sensor from sunrom.
68 Arduino-Based Embedded Systems
TABLE 7.4
Components List to Study the Working of an Alcohol Sensor
Component/Specification Quantity
Figure 7.20 shows the block diagram of the system to study the working of
an alcohol sensor. It comprises Arduino, power supply, LEDs, and an alcohol
sensor.
Liquid crystal
display
(LCD)
LED
Power 1
Arduino
supply Uno LED
2
Alcohol
detector
sensor
FIGURE 7.20
Block diagram to study the working of an alcohol sensor.
Arduino and Digital Input/Output Devices 69
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
LED connection
• Arduino digital pin 5-RED-LED
• Arduino digital pin 4-BLUE-LED
Figure 7.21 shows the circuit diagram to study the alcohol sensor.
70
FIGURE 7.21
Arduino-Based Embedded Systems
7.6.2 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);// initialize the
LCD Library w.r t. RS,E,D4,D5,D6,D7
int ALCOHOL_SENSOR_LOW=3;
int RED_LED=5;
int GREEN_LED=4;
void setup()
{
pinMode(ALCOHOL_SENSOR_LOW, INPUT_PULLUP);//configure pin5 as
an input and enable the internal pull-up resistor
pinMode(RED_LED,OUTPUT);//configure pin4 as output
pinMode(GREEN_LED,OUTPUT);//configure pin3 as output
lcd.begin(20, 4);// set the type of LCD as per number of
columns and rows
lcd.setCursor(0, 0);// set cursor to column0 and row1
lcd.print("ALCOHOL SENSOR BASED");// Print a message to the
LCD.
lcd.setCursor(0, 1);// set cursor to column0 and row1
lcd.print("ALCOHOL DETECTION ");// Print a message to
the LCD.
lcd.setCursor(0, 2);// set cursor to column0 and row2
lcd.print("SYSTEM AT UPES.....");// Print a message to the LCD.
delay(1000);
}
void loop()
{
else //oterwise
{
lcd.clear();
lcd.setCursor(0, 3);// set cursor to column0 and row3
lcd.print("ALCOHOL NOT DETECTED ");// Print a message to
the LCD.
digitalWrite(GREEN_LED, HIGH);//High PIN2
digitalWrite(RED_LED,LOW);//Low PIN3
delay(20);
}
}
FIGURE 7.22
Proteus simulation model for an alcohol sensor (alcohol not detected).
Arduino and Digital Input/Output Devices 73
FIGURE 7.23
Proteus simulation model for an ultrasonic sensor (alcohol detected).
8
Arduino and Analog Devices
This chapter describes the Arduino interfacing with the analog devices such
as ultrasonic sensor, passive infrared (PIR) sensor, and an alcohol sensor.
The working of the devices is discussed with the help of the interfacing cir-
cuit, program, and proteus simulation models.
Liquid crystal
display
(LCD)
Ultrasonic
sensor
FIGURE 8.1
Block diagram to study an ultrasonic sensor.
75
76 Arduino-Based Embedded Systems
TABLE 8.1
Component List to Study the Working of an Ultrasonic Sensor
Component/Specification Quantity
Packet Format
ASCII ASCII ASCII Fixed ASCII ASCII ASCII Fixed ASCII Fixed
(0–9) (0–9) (0–9) decimal (0–9) (0–9) (0–9) character ASCII
(.) (c) character
(m)
Figure 8.2 shows the snapshot of an ultrasonic sensor from Sunrom with the
Model no. 1166.
Arduino and Analog Devices 77
FIGURE 8.2
An ultrasonic sensor (Sunrom-1166).
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 8.3 shows the circuit diagram interfacing the ultrasonic sensor with
Arduino.
78
FIGURE 8.3
Circuit diagram to study the working of an ultrasonic sensor.
Arduino-Based Embedded Systems
Arduino and Analog Devices 79
8.2.2 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String inputString_Ultrasonic_serialout = ""; // a string
to hold incoming data
boolean stringComplete_Ultrasonic_serialout = false;
// whether the string is complete
void setup( ) {
// initialize serial:
Serial.begin(9600);
lcd.begin(20, 4);
inputString_Ultrasonic_serialout.reserve(200);
}
void loop()
{
if (stringComplete_Ultrasonic_serialout)
{
lcd.clear();
lcd.print(inputString_Ultrasonic_serialout);
Serial.println(inputString_Ultrasonic_serialout);
lcd.setCursor(0,3);
lcd.print(inputString_Ultrasonic_serialout[0]);
lcd.print(inputString_Ultrasonic_serialout[1]);
lcd.print(inputString_Ultrasonic_serialout[2]);
lcd.print(inputString_Ultrasonic_serialout[3]);
lcd.print(inputString_Ultrasonic_serialout[4]);
lcd.print(inputString_Ultrasonic_serialout[5]);
if((inputString_Ultrasonic_serialout[1]>='3')&&
(inputString_Ultrasonic_serialout[2]>='5'))
{
lcd.setCursor(0,2);
lcd.print("WATER LEVEL OVER");
}
else
{
lcd.setCursor(0,2);
lcd.print("WATER LEVEL OK");
}
inputString_Ultrasonic_serialout = "";
stringComplete_Ultrasonic_serialout = false;
}
}
80 Arduino-Based Embedded Systems
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString_Ultrasonic_serialout += inChar;
if (inChar == 0x0D)
{
stringComplete_Ultrasonic_serialout = true;
}
}
}
FIGURE 8.4
Proteus simulation model showing the working of an ultrasonic sensor.
Arduino and Analog Devices 81
FIGURE 8.5
An ultrasonic sensor (Sunrom-3719).
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 8.6 shows the circuit diagram of an ultrasonic sensor in the PWM mode.
82
FIGURE 8.6
Arduino-Based Embedded Systems
8.3.2 Program
8.3.2.1 Ultrasonic Sensor—PWM OUT
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // initialize the LCD
pin RS,E,D4,D5,D6,D7
const int pingPin = 5; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 4; // Echo Pin of Ultrasonic Sensor
void setup()
{
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("Ultrasonic distance");
lcd.setCursor(0, 1);
lcd.print("System at UPES");
delay(1000);
}
void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
lcd.clear();
lcd.setCursor(0, 2);
lcd.print(inches);
lcd.setCursor(4, 2);
lcd.print("in, ");
lcd.setCursor(8, 2);
lcd.print(cm);
lcd.setCursor(12, 2);
lcd.print("cm");
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();*/
delay(200);
}
84 Arduino-Based Embedded Systems
FIGURE 8.7
Proteus simulation model to study the working of an ultrasonic sensor (PWM mode).
Arduino and Analog Devices 85
Liquid crystal
display
(LCD)
Temperature
analog out
FIGURE 8.8
Block diagram to study the temperature sensor.
TABLE 8.2
Component List to Study the Working of Temperature Sensor
Component/Specification Quantity
Power supply/+12 V/1 A, + 5 V/500 mA 1
Arduino Uno 1
Temperature sensor 1
LCD (20 * 4) 1
LCD patch 1
Sensor patch 1
Connecting wires (M–M, M–F, F–F) 20 each
Zero-size PCB or bread board or a designed PCB 1
86 Arduino-Based Embedded Systems
FIGURE 8.9
LM35.
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 8.10 shows the circuit diagram for the temperature sensor interfacing
with the Arduino.
Arduino and Analog Devices
FIGURE 8.10
Circuit diagram to interface temperature sensor and Arduino.
87
88 Arduino-Based Embedded Systems
8.5.2 Program
8.5.2.1 Program LM35—Analog Out
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10,9, 8);// attach LCD pin
RS,E,D4,D5,D6,D7 to the given pins
int TEMP_sensor_Pin = A0; // select the input pin for the
potentiometer
int TEMP_sensor_ADC_Value = 0; // variable to store the
value coming from the sensor
void setup()
{
FIGURE 8.11
Proteus simulation model for working of the temperature sensor.
89
90 Arduino-Based Embedded Systems
FIGURE 8.12
Temperature/humidity sensor (Sunrom-1211).
Table 8.3 shows the pin description and Table 8.4 shows the packet format
for the sensor model no. 1211.
TABLE 8.3
Pin Description of Humidity/Temperature Sensor-Serial Out (Sunrom-1211)
Pin1 Pin2 Pin3
GND +5 V Transmit out-serial data at 9600 bps, 8 bit data, no parity, 1 stop bit.
TABLE 8.4
Packet Format
Byte Count Details
1 New line character: “\n”
2 Fixed character, “H”
3 Fixed character, “:”
4 Humidity character: “Hundreds”
5 Humidity character: “Tens”
6 Humidity character: “Ones”
(Continued)
Arduino and Analog Devices 91
7 Space
8 Fixed character: “T”
9 Fixed character: “:”
10 Temperature character: “Hundreds”
11 Temperature character: “Tens”
12 Temperature character: “Ones”
13 New line character: “\r”
Liquid crystal
display
(LCD)
Temp + Humidity
sensor
serial-out
FIGURE 8.13
Block diagram to study temperature/humidity sensor.
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 8.14 shows the circuit diagram for the temperature/humidity sensor
interfacing with the Arduino.
FIGURE 8.14
Circuit diagram to interface the temperature/humidity sensor.
Arduino and Analog Devices 93
8.6.2 Program
8.6.2.1 Temp/Humidity Sensor—Serial Out
#include <LiquidCrystal.h>
void setup()
{
Serial.begin(9600);
lcd.begin(20, 4);
inputString_TEMP_HUMI.reserve(200); // 200 bytes for the
inputString
lcd.setCursor(0,0);
lcd.print("TEMP_HUMIDITY");
lcd.setCursor(0,1);
lcd.print("RADIATION_sensor");
delay(2000);
}
void loop()
{
if (stringComplete_TEMP_HUMI)
{
lcd.clear();
Serial.println(inputString_TEMP_HUMI);
lcd.setCursor(0,2);
lcd.print("HUM:");
lcd.print(inputString_TEMP_HUMI[3]);
lcd.print(inputString_TEMP_HUMI[4]);
lcd.print(inputString_TEMP_HUMI[5]);
lcd.setCursor(0,3);
lcd.print("TEMP:");
lcd.print(inputString_TEMP_HUMI[9]);
lcd.print(inputString_TEMP_HUMI[10]);
lcd.print(inputString_TEMP_HUMI[11]);
if(inputString_TEMP_HUMI[0]==0x0A)
{
lcd.setCursor(0,2);
lcd.print("HUM:");
lcd.print(inputString_TEMP_HUMI[4]);
lcd.print(inputString_TEMP_HUMI[5]);
94 Arduino-Based Embedded Systems
lcd.print(inputString_TEMP_HUMI[6]);
lcd.setCursor(0,3);
lcd.print("TEMP:");
lcd.print(inputString_TEMP_HUMI[10]);
lcd.print(inputString_TEMP_HUMI[11]);
lcd.print(inputString_TEMP_HUMI[12]);
}
inputString_TEMP_HUMI = "";
stringComplete_TEMP_HUMI = false;
}
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString_TEMP_HUMI += inChar;
if (inChar == 0x0D)
{
stringComplete_TEMP_HUMI = true;
}
}
}
Liquid crystal
display
(LCD)
LDR
analog out
FIGURE 8.15
Block diagram to study the LDR.
Figure 8.16 shows the snapshot for the LDR. To study the behavior of
LDR, a small system can be developed. Table 8.5 shows the components list
required to implement it.
FIGURE 8.16
LDR (Sunrom-3190).
96 Arduino-Based Embedded Systems
TABLE 8.5
Component List to Study the Working of LDR
Component/Specification Quantity
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 8.17 shows the circuit diagram for LDR interfacing with Arduino.
Arduino and Analog Devices
FIGURE 8.17
Circuit diagram for LDR interfacing with the Arduino.
97
98 Arduino-Based Embedded Systems
8.8.2 Program
8.8.2.1 Light-Dependent Resistor—Analog Out
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10,9, 8);// attach LCD pin
RS,E,D4,D5,D6,D7 to the given pins
int LDR_sensor_Pin = A0; // select the input pin for the
potentiometer
int LDR_sensor_ADC_Value = 0; // variable to store the value
coming from the sensor
int RED_LED=7;
void setup()
{
void loop()
{
LDR_sensor_ADC_Value = analogRead(LDR_sensor_Pin);
// read the value from the sensor
lcd.setCursor(0,2);
lcd.print("ADC LEVEL+LDR:");
lcd.setCursor(17,2);
lcd.print(LDR_sensor_ADC_Value);
if(LDR_sensor_ADC_Value>=100)
{
digitalWrite(RED_LED,HIGH);
delay(20);
}
else
{
digitalWrite(RED_LED,LOW);
delay(20);
}
}
Arduino and Analog Devices 99
FIGURE 8.18
Proteus simulation model for LDR interfacing.
100 Arduino-Based Embedded Systems
Liquid crystal
display
(LCD)
Light
sensor
12C-out
FIGURE 8.19
Block diagram to study the light sensor.
FIGURE 8.20
Light sensor (BH1750FVI).
Arduino and Analog Devices 101
Table 8.6 shows the component list to study the working of a light sensor.
TABLE 8.6
Component List to Study the Working of a Light Sensor
Component/Specification Quantity
Power supply/+12 V/1 A, + 5 V/500 mA 1
Arduino Uno 1
Light sensor (BM1750) I2C out 1
LCD (20 * 4) 1
LCD patch 1
Sensor patch 1
Connecting wires (M–M, M–F, F–F) 20 each
Zero-size PCB or bread board or a designed PCB 1
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 8.21 shows the circuit diagram of the light sensor interfacing with the
Arduino.
102
FIGURE 8.21
Arduino-Based Embedded Systems
8.9.2 Program
8.9.2.1 LDR TWI (I2C) Out
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;
void setup()
{
lcd.begin(16,4);
Serial.begin(9600);
lightMeter.begin();
lcd.setCursor(0,0);
lcd.print("LIGHT SENSOR");
lcd.setCursor(0,1);
lcd.print("MBM1750 at UPES");
void loop()
{
uint16_t lux = lightMeter.readLightLevel();
lcd.setCursor(0,2);
lcd.print("LIGHT LEVEL:");
lcd.print(lux);
lcd.print("lux");
Serial.print("Light level: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}
Liquid crystal
display
(LCD)
POT
analog out
FIGURE 8.22
Block diagram to study a servo motor.
FIGURE 8.23
Servo motor from Robokits.
TABLE 8.7
Component List to Study the Working of a Servo Motor
Component/Specification Quantity
Servo connection
• Arduino GND-Module GND
• Arduino +5 V-Module +
• Arduino pin(3)-servo PWM pin
POT connection
• Arduino GND-Module GND
• Arduino +5 V-Module +
• Arduino A0 pin-data out pin of POT
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 8.24 shows the circuit diagram to interface servo motor with the
Arduino.
106
FIGURE 8.24
Circuit diagram to interface servo motor.
Arduino-Based Embedded Systems
Arduino and Analog Devices 107
8.10.2 Program
#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
Servo myservo;
int POT_PIN = A0; // analog pin used to connect the
potentiometer
int POT_PIN_ADC_LEVEL; // variable to read the value from
the analog pin
void setup()
{ myservo.attach(3); // connect the servo on pin 9 to the
servo object
lcd.begin(20,4);
lcd.setCursor(0, 0);
lcd.print("Servo ANALOG write ");
lcd.setCursor(0, 1);
lcd.print("system at UPES....");
}
void loop()
{
POT_PIN_ADC_LEVEL = analogRead(POT_PIN); // reads
the value of the potentiometer (value between 0 and 1023)
FIGURE 8.25
Proteus simulation model for servo motor interfacing with Arduino.
9
Arduino and Motors/Actuators
This chapter describes the Arduino interfacing with the motors or actuators
such as DC motor, stepper motor, and the AC motor. The working of the
devices is discussed with the help of an interfacing circuit, program, and
Proteus simulation models.
9.1 DC Motor
DC motor with 100 rpm is used to demonstrate the working. It is very easy
to use and is available in standard size. It has 1.2 kg/cm torque, No-load
current = 60 mA (Max), and Load current = 300 mA (Max). Figure 9.1 shows
the DC motor from Robokits India.
Figure 9.2 shows the block diagram to study the working of a DC motor.
Block diagram comprises the Arduino Uno, liquid crystal display (LCD),
power supply, DC motor, and motor driver. As DC motor is 12 V/1 A, so
L293D motor driver is used.
FIGURE 9.1
DC motor from Robokits India.
109
110 Arduino-Based Embedded Systems
Liquid crystal
display
(LCD)
LEDs
FIGURE 9.2
Block diagram to study a DC motor.
Table 9.1 shows the component list for interfacing the DC motor with the
Arduino.
TABLE 9.1
Component List to Study the Working of a DC Motor
Component/Specification Quantity
L293D connection
• Arduino GND-4,5,12,13 pins of IC
• Arduino +5 V-1,9,16 pins of IC
• Arduino pin 7-pin 2 of IC
• Arduino pin 6-pin 7 of IC
• Arduino pin 5-pin 10 of IC
• Arduino pin 4-pin 15 of IC
• L293D pin8-+ve of 12 V battery
LED connection
• Arduino pin 7-LED1
• Arduino pin 6-LED2
• Arduino pin 5-LED3
• Arduino pin 4-LED4
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 9.3 shows the circuit diagram to interface the DC motor with the
Arduino.
112
FIGURE 9.3
Arduino-Based Embedded Systems
9.1.2 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int MPIN1= 7;
int MPIN2= 6;
int MPIN3= 5;
int MPIN4= 4;
void setup()
{
pinMode(MPIN1, OUTPUT);
pinMode(MPIN2, OUTPUT);
pinMode(MPIN3, OUTPUT);
pinMode(MPIN4, OUTPUT);
lcd.begin(20,4);
lcd.setCursor(0, 0);
lcd.print("DC Motor direction");
lcd.setCursor(0, 1);
lcd.print("control system...");
delay(1000);
lcd.clear();
}
delay(2000);
lcd.clear();
digitalWrite(MPIN1, HIGH);
digitalWrite(MPIN2, LOW);
digitalWrite(MPIN3, LOW);
digitalWrite(MPIN4, LOW);
lcd.setCursor(0, 2);
lcd.print("RIGHT");
delay(2000);
lcd.clear();
}
FIGURE 9.4
Proteus simulation model to control DC motor (anticlockwise).
Arduino and Motors/Actuators 115
FIGURE 9.5
Proteus simulation model to control a DC motor (clockwise).
FIGURE 9.6
Stepper motor from Robokits India.
116 Arduino-Based Embedded Systems
Figure 9.7 shows the block diagram to study the working of a stepper
motor. It comprises Arduino Uno, power supply, LCD, stepper motor, and a
motor driver (L293D).
Liquid crystal
display
(LCD)
LEDs
FIGURE 9.7
Block diagram to study the working of a stepper motor.
Table 9.2 shows the component list for interfacing stepper motor with the
Arduino.
TABLE 9.2
Component List to Study the Working of a Stepper Motor
Component/Specification Quantity
L293D connection
• Arduino GND-4,5,12,13 pins of IC
• Arduino +5 V-1,9,16 pins of IC
• Arduino pin 7-pin 2 of IC
• Arduino pin 6-pin 7 of IC
• Arduino pin 5-pin 10 of IC
• Arduino pin 4-pin 15 of IC
• L293D pin8-+ve of 12 V battery
LED connection
• Arduino pin 7-LED1
• Arduino pin 6-LED2
• Arduino pin 5-LED3
• Arduino pin 4-LED4
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 9.8 shows the circuit diagram to interface the stepper motor with the
Arduino.
118
FIGURE 9.8
Arduino-Based Embedded Systems
9.2.2 Program
#include <LiquidCrystal.h>
int A_Phase_MPIN1= 7;
int B_Phase_MPIN2= 6;
int C_Phase_MPIN3= 5;
int D_Phase_MPIN4= 4;
void setup()
{
pinMode(A_Phase_MPIN1, OUTPUT);
pinMode(B_Phase_MPIN2, OUTPUT);
pinMode(C_Phase_MPIN3, OUTPUT);
pinMode(D_Phase_MPIN4, OUTPUT);
lcd.begin(20,4);
lcd.setCursor(0, 0);
lcd.print("DC Motor direction");
lcd.setCursor(0, 1);
lcd.print("control system...");
delay(2000);
lcd.clear();
}
digitalWrite(D_Phase_MPIN4, LOW);
lcd.setCursor(0, 2);
lcd.print("270 Degree");
delay(2000);
lcd.clear();
digitalWrite(A_Phase_MPIN1, LOW);
digitalWrite(B_Phase_MPIN2, LOW);
digitalWrite(C_Phase_MPIN3, LOW);
digitalWrite(D_Phase_MPIN4, HIGH);
lcd.setCursor(0, 2);
lcd.print("360 Degree");
delay(2000);
lcd.clear();
}
FIGURE 9.9
Proteus simulation model to control a stepper motor.
Arduino and Motors/Actuators 121
Liquid crystal
display
(LCD)
FIGURE 9.10
Block diagram to study an AC motor.
Table 9.3 shows the component list for interfacing AC motor with the
Arduino.
TABLE 9.3
Component List to Study the Working of a AC Motor
Component/Specification Quantity
LCD connection
• Arduino digital pin 13-RS pin(4) of LCD
• Arduino digital pin GND-RW pin(5) of LCD
• Arduino digital pin 12-E pin(6) of LCD
• Arduino digital pin 11-D4 pin(11) of LCD
• Arduino digital pin 10-D5 pin(12) of LCD
• Arduino digital pin 9-D6 pin(13) of LCD
• Arduino digital pin 8-D7 pin(14) of LCD
Figure 9.11 shows the circuit diagram to interface the AC motor with the
Arduino through the relay and the transistor.
Arduino and Motors/Actuators
FIGURE 9.11
123
9.3.2 Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int RELAY_2N2222= 7;
void setup()
{
lcd.begin(20,4);
pinMode(RELAY_2N2222, OUTPUT);
lcd.setCursor(0, 0);
lcd.print("AC MOTOR ON/OFF");
lcd.setCursor(0, 1);
lcd.print("System at UPES");
delay(1000);
}
void loop()
{
lcd.setCursor(0, 2);
lcd.print("AC MOTOR ONN");
digitalWrite(RELAY_2N2222, HIGH); // turn the LED on
(HIGH is the voltage level)
delay(2000); // wait for a second
lcd.setCursor(0, 2);
lcd.print("AC MOTOR OFF");
digitalWrite(RELAY_2N2222, LOW); // turn the LED off by
making the voltage LOW
delay(2000); // wait for a second
}
FIGURE 9.12
Proteus simulation model to control AC motor (ON condition).
FIGURE 9.13
Proteus simulation model to control AC motor (OFF condition).
Section III
Frequency channel setting can be used to have multiple sets operating at the
same time but without interfering with each other. The pair with the same
channel setting can communicate with each other. Frequency channel has to
be set when the unit is OFF. Frequency channel can be configured as follows:
Figure 10.1 shows the snapshot of the 2.4 GHz RF modem (Table 10.1).
129
130 Arduino-Based Embedded Systems
FIGURE 10.1
2.4 GHz RF modem (Sunrom model-1418).
TABLE 10.1
Pin Description of RF Modem
RXD Receive input (Connected to TXD pin of the microcontroller)
TXD Transmit output (Connected to RXD pin of the microcontroller)
+3/5 V Regulated 3.3–5 V supply input
GND Ground (Must be connected with the ground of microcontroller)
Temperature
sensor Power supply
12 V/1 A
FIGURE 10.2
Block diagram to study the RF modem.
Arduino and Wireless Communication 131
Table 10.2 shows the components that are required to study the operation of
a RF modem.
TABLE 10.2
Components List to Study the Working of a RF Modem
Component/Specification Quantity
Figure 10.3 shows the circuit diagram for the transmitter and the receiver
sections.
Arduino and Wireless Communication
FIGURE 10.3
133
10.1.2 Program
10.1.2.1 Transmitter Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int TEMP_SENSOR=A0;
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);// initialize serial communication at
9600 bits per second
lcd.setCursor(0,0);
lcd.print("wireless Serial ");
lcd.setCursor(0,1);
lcd.print("communication via 2.4 GHz");
lcd.setCursor(0,2);
lcd.print("modem at SME.....");
}
void loop()
{
int TEMP_SENSOR_ADC_VALUE = analogRead(TEMP_SENSOR);
int TEMP_VAL=TEMP_SENSOR_ADC_VALUE/2;//10mV/0C is resolution
of sensor
lcd.setCursor(0,3);
lcd.print("Temp. in 0C:");
lcd.setCursor(13,3);
lcd.print(TEMP_VAL);// print temperature value on LCD
Serial.write(TEMP_VAL);
delay(100);
}
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);// initialize serial communication at 9600
bits per second
lcd.setCursor(0,0);
lcd.print("wireless Serial ");
lcd.setCursor(0,1);
lcd.print("communication via 2.4 GHz");
lcd.setCursor(0,2);
lcd.print("modem at SME.....");
}
Arduino and Wireless Communication 135
Serial.print("TEMP_VAL:");
Serial.println(TEMP_VALUE);
delay(100); // delay in between reads for stability
}
FIGURE 10.4
Proteus simulation model for the transmitter and receiver.
136 Arduino-Based Embedded Systems
FIGURE 10.5
Proteus simulation model with virtual terminal.
FIGURE 10.6
GSM modem.
Liquid crystal
display Wireless
(LCD)
Temperature
sensor
FIGURE 10.7
Block diagram to study the GSM modem.
TABLE 10.3
Components List to Study the Working of a GSM Modem
Component/Specification Quantity
Circuit diagram.
FIGURE 10.8
140 Arduino-Based Embedded Systems
10.2.2 Program
To program GSM modem, make pin9 and pin10 as transmitter and receiver
and include SoftwareSerial library. The format is SoftwareSerial mySerial (Rx, Tx).
In this code, pin9 of Arduino is the Rx and pin10 of Arduino is the Tx.
The first step is to set baud rate of SoftwareSerial library to communicate
with the GSM module. This is achieved by the command mySerial.begin func-
tion. The second step is to set the baud rate of Arduino IDE’s serial moni-
tor. This is done by the command Serial.begin function. The baud rate is
9600 bits/s is set.
The details of some of the important instructions are as follows:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4);
#define MESSAGE_button 7
#define CALL_button 6
#define END_button 5
String number ="9837043685"; // Add the 10-Digit Mobile Number
Arduino and Wireless Communication 141
void setup()
{
lcd.begin(20, 4);
Serial.begin(9600);
mySerial.begin(9600);
pinMode(MESSAGE_button,INPUT_PULLUP);
pinMode(CALL_button,INPUT_PULLUP);
pinMode(END_button,INPUT_PULLUP);
//digitalWrite(msg_key,HIGH);
//digitalWrite(call_key,HIGH);
//digitalWrite(end_key,HIGH);
lcd.setCursor(0, 0);
lcd.print("GSM MESSAGE ");
lcd.setCursor(0, 1);
lcd.print("sending system.... ");
delay(1000);
}
void loop()
{
//Sends an sms everytime msg_key is pressed
if (digitalRead(MESSAGE_button)==LOW) // Check if the
sms key is being pressed
{
lcd.clear();
mySerial.println("AT+CMGF=1"); // Set the Mode as Text Mode
lcd.setCursor(0, 2);
lcd.print("AT+CMGF=1");
delay(150);
mySerial.println("AT+CMGS=\"+919837043685\"\r");
// Specify the Destination number in
international format by replacing the 0's
lcd.setCursor(0, 2);
lcd.print("AT+CMGS=\"+919837043685\"\r");
delay(150);
mySerial.print("message Send"); // Enter the message
lcd.setCursor(0, 2);
lcd.print("message Send");
delay(150);
mySerial.write((byte)0x1A); // End of message character
0x1A : Equivalent to Ctrl+z
lcd.setCursor(0, 2);
lcd.print("cntrl+Z");
delay(50);
mySerial.println();
}
//Makes a call when call_key is pressed
else if (digitalRead(CALL_button)==LOW) // Check if the call
key is being pressed
{
lcd.clear();
142 Arduino-Based Embedded Systems
lcd.setCursor(0, 2);
lcd.print("ATD+91"+number+";");
mySerial.println("ATD+91"+number+";"); //Specify the
number to call
while(digitalRead(CALL_button)==LOW);
delay(50);
}
//Hang the call
else if (digitalRead(END_button)==LOW) // Check if the hang
up key is being pressed
{
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("ATH");
mySerial.println("ATH");
while(digitalRead(END_button)==LOW);
delay(50);
}
}
FIGURE 10.9
Proteus simulation model.
Section IV
Projects
11
2.4 GHz RF Modem-Based Security
System for Restricted Area
11.1 Introduction
This project is designed for monitoring the security of the restricted areas.
The system is designed in two sections: (1) sensor node and (2) server. It is
designed in such a way that it will sense any intrusion with the help of a
passive infrared (PIR) sensor at the sensor node and communicated to the
server wirelessly with a 2.4 GHz RF modem. At the server, a LabVIEW GUI
is created to observe the system. Figure 11.1 shows the block diagram of the
system.
Power supply
PIR 12 V/1 A
sensor
FIGURE 11.1
Block diagram for the system.
145
146 Arduino-Based Embedded Systems
TABLE 11.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 11.2
Components List for a Receiver Section
Component/Specification Quantity
TRANSMITTER SECTION
Arduino and PIR sensor
• Arduino GND-Sensor GND
• Arduino +5 V-sensor +Vcc
• Arduino A0 pin-data out pin of sensor
2.4 GHz RF Modem-Based Security System for Restricted Area 147
RECEIVER SECTION
Arduino and RF modem
• Arduino pin0(Tx)-RX pin of RF modem
• Arduino pin0(RX)-Tx pin of RF modem
• Arduino+5 V-+Vcc of RF modem
• Arduino Ground-GND of RF modem
Circuit diagram.
FIGURE 11.2
2.4 GHz RF Modem-Based Security System for Restricted Area 149
11.3 Program
11.3.1 Transmitter Section
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int PIR_sensor_PIN = 10;
int PIR_sensor_PIN_state=0;
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
pinMode(PIR_sensor_PIN, INPUT);
lcd.setCursor(0,0);
lcd.print("SECURITY SYSTEM");
lcd.setCursor(0,1);
lcd.print("OF RESTRICTED AREA");
}
if(PIR_sensor_PIN_state == HIGH)
{
lcd.clear();
int PIR_SERIAL_BYTE=10;
Serial.write(PIR_SERIAL_BYTE);
lcd.setCursor(0,1);
lcd.print("SECURITY BREAK");
delay(50);
}
else
{
lcd.clear();
int PIR_SERIAL_BYTE=20;
Serial.write(PIR_SERIAL_BYTE);
lcd.setCursor(0,1);
lcd.print("SYSTEM SECURED");
delay(50);
}
}
150 Arduino-Based Embedded Systems
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("SECURITY SYSTEM");
lcd.setCursor(0,1);
lcd.print("OF RESTRICTED AREA");
}
if(PIR_sensor_SERIAL_BYTE == 10)
{
lcd.clear();
Serial.print("PIRSENSOR:");
Serial.println(PIR_sensor_SERIAL_BYTE);
lcd.setCursor(0,1);
lcd.print("SECURITY BREAK");
delay(50);
}
else if(PIR_sensor_SERIAL_BYTE == 20)
{
lcd.clear();
Serial.print("PIRSENSOR:");
Serial.println(PIR_sensor_SERIAL_BYTE);
lcd.setCursor(0,1);
lcd.print("SYSTEM SECURED");
delay(50);
}
}
2.4 GHz RF Modem-Based Security System for Restricted Area 151
FIGURE 11.3
Proteus simulation model showing “system secured.”
152 Arduino-Based Embedded Systems
FIGURE 11.4
Proteus simulation model showing “security break.”
FIGURE 11.5
Front panel showing “security break.”
FIGURE 11.6
Front panel showing “system secured.”
154
FIGURE 11.7
LabVIEW GUI block diagram for the system.
Arduino-Based Embedded Systems
12
Campus Fire Monitoring System
with a 2.4 GHz RF Modem
12.1 Introduction
The objective of this project is to design a monitoring system for the fire alerts
in the campus. The system is designed in two sections: (1) transmitter sec-
tion and (2) receiver section, in such a way that it will sense the fire in the
surroundings with the help of a fire sensor at the transmitter section and
communicated to the receiver section wirelessly with a 2.4 GHz RF modem.
At the receiver end, a LabVIEW GUI is created to observe the system.
Figure 12.1 shows the block diagram of the system.
To design the system, following components are required (Tables 12.1
and 12.2).
FIGURE 12.1
Block diagram for the system.
155
156 Arduino-Based Embedded Systems
TABLE 12.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 12.2
Components List for a Receiver Section
Component/Specification Quantity
Figure 12.2 shows the circuit diagram for the system, connecting all the
components as per connections.
158 Arduino-Based Embedded Systems
FIGURE 12.2
Circuit diagram.
12.3 Program
12.3.1 Transmitter Section
const int FLAME_SENSOR_PIN = 8;
int FLAME_SENSOR_state=0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
pinMode(FLAME_SENSOR_PIN, INPUT);
lcd.setCursor(0,0);
lcd.print("FLAME DETECTION");
lcd.setCursor(0,1);
lcd.print("SYSTENM AT UPES");
delay(1000);
}
Campus Fire Monitoring System with a 2.4 GHz RF Modem 159
void loop()
{
FLAME_SENSOR_state = digitalRead(FLAME_SENSOR_PIN);
if(FLAME_SENSOR_state== HIGH)
{
lcd.clear();
int FLAME_SENSOR_serial_data=10;
Serial.write(FLAME_SENSOR_serial_data);
lcd.setCursor(0,1);
lcd.print("FLAME DETECTED");
delay(50);
}
else
{
lcd.clear();
int FLAME_SENSOR_serial_data=20;
Serial.write(FLAME_SENSOR_serial_data);
lcd.setCursor(0,1);
lcd.print("NO FLAME");
delay(50);
}
}
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("FLAME DETECTION");
lcd.setCursor(0,1);
lcd.print("SYSTENM AT UPES");
delay(1000);
}
void loop()
{
int FLAME_SENSOR_serial_data= Serial.read();;
if(FLAME_SENSOR_serial_data == 10)
{
lcd.clear();
Serial.print("FLAMESENSOR:");
160 Arduino-Based Embedded Systems
Serial.println(FLAME_SENSOR_serial_data);
lcd.setCursor(0,0);
lcd.print("FLAME DETECTED");
delay(50);
}
else if(FLAME_SENSOR_serial_data == 20)
{
lcd.clear();
Serial.print("FLAMESENSOR:");
Serial.println(FLAME_SENSOR_serial_data);
lcd.setCursor(0,1);
lcd.print("NO FLAME");
delay(50);
}
FIGURE 12.3
Proteus simulation model for the system showing “NO FLAME.”
Campus Fire Monitoring System with a 2.4 GHz RF Modem 161
FIGURE 12.4
Proteus simulation model for the system showing “FLAME DETECTED.”
FIGURE 12.5
Front panel showing “FIRE DETECTED.”
FIGURE 12.6
Front panel showing “NO FIRE DETECTED.”
Campus Fire Monitoring System with a 2.4 GHz RF Modem 163
13.1 Introduction
This project is about to design the light-dependent resistor-based room light
intensity control system. The system is designed in two sections: (1) transmitter
section and (2) receiver section. At the transmitter, light-dependent resistor
(LDR) is connected to the Arduino to sense the intensity of the surroundings.
The level of intensity is sensed and transmitted to the receiver section to
control the intensity at the required level. The receiver section comprises the
Arduino Uno, LCD, RF modem, dimmer, and load (bulb). The load can be
controlled in 4, 8, or 16 levels. At the server, a LabVIEW GUI is created to
observe the system. Figure 13.1 shows the block diagram of the system.
LDR Power
Dimmer
supply
12 V/1 A
Load
FIGURE 13.1
Block diagram for the system.
165
166 Arduino-Based Embedded Systems
TABLE 13.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 13.2
Components List for a Receiver Section
Component/Specification Quantity
FIGURE 13.2
Circuit diagram for the system.
13.3 Program
13.3.1 Transmitter Section
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Light-Dependent Resistor-Based Light Intensity Control System 169
#define LDR_SENSOR_PIN A0
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print( "LDR BASED LIGHT");
lcd.setCursor(0,1);
lcd.print( "Intensity control ");
lcd.setCursor(0,2);
lcd.print( "system AT SME ");
delay(1000);
}
void loop()
{
int LDR_sensor_BYTE_LEVEL = analogRead(LDR_SENSOR_PIN);
int LDR_sensor_BYTE=LDR_sensor_BYTE_LEVEL/100;
lcd.setCursor(0,3);
lcd.print("LDR LEVEL:");
lcd.setCursor(11,3);
lcd.print(LDR_sensor_BYTE);
Serial.write(LDR_sensor_BYTE);
delay(100);
}
void loop()
{
int LDR_sensor_BYTE=Serial.read();
Serial.print("LDRSENSOR:");
Serial.println(LDR_sensor_BYTE);
lcd.setCursor(0,3);
lcd.print("LDR LEVEL:");
lcd.setCursor(11,3);
lcd.print(LDR_sensor_BYTE);
if(LDR_sensor_BYTE<=20)
{
digitalWrite(DIMMER_PIN_A,LOW);
digitalWrite(DIMMER_PIN_B,LOW);
digitalWrite(DIMMER_PIN_C,LOW);
digitalWrite(DIMMER_PIN_D,HIGH);
}
if(LDR_sensor_BYTE>=30)
{
digitalWrite(DIMMER_PIN_A,LOW);
digitalWrite(DIMMER_PIN_B,LOW);
digitalWrite(DIMMER_PIN_C,HIGH);
digitalWrite(DIMMER_PIN_D,LOW);
}
delay(100);
}
FIGURE 13.3
Proteus simulation model for the system.
FIGURE 13.4
Front panel for the system.
FIGURE 13.5
LabVIEW GUI block diagram for the system.
14
DC Motor Control System
with LabVIEW GUI
14.1 Introduction
This project is designed to control DC motor with the LabVIEW GUI. It can
be used in the applications such as a wireless control for a robot. The system
is designed in two sections: (1) transmitter section and the (2) receiver sec-
tion. The transmitter section comprises Arduino Uno, power supply, PC (for
LabVIEW), LCD, and the RF modem. In this project, two independent meth-
ods to control a DC motor are discussed. A motor can be controlled with a
switch array as well as with LabVIEW GUI for “clockwise,” “anticlockwise,”
and “stop” to make movement in the forward or reverse direction. Receiver
section comprises the Arduino Uno, power supply, motor driver (L293D),
DC motor, and RF modem. The RF modem is connected to communicate
wirelessly between the two sections and operates at 2.4 GHz frequency.
Figure 14.1 shows the block diagram of the system.
To design the system, following components are required (Tables 14.1
and 14.2).
FIGURE 14.1
Block diagram for the system.
173
174 Arduino-Based Embedded Systems
TABLE 14.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 14.2
Components List for a Receiver Section
Component/Specification Quantity
Circuit diagram.
FIGURE 14.2
178 Arduino-Based Embedded Systems
14.3 Program
14.3.1 Transmitter Section
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
#define BUTTON_MODE_SELECTION 7
#define BUTTON_PIN_FORWARD 6
#define BUTTON_PIN_REVERSE 5
#define BUTTON_PIN_STOP 4
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
pinMode(BUTTON_MODE_SELECTION,INPUT_PULLUP);
pinMode(BUTTON_PIN_FORWARD,INPUT_PULLUP);
pinMode(BUTTON_PIN_REVERSE,INPUT_PULLUP);
pinMode(BUTTON_PIN_STOP,INPUT_PULLUP);
lcd.setCursor(0,0);
lcd.print("DC motor control");
lcd.setCursor(0,1);
lcd.print("+ remote control");
delay(1000);
}
void loop()
{
int
BUTTON_MODE_SELECTION_digital=digitalRead(BUTTON_MODE_
SELECTION);
if (BUTTON_MODE_SELECTION_digital==LOW)
{
char LABVIEW_SERIAL_CHAR;
LABVIEW_SERIAL_CHAR=Serial.read();
if (LABVIEW_SERIAL_CHAR=='W')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("CLOSEWISE");
Serial.write('W');
else if (LABVIEW_SERIAL_CHAR=='Z')
{
lcd.clear();
DC Motor Control System with LabVIEW GUI 179
lcd.setCursor(0,3);
lcd.print("ANTICLOCKWISE");
Serial.write('Z');
else if (LABVIEW_SERIAL_CHAR=='E')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("STOP");
Serial.write('E');
}
delay(10);
}
else if(BUTTON_MODE_SELECTION_digital==HIGH)
{
int
BUTTON_PIN_FORWARD_digital=digitalRead (BUTTON_PIN_FORWARD);
int BUTTON_PIN_REVERSE_digital=digitalRead
(BUTTON_PIN_REVERSE);
int BUTTON_PIN_STOP_digital=digitalRead (BUTTON_PIN_STOP);
if (BUTTON_PIN_FORWARD_digital==LOW)
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("CLOSEWISE");
Serial.write('W');
}
if(BUTTON_PIN_REVERSE_digital==LOW)
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("ANTICLOCKWISE");
Serial.write('Z');
}
if(BUTTON_PIN_STOP_digital==LOW)
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("STOP");
Serial.write('E');
}
}
180 Arduino-Based Embedded Systems
void setup()
{
Serial.begin(9600);
lcd.begin(20,4);
pinMode(DC_MOTOR1_POSITIVE, OUTPUT);
pinMode(DC_MOTOR1_NEGATIVE, OUTPUT);
lcd.setCursor(0,0);
lcd.print("DC motor control");
lcd.setCursor(0,1);
lcd.print("+ remote control");
delay(1000);
}
void loop()
{
char LABVIEW_SERIAL_CHAR;
LABVIEW_SERIAL_CHAR=Serial.read();
if (LABVIEW_SERIAL_CHAR=='W')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("CLOCKWISE");
digitalWrite(DC_MOTOR1_POSITIVE, HIGH);
digitalWrite(DC_MOTOR1_NEGATIVE, LOW);
}
DC Motor Control System with LabVIEW GUI 181
else if (LABVIEW_SERIAL_CHAR=='Z')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("ANTICLOCKWISE");
digitalWrite(DC_MOTOR1_POSITIVE, LOW);
digitalWrite(DC_MOTOR1_NEGATIVE, HIGH);
}
else if (LABVIEW_SERIAL_CHAR=='E')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("STOP");
digitalWrite(DC_MOTOR1_POSITIVE, LOW);
digitalWrite(DC_MOTOR1_NEGATIVE, LOW);
delay(10);
}
FIGURE 14.3
Proteus simulation model showing the motor moving in “CLOCKWISE” direction.
Arduino-Based Embedded Systems
DC Motor Control System with LabVIEW GUI 183
FIGURE 14.4
Front panel showing that the motor is controlled in “FORWARD” direction.
FIGURE 14.5
Front panel showing that the motor is controlled in “REVERSE” direction.
184
FIGURE 14.6
LabVIEW GUI block diagram for the system.
Arduino-Based Embedded Systems
15
Stepper Motor Control System
with LabVIEW GUI
15.1 Introduction
This project is designed to control the stepper motor. The system is designed
to operate with the help of LabVIEW GUI. It comprises of two sections:
(1) transmitter section and (2) receiver section. Transmitter section comprises
the Arduino Uno, power supply, PC (for LabVIEW), LCD, and the RF modem.
Motor is controlled with LabVIEW GUI. Receiver section comprises the
Arduino Uno, power supply, motor driver (L293D), stepper motor, and the
RF modem. The RF modem is connected to communicate wirelessly between
the two sections and operates at 2.4 GHz frequency. Figure 15.1 shows the
block diagram of the system.
Power
supply Power
12 V/1 A supply
12 V/1 A
FIGURE 15.1
Block diagram for the system.
185
186 Arduino-Based Embedded Systems
TABLE 15.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 15.2
Components List for a Receiver Section
Component/Specification Quantity
Figure 15.2 shows the circuit diagram for the system, connecting all the com-
ponents as per connections.
Stepper Motor Control System with LabVIEW GUI 189
Circuit diagram.
FIGURE 15.2
190 Arduino-Based Embedded Systems
15.3 Program
15.3.1 Transmitter Section
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("DC motor control");
lcd.setCursor(0,1);
lcd.print("+ remote control");
delay(1000);
}
void loop()
{
char LABVIEW_SERIAL_CHAR;
LABVIEW_SERIAL_CHAR=Serial.read();
if (LABVIEW_SERIAL_CHAR=='W')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("4 STEP SYSTEM");
Serial.write('W');
}
else if (LABVIEW_SERIAL_CHAR=='Z')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("8 STEP SYSTEM");
Serial.write('Z');
else if (LABVIEW_SERIAL_CHAR=='E')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("STOP");
Serial.write('E');
}
delay(10);
}
Stepper Motor Control System with LabVIEW GUI 191
void loop()
{
char LABVIEW_SERIAL_CHAR;
LABVIEW_SERIAL_CHAR=Serial.read();
if (LABVIEW_SERIAL_CHAR=='W')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("4 STEP SYSTEM");
digitalWrite(STEPPER_MOTOR_PHASE_A, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_C, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
192 Arduino-Based Embedded Systems
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D, HIGH);
}
else if (LABVIEW_SERIAL_CHAR=='Z')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("Motor Reverse");
digitalWrite(STEPPER_MOTOR_PHASE_A, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_B, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_C, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_C, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_C, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_D, HIGH);
delay(20);
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D,HIGH);
delay(20);
Stepper Motor Control System with LabVIEW GUI 193
digitalWrite(STEPPER_MOTOR_PHASE_A, HIGH);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D, HIGH);
else if (LABVIEW_SERIAL_CHAR=='E')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("STOP");
digitalWrite(STEPPER_MOTOR_PHASE_A, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_B, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_C, LOW);
digitalWrite(STEPPER_MOTOR_PHASE_D, LOW);
}
delay(10);
}
FIGURE 15.3
Proteus simulation model to control stepper motor.
Arduino-Based Embedded Systems
Stepper Motor Control System with LabVIEW GUI 195
FIGURE 15.4
Front panel showing that the motor is controlled in the “REVERSE” direction.
196 Arduino-Based Embedded Systems
FIGURE 15.5
Front panel showing that the motor is controlled in the “FORWARD” direction.
FIGURE 15.6
LabVIEW GUI block diagram for the system.
16
Accelerometer-Based Laboratory
Automation System
16.1 Introduction
This project is to design an accelerometer-based laboratory automation
system. The system is designed in two sections: (1) transmitter section and
(2) receiver section. The transmitter section comprises the Arduino Nano,
power supply, PC (for LabVIEW), Accelerometer, LCD, and the RF modem.
The receiver section comprises the Arduino Nano, power supply, relay,
load, and the RF modem. The RF modem is connected to communicate
wirelessly between the two sections and operates at 2.4 GHz frequency.
Load is made “ON” or “OFF” through relays. For the experiment, two load
bulbs and fan are considered to operate. Figure 16.1 shows the block dia-
gram of the system.
Relay 1 Load 1
Power
Arduino RF RF Arduino
supply
Nano modem modem Nano
12 V/1 A
Relay 2 Load 2
Power
Accelerometer
supply
12 V/1 A
FIGURE 16.1
Block diagram for the system.
197
198 Arduino-Based Embedded Systems
TABLE 16.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 16.2
Components List for a Receiver Section
Component/Specification Quantity
Circuit diagram.
FIGURE 16.2
202 Arduino-Based Embedded Systems
16.3 Program
16.3.1 Transmitter Section
#include <LiquidCrystal.h>
int ACCELARATION_X_AXIS=A0;
int ACCELARATION_Y_AXIS=A1;
void setup()
{
Serial.begin(9600);// initialize serial communication
lcd.begin(20,4); // initialize LCD
lcd.setCursor(0,0);// choose Column and ROW of LCD
lcd.print("ACCELAROMETER BASED");//Print string on LCD
lcd.setCursor(0,1);// choose Column and ROW of LCD
lcd.print("AUTOMATION SYSTEM");// Print string on LCD
delay(1000);// delay of 1000mSec
}
void loop()
{
int ACCELARATION_X_AXIS_LEVEL=analogRead(ACCELARATION_X_
AXIS);//read the level of sensor
int ACCELARATION_Y_AXIS_LEVEL=analogRead(ACCELARATION_Y_
AXIS); //read the level of sensor
int ACCELARATION_X_AXIS_BYTE=ACCELARATION_X_AXIS_LEVEL/10;
//scale the level by 10
int ACCELARATION_Y_AXIS_BYTE=ACCELARATION_Y_AXIS_LEVEL/10;
//scale the level by 10
void loop()
{
if (a==1)
{
Serial.println(inputString);// serial print
lcd.setCursor(0,2);// set cursor
lcd.print(inputString[0]);// print byte on LCD
lcd.print(inputString[1]);// print byte on LCD
lcd.print(inputString[2]);// print byte on LCD
lcd.print(inputString[3]);// print byte on LCD
lcd.print(inputString[4]);// print byte on LCD
lcd.print(inputString[5]);// print byte on LCD
lcd.print(inputString[6]);// print byte on LCD
lcd.print(inputString[7]);// print byte on LCD
lcd.setCursor(0,3);// set cursor
lcd.print(inputString[8]);// print byte on LCD
lcd.print(inputString[9]);// print byte on LCD
lcd.print(inputString[10]);// print byte on LCD
lcd.print(inputString[11]);// print byte on LCD
lcd.print(inputString[12]);// print byte on LCD
lcd.print(inputString[13]);// print byte on LCD
lcd.print(inputString[14]);// print byte on LCD
lcd.print(inputString[15]);// print byte on LCD
if((inputString[6]>='4')&&(inputString[7]>='0'))
204 Arduino-Based Embedded Systems
{
digitalWrite(RELAY1,HIGH);// set pin6 high
digitalWrite(RELAY2,LOW);//set pin6 high
delay(20);// delay 20mSec
}
if((inputString[14]>='5')&&(inputString[15]>='0'))
{
digitalWrite(RELAY2,HIGH);// set pin6 high
digitalWrite(RELAY1,LOW);// set pin6 low
delay(20);// delay 20mSec
}
if(inputString[0]==0x0A)
{
lcd.setCursor(0,2);// set cursor
lcd.print(inputString[1]);// print byte on LCD
lcd.print(inputString[2]); // print byte on LCD
lcd.print(inputString[3]); // print byte on LCD
lcd.print(inputString[4]); // print byte on LCD
lcd.print(inputString[5]); // print byte on LCD
lcd.print(inputString[6]); // print byte on LCD
lcd.print(inputString[7]); // print byte on LCD
lcd.print(inputString[8]); // print byte on LCD
lcd.setCursor(0,3);// set cursor
lcd.print(inputString[9]); // print byte on LCD
lcd.print(inputString[10]); // print byte on LCD
lcd.print(inputString[11]); // print byte on LCD
lcd.print(inputString[12]); // print byte on LCD
lcd.print(inputString[13]); // print byte on LCD
lcd.print(inputString[14]); // print byte on LCD
lcd.print(inputString[15]); // print byte on LCD
lcd.print(inputString[16]); // print byte on LCD
if((inputString[7]>='4')&&(inputString[8]>='0'))
{
digitalWrite(RELAY1,HIGH);// set pin 6 high
digitalWrite(RELAY2,LOW);//set pin 5 low
delay(20);
}
if((inputString[15]>='5')&&(inputString[16]>='0'))
{
digitalWrite(RELAY2,HIGH);// set pin 5 high
digitalWrite(RELAY1,LOW);// set pin 6 low
delay(20);// delay 20mSec
}
}
inputString = "";// clear the string
a=0;// set a variable 0
}
}
Accelerometer-Based Laboratory Automation System 205
void serialEvent()
{
while (Serial.available())// cheack serial
{
char inChar = (char)Serial.read(); // read serial
inputString += inChar;// store byte in string
if (inChar == 0x0D)
{
a=1;// set a=1
}
}
}
FIGURE 16.3
Proteus simulation model for the system.
Arduino-Based Embedded Systems
17
Temperature Monitoring
System Using RF Modem
17.1 Introduction
The project is about to design the temperature monitoring system using a
RF modem. The system is designed in two sections: (1) transmitter section
and (2) receiver section. Transmitter section comprises Arduino Uno, power
supply, temperature sensor, LCD, and a RF modem. The receiver section
comprises Arduino Uno, power supply, PC (LabVIEW), and RF modem.
LabVIEW GUI is created to monitor the system. Figure 17.1 shows the block
diagram of the system.
To design the system, following components are required (Tables 17.1
and 17.2).
Power Arduino RF
supply RF Arduino To
Uno modem modem Uno LabVIEW
12 V/1 A
Power
Temperature supply
sensor 12 V/1 A
FIGURE 17.1
Block diagram of the system.
207
208 Arduino-Based Embedded Systems
TABLE 17.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 17.2
Components List for a Receiver Section
Component/Specification Quantity
A circuit diagram.
FIGURE 17.2
Temperature Monitoring System Using RF Modem 211
17.3 Program
17.3.1 Transmitter Section
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("Room temperature");
lcd.setCursor(0,1);
lcd.print("control System");
delay(1000);
}
void loop()
{
int TEMP_sensor_BYTE_LEVEL = analogRead(A0);
int TEMP_sensor_BYTE=TEMP_sensor_BYTE_LEVEL/2;
lcd.setCursor(0,2);
lcd.print("Temperature 0C:");
lcd.setCursor(0,3);
lcd.print(TEMP_sensor_BYTE);
Serial.write(TEMP_sensor_BYTE);
delay(100);
}
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("Room temperature");
lcd.setCursor(0,1);
lcd.print("control System");
delay(1000);
}
212 Arduino-Based Embedded Systems
void loop()
{
int TEMP_sensor_BYTE=Serial.read();
Serial.print("TEMPERATURESENSOR:");
Serial.println(TEMP_sensor_BYTE);
lcd.setCursor(0,2);
lcd.print("Temperature 0C:");
lcd.setCursor(0,3);
lcd.print(TEMP_sensor_BYTE);
delay(100);
}
FIGURE 17.3
A Proteus simulation model.
Temperature Monitoring System Using RF Modem 213
FIGURE 17.4
Front panel showing “Temperature 28°C.”
214 Arduino-Based Embedded Systems
FIGURE 17.5
Front panel showing “Temperature 20°C.”
FIGURE 17.6
LabVIEW GUI block diagram for the system.
18
Emergency Hooter in the Case of a Disaster
18.1 Introduction
This project is about to generate an emergency alert in the case of a disas-
ter. The system is designed in two sections: a sensor node and (2) a server.
The sensor node comprises the Arduino Uno, power supply, soil moisture
sensor, relay, hooter, LCD, and the RF modem. The relay is used to make
the hooter “ON” or “OFF.” The server comprises the Arduino Uno, power
supply, switch array, PC (LabVIEW), and the RF modem. The switch array is
attached to generate an emergency signal at the server and is sent to the sen-
sor node. Figure 18.1 shows the block diagram of the system.
To
Power LabVIEW
supply
12 V/1 A Arduino RF RF Arduino
Uno modem modem Uno
Relay Switch
array
Soil Power
Hooter moisture supply
sensor 12 V/1 A
FIGURE 18.1
A block diagram of the system.
215
216 Arduino-Based Embedded Systems
TABLE 18.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 18.2
Components List for a Receiver Section
Component/Specification Quantity
18.2.2 Server
Arduino and RF modem
• Arduino pin0(TX)-RX pin of RF modem
• Arduino pin0(RX)-Tx pin of RF modem
• Arduino+5 V-+Vcc of RF modem
• Arduino Ground-GND of RF modem
A circuit diagram.
FIGURE 18.2
220 Arduino-Based Embedded Systems
18.3 Program
18.3.1 Sensor Node
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
#define BUTTON_MODE_SELECTION 7
#define BUTTON_PIN_HOOTERON 6
#define BUTTON_PIN_HOOTEROFF 5
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is
complete
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
pinMode(BUTTON_MODE_SELECTION,INPUT_PULLUP);
pinMode(BUTTON_PIN_HOOTERON,INPUT_PULLUP);
pinMode(BUTTON_PIN_HOOTEROFF,INPUT_PULLUP);
inputString.reserve(200);
lcd.setCursor(0,0);
lcd.print("Hooter control");
lcd.setCursor(0,1);
lcd.print("system in diste");
delay(1000);
}
void loop()
{
int BUTTON_MODE_SELECTION_digital=digitalRead
(BUTTON_MODE_SELECTION);
if (BUTTON_MODE_SELECTION_digital==LOW)
{
Serial.println(30);
if (stringComplete)
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print(inputString);
delay(10);
inputString = "";
stringComplete = false;
}
}
Emergency Hooter in the Case of a Disaster 221
else if(BUTTON_MODE_SELECTION_digital==HIGH)
{
int BUTTON_PIN_HOOTERON_digital= digitalRead
(BUTTON_PIN_HOOTERON);
int BUTTON_PIN_HOOTEROFF_digital= digitalRead
(BUTTON_PIN_HOOTEROFF);
if(BUTTON_PIN_HOOTERON_digital==LOW)
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("HOOTER ON");
Serial.println(10);
}
if(BUTTON_PIN_HOOTEROFF_digital==LOW)
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("HOOTER OFF");
Serial.println(20);
}
}
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString += inChar;
if(inChar == 0x0D)
{
stringComplete = true;
}
}
}
18.3.2 Server
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define HOOTER_RELAY 7
#define SM_SENSOR A0
String inputString = ""; // a string to hold
incoming data
boolean stringComplete = false; // whether the string
is complete
222 Arduino-Based Embedded Systems
void setup()
{
Serial.begin(9600);
lcd.begin(20,4);
pinMode(HOOTER_RELAY, OUTPUT);
inputString.reserve(200);
lcd.setCursor(0,0);
lcd.print("Hooter control");
lcd.setCursor(0,1);
lcd.print("system in dister");
delay(1000);
}
void loop()
{
if(stringComplete)
{
lcd.clear();
delay(10);
if((inputString[0]=='1')&&(inputString[1]=='0')
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("HOOTER ON");
digitalWrite(HOOTER_RELAY, HIGH);
delay(20);
}
else if ((inputString[0]=='2')&&
(inputString[1]=='0'))
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("HOOTER OFF");
digitalWrite(HOOTER_RELAY, LOW);
delay(20);
}
else if ((inputString[0]=='3')&&
(inputString[1]=='0'))
{
int ANALOG_READ_SM_SENSOR_ LEVEL=analogRead
(SM_SENSOR);
int ANALOG_READ_SM_SENSOR_ PPM=ANALOG_READ_
SM_SENSOR_LEVEL/10;
lcd.setCursor(0,3);
lcd.print("SMSENSOR:");
lcd.print(ANALOG_READ_SM_ SENSOR_PPM);
Serial.print("SMSENSOR:");
Serial.println(ANALOG_READ_ SM_SENSOR_PPM);
Emergency Hooter in the Case of a Disaster 223
delay(20);
}
if((inputString[0]==0x0A))
{
if ((inputString[1]=='1')&& (inputString[2]
=='0'))
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("HOOTER ON");
digitalWrite(HOOTER_RELAY, HIGH);
delay(20);
}
else if ((inputString[1]=='2')&&(inputString[2]
=='0'))
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("HOOTER OFF");
digitalWrite(HOOTER_RELAY, LOW);
delay(20);
}
else if ((inputString[1]=='3') &&
(inputString[2]=='0'))
{
int ANALOG_READ_SM_SENSOR_LEVEL=analogRead
(SM_SENSOR);
int ANALOG_READ_SM_SENSOR_PPM=ANALOG_READ_
SM_SENSOR_ LEVEL/10;
lcd.setCursor(0,3);
lcd.print("SMSENSOR:");
lcd.print(ANALOG_READ_SM_SENSOR_PPM);
Serial.print("SMSENSOR:");
Serial.println(ANALOG_READ_SM_SENSOR_PPM);
delay(20);
}
inputString = "";
stringComplete = false;
}
224 Arduino-Based Embedded Systems
delay(10);
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == 0x0D)
{
stringComplete = true;
}
}
}
FIGURE 18.3
A Proteus simulation model showing the soil moisture content.
Emergency Hooter in the Case of a Disaster 225
FIGURE 18.4
A Proteus simulation model showing hooter “ON.”
FIGURE 18.5
A Proteus simulation model showing hooter “OFF.”
226 Arduino-Based Embedded Systems
FIGURE 18.6
Front panel for the LabVIEW GUI.
Emergency Hooter in the Case of a Disaster 227
FIGURE 18.7
LabVIEW GUI block diagram for the system.
19
LabVIEW GUI-Based Wireless
Robot Control System
19.1 Introduction
This chapter explains a project titled “LabVIEW GUI-based robot control
system.” The system is designed in two sections: (1) transmitter section
and (2) receiver section. The transmitter section comprises the Arduino
Uno, power supply, PC (LabVIEW), LCD, and the RF modem. The receiver
section comprises the Arduino Uno, power supply, LCD, DC motor, and RF
modem. In this project, two independent methods to control a DC motor
are discussed. A motor can be controlled with a switch array as well as with
LabVIEW GUI for “clockwise,” “anticlockwise,” and “stop” to make move-
ment in the forward or reverse direction. The receiver section comprises
the Arduino Uno, power supply, motor driver (L293D), DC motor, and RF
modem. A chassis is used to make the robot body. A free wheel is connected
in the front side of the robot with two DC motor at the back sides. Figure 19.1
shows the block diagram of the system.
Switch Power
array supply
12 V/1 A
FIGURE 19.1
Block diagram of the Robot.
229
230 Arduino-Based Embedded Systems
TABLE 19.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 19.2
Components List for a Receiver Section
Component/Specification Quantity
Figure 19.2 shows the circuit diagram for the system, connecting all the com-
ponents as per connections.
LabVIEW GUI-Based Wireless Robot Control System 233
A circuit diagram.
FIGURE 19.2
234 Arduino-Based Embedded Systems
19.3 Program
19.3.1 Transmitter Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("DC motor control");
lcd.setCursor(0,1);
lcd.print("+ remote control");
delay(1000);
}
void loop()
{
char LABVIEW_SERIAL_CHAR;
LABVIEW_SERIAL_CHAR=Serial.read();
if(LABVIEW_SERIAL_CHAR=='W')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("Motor Forward");
Serial.write('W');
}
else if (LABVIEW_SERIAL_CHAR=='Z')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("Motor Reverse");
Serial.write('Z');
}
else if (LABVIEW_SERIAL_CHAR=='X')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("Motor Left");
Serial.write('X');
}
else if (LABVIEW_SERIAL_CHAR=='Y')
LabVIEW GUI-Based Wireless Robot Control System 235
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("Motor Right");
Serial.write('Y');
}
else if (LABVIEW_SERIAL_CHAR=='E')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("STOP");
Serial.write('E');
}
delay(10);
}
void loop()
{
char LABVIEW_SERIAL_CHAR;
LABVIEW_SERIAL_CHAR=Serial.read();
if(LABVIEW_SERIAL_CHAR=='W')
{
lcd.clear();
lcd.setCursor(0,3);
236 Arduino-Based Embedded Systems
lcd.print("Motor Forward");
digitalWrite(DC_MOTOR1_POSITIVE, HIGH);
digitalWrite(DC_MOTOR1_NEGATIVE, LOW);
digitalWrite(DC_MOTOR2_POSITIVE, HIGH);
digitalWrite(DC_MOTOR2_NEGATIVE, LOW);
}
else if (LABVIEW_SERIAL_CHAR=='Z')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("Motor Reverse");
digitalWrite(DC_MOTOR1_POSITIVE, LOW);
digitalWrite(DC_MOTOR1_NEGATIVE, HIGH);
digitalWrite(DC_MOTOR2_POSITIVE, LOW);
digitalWrite(DC_MOTOR2_NEGATIVE, HIGH);
}
else if (LABVIEW_SERIAL_CHAR=='X')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("Motor Left");
digitalWrite(DC_MOTOR1_POSITIVE, HIGH);
digitalWrite(DC_MOTOR1_NEGATIVE, LOW);
digitalWrite(DC_MOTOR2_POSITIVE, LOW);
digitalWrite(DC_MOTOR2_NEGATIVE, LOW);
}
else if (LABVIEW_SERIAL_CHAR=='Y')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("Motor Right");
digitalWrite(DC_MOTOR1_POSITIVE, LOW);
digitalWrite(DC_MOTOR1_NEGATIVE, LOW);
digitalWrite(DC_MOTOR2_POSITIVE, HIGH);
digitalWrite(DC_MOTOR2_NEGATIVE, LOW);
}
else if (LABVIEW_SERIAL_CHAR=='E')
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print("STOP");
digitalWrite(DC_MOTOR2_POSITIVE, LOW);
digitalWrite(DC_MOTOR1_NEGATIVE, LOW);
digitalWrite(DC_MOTOR2_POSITIVE, LOW);
digitalWrite(DC_MOTOR2_NEGATIVE, LOW);
}
delay(10);
}
LabVIEW GUI-Based Wireless Robot Control System 237
FIGURE 19.3
A Proteus simulation model showing the motor in reverse direction.
238 Arduino-Based Embedded Systems
FIGURE 19.4
Front panel to control the Robot.
FIGURE 19.5
LabVIEW GUI block diagram for the system.
20
Home Automation System Using DTMF
20.1 Introduction
This project is designed to control the home appliances with dual-tone
multi-frequency decoder (DTMF). The system has two sections: (1) receiver
section and (2) remote control (mobile). The system is designed to control
(ON & OFF) four loads through relays. The receiver section comprises
Arduino Nano, power supply, LCD, DTMF decoder, mobile phone, and the
head phone with a 3 mm jack. Another mobile phone is used as a remote
control. Figure 20.1 shows the block diagram of the system.
To design the system, following components are required (Table 20.1).
Liquid crystal
display
(LCD)
Relay 1 Load 1
Relay 2 Load 2
Power
Arduino
supply Relay 3 Load 3
Nano
12 V/1 A
GSM
Relay 4 Load 4
network
DTMF Head
decoder Mobile phone 1 phone Mobile phone 2
with 3 mm
jack
FIGURE 20.1
Block diagram of the system.
239
240 Arduino-Based Embedded Systems
TABLE 20.1
Components List for a Receiver Section
Component/Specification Quantity
FIGURE 20.2
Circuit diagram for the system.
Arduino-Based Embedded Systems
Home Automation System Using DTMF 243
20.3 Program
// include the library code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);// initialize the LCD
Library w.r t. RS,E,D4,D5,D6,D7
int DTMF_LED1_HIGH=6;
int DTMF_LED2_HIGH=5;
int DTMF_LED3_HIGH=4;
int DTMF_LED4_HIGH=3;
int DTMF_LED1_HIGH_READ=0;
int DTMF_LED2_HIGH_READ=0;
int DTMF_LED3_HIGH_READ=0;
int DTMF_LED4_HIGH_READ=0;
int AC_DEVICE_1=2;
int AC_DEVICE_2=1;
int AC_DEVICE_3=0;
int AC_DEVICE_4=13;
void setup()
{
pinMode(DTMF_LED1_HIGH, INPUT);//configure pin6 as an input
and enable the internal pull-up resistor
pinMode(DTMF_LED2_HIGH, INPUT);//configure pin6 as an input
and enable the internal pull-up resistor
pinMode(DTMF_LED3_HIGH, INPUT);//configure pin6 as an input
and enable the internal pull-up resistor
pinMode(DTMF_LED4_HIGH, INPUT);//configure pin6 as an input
and enable the internal pull-up resistor
pinMode(AC_DEVICE_1,OUTPUT);
pinMode(AC_DEVICE_2,OUTPUT);
pinMode(AC_DEVICE_3,OUTPUT);
pinMode(AC_DEVICE_4,OUTPUT);
lcd.begin(20, 4);// set up the LCD's number of columns and
rows
lcd.setCursor(0, 0);// set cursor to column0 and row1
lcd.print("DTMF BASED HOME ");// Print a message to the LCD.
lcd.setCursor(0, 1);// set cursor to column0 and row1
lcd.print("AUTOMATION SYSTEM.......");// Print a message to
the LCD.
delay(1000);
}
244 Arduino-Based Embedded Systems
void loop()
{
if ((DTMF_LED1_HIGH_READ == LOW)&&(DTMF_LED2_HIGH_READ ==
LOW)&&(DTMF_LED3_HIGH_READ == LOW)&&(DTMF_LED4_HIGH_READ ==
HIGH))// Read PIN 6,5,4,3 as HIGH PIN
{
lcd.clear();
lcd.setCursor(0, 2);// set cursor to column0 and row2
lcd.print("NUMBER 1 FROM MOBILE");// Print a message to
the LCD.
digitalWrite(AC_DEVICE_1,HIGH);
digitalWrite(AC_DEVICE_2,LOW);
digitalWrite(AC_DEVICE_3,LOW);
digitalWrite(AC_DEVICE_4,LOW);
lcd.setCursor(0, 3);
lcd.print("AC_DEVICE_1 ON");
delay(20);
}
if ((DTMF_LED1_HIGH_READ == LOW)&&(DTMF_LED2_HIGH_READ ==
LOW)&&(DTMF_LED3_HIGH_READ ==HIGH)&&(DTMF_LED4_HIGH_READ ==
LOW))// Read PIN 6,5,4,3 as HIGH PIN
{
lcd.clear();
lcd.setCursor(0, 2);// set cursor to column0 and row2
lcd.print("NUMBER 2 FROM MOBILE");// Print a message to
the LCD.
digitalWrite(AC_DEVICE_1,LOW);
digitalWrite(AC_DEVICE_2,HIGH);
digitalWrite(AC_DEVICE_3,LOW);
digitalWrite(AC_DEVICE_4,LOW);
lcd.setCursor(0, 3);
lcd.print("AC_DEVICE_2 ON");
delay(20);
}
if ((DTMF_LED1_HIGH_READ == LOW)&&(DTMF_LED2_HIGH_READ ==
LOW)&&(DTMF_LED3_HIGH_READ ==HIGH)&&(DTMF_LED4_HIGH_READ ==
HIGH))// Read PIN 6,5,4,3 as HIGH PIN
Home Automation System Using DTMF 245
{
lcd.clear();
lcd.setCursor(0, 2);// set cursor to column0 and row2
lcd.print("NUMBER 3 FROM MOBILE");// Print a message to the
LCD.
digitalWrite(AC_DEVICE_1,LOW);
digitalWrite(AC_DEVICE_2,LOW);
digitalWrite(AC_DEVICE_3,HIGH);
digitalWrite(AC_DEVICE_4,LOW);
lcd.setCursor(0, 3);
lcd.print("AC_DEVICE_3 ON");
delay(20);
}
if ((DTMF_LED1_HIGH_READ == LOW)&&(DTMF_LED2_HIGH_READ ==
HIGH)&&(DTMF_LED3_HIGH_READ ==LOW)&&(DTMF_LED4_HIGH_READ ==
LOW))// Read PIN 6,5,4,3 as HIGH PIN
{
lcd.clear();
lcd.setCursor(0, 2);// set cursor to column0 and row2
lcd.print("NUMBER 4 FROM MOBILE");// Print a message to
the LCD.
digitalWrite(AC_DEVICE_1,LOW);
digitalWrite(AC_DEVICE_2,LOW);
digitalWrite(AC_DEVICE_3,LOW);
digitalWrite(AC_DEVICE_4,HIGH);
lcd.setCursor(0, 3);
lcd.print("AC_DEVICE_4 ON");
delay(20);
}
if ((DTMF_LED1_HIGH_READ == LOW)&&(DTMF_LED2_HIGH_READ ==
HIGH)&&(DTMF_LED3_HIGH_READ ==LOW)&&(DTMF_LED4_HIGH_READ ==
HIGH))// Read PIN 6,5,4,3 as HIGH PIN
{
lcd.clear();
lcd.setCursor(0, 2);// set cursor to column0 and row2
lcd.print("NUMBER 5 FROM MOBILE");// Print a message to the
LCD.
digitalWrite(AC_DEVICE_1,LOW);
digitalWrite(AC_DEVICE_2,LOW);
digitalWrite(AC_DEVICE_3,LOW);
digitalWrite(AC_DEVICE_4,LOW);
lcd.setCursor(0, 3);
lcd.print("AC_DEVICE OFF");
delay(20);
}
}
246 Arduino-Based Embedded Systems
FIGURE 20.3
Proteus simulation model of the receiver section.
21
RFID Card-Based Attendance System
21.1 Introduction
The objective of this chapter is to develop a RFID card-based attendance
system. Each student will be having a RFID tag with a unique ID, which
will be first identified and then stored in the program. The stored id will
be matched with the RFID tag ID, which will be swiped to the reader to
authenticate the presence of a student. The system comprises Arduino Uno,
power supply, RFID reader, and the RFID tag. It operates on a baud rate of
9600. It can be connected to an RS232, which is compatible to the PC or to the
UART. RFID tag generates a 12 byte unique ID. Figure 21.1 shows the block
diagram of the system.
Liquid crystal
display
(LCD)
Power
supply Arduino RFID
12 V/1 A Uno reader
RFID tag
FIGURE 21.1
Block diagram of the system.
247
248 Arduino-Based Embedded Systems
TABLE 21.1
Components List for a System
Component/Specification Quantity
FIGURE 21.2
Connections to read the RFID reader.
249
250 Arduino-Based Embedded Systems
21.2.2 Connections
To develop the system, connect the components as follows:
Figure 21.3 shows the circuit diagram for the system, connecting all the
components as per connections.
RFID Card-Based Attendance System
FIGURE 21.3
251
21.3 Program
#include<SoftwareSerial.h>
#include <LiquidCrystal.h>
SoftwareSerial mySerial(9,10);
LiquidCrystal lcd(13, 12, 5, 4, 3, 2);
int j=0,k=0;
int read_count=0;
char data_temp, RFID_data[12],x=0;
char Saved_Tags[3][12]={
{'5','0','0','0','9','2','B','E','9','3','E','F'},
//ASCII value of extracted code from RFID card1
{'5','0','0','0','9','2','E','A','2','C','0','4'},
//ASCII value of extracted code from RFID card2
{'5','0','0','0','9','3','2','1','7','F','9','D'}
//ASCII value of extracted code from RFID card3
};
boolean tag_check,tag_status,entry_control;
void setup()
{
lcd.begin(20,4);
mySerial.begin(9600);
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("RFID CARD READER");
lcd.setCursor(0,1);
lcd.print("and data logger");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PUNCH THE CARD ");
}
void loop()
{
RecieveData();
CheckData();
AccessCheck();
}
void RecieveData()
{
if(mySerial.available()>0)
{
data_temp=mySerial.read();
RFID_data[read_count]=data_temp;
RFID Card-Based Attendance System 253
read_count++;
lcd.setCursor(0,2);
lcd.print(RFID_data[read_count]);
Serial.print(RFID_data[read_count]);
}
}
void CheckData()
{
if(read_count==12)
{
entry_control=true;
for(k=0;k<3;k++)
{
for(j=0;j<12;j++)
{
if(Saved_Tags[k][j]==RFID_data[j])
{
tag_check=true;
}
else
{
tag_check=false;
break;
}
}
if(tag_check==true)
{
tag_status=true;
}
}
read_count=0;
}
}
void AccessCheck()
{
if(entry_control==true)
{
if(tag_status==true)
{
x=1;
lcd.setCursor(0,1);
lcd.print("ACCESS GRANTED");
//Serial.println("Access Granted");
}
else
{
254 Arduino-Based Embedded Systems
lcd.setCursor(0,1);
lcd.print("ACCESS DENIED");
lcd.setCursor(0,3);
lcd.print("NOT VERIFIED");
// Serial.println("Access Denied");
}
entry_control=false;
tag_status=false;
}
}
22
Global System for Mobile-Based
Emergency System
22.1 Introduction
This chapter explains the global system for mobile (GSM)-based emergency
alert system in case of fire. The system has two sections: (1) sensor node and
(2) mobile phone (to receive message in case of fire). The sensor node com-
prises Arduino Uno, power supply, fire sensor, LCD, and GSM modem. A fire
sensor is connected to detect fire in the surrounding. If fire happens, the sys-
tem will generate an alert message and that is sent to the registered mobile
number through the GSM modem. Figure 22.1 shows the block diagram of
the system.
Liquid crystal
display
(LCD)
Power Fire
Arduino
supply sensor
Nano
12 V/1 A
GSM
network
GSM
modem
Mobile phone
FIGURE 22.1
Block diagram of the system.
255
256 Arduino-Based Embedded Systems
TABLE 22.1
Components List for a Sensor Node
Component/Specification Quantity
Figure 22.2 shows the circuit diagram for the system, connecting all the com-
ponents as per connections.
258
FIGURE 22.2
A circuit diagram for the system.
Arduino-Based Embedded Systems
Global System for Mobile-Based Emergency System 259
22.3 Program
22.3.1 Program to Write the Message
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8,7);
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4);
#define FIRE_SENSOR_button 5
lcd.setCursor(0, 0);
lcd.print("GSM Based emergency ");
lcd.setCursor(0, 1);
lcd.print("system at UPES.... ");
delay(2000);
}
void loop()
{
int FIRE_STATUS_READ=digitalRead(FIRE_SENSOR_button);
if (digitalRead(FIRE_STATUS_READ)==LOW) // Check if the sms
key is being pressed
{
lcd.clear();
mySerial.println("AT+CMGF=1"); // Set the Mode as Text Mode
lcd.setCursor(0, 2);
lcd.print("AT+CMGF=1");
delay(150);
mySerial.println("AT+CMGS=\"+919837043685\"\r"); // Specify
the Destination number in international format by replacing
the 0's
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("AT+CMGS=\"+919837043685\"\r");
delay(150);
lcd.clear();
mySerial.print("message Send"); // Enter the message
lcd.setCursor(0, 2);
lcd.print("message Send");
260 Arduino-Based Embedded Systems
delay(150);
lcd.clear();
mySerial.write((byte)0x1A); // End of message character
0x1A : Equivalent to Ctrl+z
lcd.setCursor(0, 2);
lcd.print("cntrl+Z");
delay(50);
mySerial.println();
delay(50);
lcd.setCursor(0, 3);
lcd.print("FIRE DETECTED");
delay(5000);
}
else
{
lcd.clear();
lcd.setCursor(0, 3);
lcd.print("NO FIRE");
delay(20);
}
}
}
}
void modem_initialization(void)
{
char rec_data;
byte network_status = 0 ;//network_status initialized as
zero
byte status_check = 0 ;//status_check initialized as zero
byte gsm_cnt = 0;//gsm_cnt initialized as zero
byte ok_flag=0;//ok_flag initialized as zero
byte count=0;//count initialized as zero
clear_rx_buffer();//clearing receiving buffer
while(gsm_cnt < 5)// repeat entire loop until gsm_cnt less
than seven
{
switch(gsm_cnt)
{
case 0: clear_rx_buffer();//clearing receiving buffer
Serial.println("AT");// Attention command to wake
up GSM modem
delay(1000);
break;
case 1: clear_rx_buffer();//clearing receiving buffer
Serial.println("ATE0");//Command for disable echo
delay(1000);
break;
case 2: clear_rx_buffer();//clearing receiving buffer
Serial.println("ATV0");// Command for numeric
response after this '0'(zero) will be recieved
instead of "OK"
delay(1000);
break;
case 3: clear_rx_buffer();//clearing receiving buffer
264 Arduino-Based Embedded Systems
status_check = 14 ;
else if( rec_data == 0X0A && status_check == 14 )
//Line Feed
status_check = 15 ;
else if( rec_data == '0' && status_check == 15 )
// '0' is recieved
{
clear_rx_buffer();//clearing receiving
buffer
status_check = 0 ;
network_status=1;//goto next step
}
else if( rec_data != 'R' && status_check == 8 )
//+CPIN: NOT READY
{
clear_rx_buffer();//clearing receiving buffer
status_check = 0 ;
network_status=0;//repeat current step
}
else if( rec_data == 'M' && status_check == 3 )
// in case of any message
{
clear_rx_buffer();//clearing receiving
buffer
status_check = 0 ;
network_status=0;//repeat current step
}
}
lcd.setCursor(0,0);
lcd.print("CPIN: Ready ");
while(network_status == 1 )//wait for SIM network
registration
{
if(status_check == 0 )
{
delay(1000);
status_check = 1 ;
clear_rx_buffer();//clearing receiving buffer
Serial.println("AT+CREG?"); //checking for SIM
card registration,if registerd "+CREG: 0,1"
will receive
}
while(Serial.available() > 0)
{
rec_data = Serial.read();
if( rec_data == '+' && status_check == 1 )
// '+' is recieved
Global System for Mobile-Based Emergency System 267
status_check = 2 ;
else if( rec_data == 'C' && status_check == 2 )
// 'C' is recieved
status_check = 3 ;
else if( rec_data == 'R' && status_check == 3 )
// 'R' is recieved
status_check = 4 ;
else if( rec_data == 'E' && status_check == 4 )
// 'E' is recieved
status_check = 5 ;
else if( rec_data == 'G' && status_check == 5 )
// 'G' is recieved
status_check = 6 ;
else if( rec_data == ':' && status_check == 6 )
// ':' is recieved
status_check = 7 ;
else if( rec_data == ' ' && status_check == 7 )
// ' ' is recieved
status_check = 8 ;
else if( rec_data == '0' && status_check == 8 )
// '0' is recieved
status_check = 9 ;
else if( rec_data == ',' && status_check == 9 )
// ',' is recieved
status_check = 10 ;
else if( rec_data == '1' && status_check == 10 )
// '1' is recieved
status_check = 11 ;
else if( rec_data == 0X0D && status_check == 11 )
//Carriage return
status_check = 12 ;
else if( rec_data == 0X0A && status_check == 12 )
// Line Feed
status_check = 13 ;
else if( rec_data == '0' && status_check == 13 )
// '0' is recieved
{
clear_rx_buffer();//
clearing receiving buffer
status_check = 0 ;
network_status=2;//goto next step
}
else if( rec_data != '1' && status_check == 10 )
// +CREG: 0,2 not registered
268 Arduino-Based Embedded Systems
{
clear_rx_buffer();//
clearing receiving buffer
status_check = 0 ;
network_status=1;//repeat current step
}
else if( rec_data == 'M' && status_check == 3 )
// in case of any message
{
clear_rx_buffer();//clearing receiving
buffer
status_check = 0 ;
network_status=1;//repeat current step
}
}
gsm_cnt=0;
lcd.setCursor(0,0);
lcd.print("Registration Ok ");
while(gsm_cnt < 4)// repeat entire loop until gsm_cnt less
than nine
{
switch(gsm_cnt)
{
case 0: clear_rx_buffer();//clearing receiving buffer
Serial.println("AT+CMGF=1");// Attention
command to wake up GSM modem
delay(1000);
break;
case 1: clear_rx_buffer();//clearing receiving buffer
Serial.println("AT+CNMI=2,1,0,0,0");
//Command to configure new message indication
delay(1000);
break;
case 2: clear_rx_buffer();//clearing receiving buffer
Serial.println("AT+CMGD=1,4");// Command
to delete all received messages
delay(1000);
break;
case 3: gsm_cnt = 4;// exit from the loop
break;
default :break;
}
while(Serial.available() > 0)
{
rec_data = Serial.read();
Global System for Mobile-Based Emergency System 269
msg_flg=0;
call_flag=0;
msg_flag_2=0;
d_count=0;
reply_flag=0;
}
}
}
void array_clear(void)
{
byte k=0;
for(k=0;k<=15;k++)
number[k]='\0';
for(k=0;k<=63;k++)
message[k]='\0';
}
FIGURE 22.3
Proteus simulation model of the system showing “FIRE DETECTED.”
Global System for Mobile-Based Emergency System 273
FIGURE 22.4
Proteus simulation model of the system showing “NO FIRE.”
23
Coordinate Display System Using GPS
23.1 Introduction
This chapter explains the global positioning system (GPS)-based coordinate
display system. The system has two sections: (1) transmitter section and
(2) receiver section. The transmitter section comprises the Arduino Uno,
power supply, LCD, GPS module, and the RF modem. GPS is connected to
detect the coordinates of node location. The receiver section comprises the
Arduino Uno, power supply, LCD, RF modem, and the terminal v1.9b. The
RF modem is used for short-distance wireless communication and the termi-
nal v1.9b is used to display the coordinates with the PC. It can be used as a
localization system in the robots. Figure 23.1 shows the snapshot of the GPS
module. Figure 23.2 shows the block diagram of the system.
To design the system, following components are required (Tables 23.1
and 23.2).
FIGURE 23.1
A GPS module.
275
276 Arduino-Based Embedded Systems
Power
Arduino RF RF Arduino Terminal
supply
Uno modem modem Uno v1.9b
12 V/1 A
Power
GPS supply
module 12 V/1 A
FIGURE 23.2
Block diagram of the system.
TABLE 23.1
Components List for a Transmitter Section
Component/Specification Quantity
TABLE 23.2
Components List for a Receiver Section
Component/Specification Quantity
Figure 23.3 shows the circuit diagram for the system, connecting all the
components as per connections.
Coordinate Display System Using GPS
FIGURE 23.3
A circuit diagram of the system.
279
280 Arduino-Based Embedded Systems
23.3 Program
23.3.1 Transmitter Section
#include <TinyGPS.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
TinyGPS gps; //Creates a TinyGPS object
void setup()
{
Serial.begin(9600);
lcd.begin(40,2);
lcd.print("GPS DISPLAY SYSTEM");
delay(1000);
lcd.clear();
}
void loop()
{
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
lcd.setCursor(0,0);
lcd.print("Latitude = ");
lcd.print(flat == TinyGPS::GPS_INVALID_F_ANGLE
? 0.0 : flat, 6);
Coordinate Display System Using GPS 281
lcd.setCursor(0,1);
lcd.print(" Longitude = ");
lcd.print(flon == TinyGPS::GPS_INVALID_F_ANGLE
? 0.0 : flon, 6);
}
Serial.println(failed);
}
void loop()
{
if (stringComplete)
{
lcd.clear();
Serial.println(inputString);
lcd.setCursor(0,2);
lcd.print("LATITUDE:");
lcd.print(inputString[0]);
lcd.print(inputString[1]);
lcd.print(inputString[2]);
lcd.print(inputString[3]);
lcd.print(inputString[4]);
lcd.print(inputString[5]);
lcd.print(inputString[6]);
lcd.print(inputString[7]);
lcd.print(inputString[8]);
282 Arduino-Based Embedded Systems
lcd.setCursor(0,3);
lcd.print("LONGITUDE:");
lcd.print(inputString[9]);
lcd.print(inputString[10]);
lcd.print(inputString[11]);
lcd.print(inputString[12]);
lcd.print(inputString[13]);
lcd.print(inputString[14]);
lcd.print(inputString[15]);
lcd.print(inputString[16]);
lcd.print(inputString[17]);
lcd.print(inputString[18]);
lcd.print(inputString[19]);
if(inputString[0]==0x0A)
{
lcd.setCursor(0,2);
lcd.print("LATITUDE:");
lcd.print(inputString[1]);
lcd.print(inputString[2]);
lcd.print(inputString[3]);
lcd.print(inputString[4]);
lcd.print(inputString[5]);
lcd.print(inputString[6]);
lcd.print(inputString[7]);
lcd.print(inputString[8]);
lcd.print(inputString[9]);
lcd.setCursor(0,3);
lcd.print("LONGITUDE:");
lcd.print(inputString[10]);
lcd.print(inputString[11]);
lcd.print(inputString[12]);
lcd.print(inputString[13]);
lcd.print(inputString[14]);
lcd.print(inputString[15]);
lcd.print(inputString[16]);
lcd.print(inputString[17]);
lcd.print(inputString[18]);
lcd.print(inputString[19]);
lcd.print(inputString[20]);
}
inputString = "";
stringComplete = false;
}
delay(200);
}
Coordinate Display System Using GPS 283
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read(); // read serial
inputString += inChar;// store byte in string
if (inChar == 0x0D)
{
stringComplete = true;
}
}
}
FIGURE 23.4
Proteus simulation model for the system.
24
Fingerprint-Based Attendance System
24.1 Introduction
This chapter discusses about the fingerprint-based attendance system. The
fingerprint sensor can read different fingerprints and store them in its flash
memory. It can perform functions such as ADD, Empty, or Search and return
to the stored ID. These functions can be performed with three onboard
switches. Fingerprint of each student is first identified and stored. The
fingerprint of student is matched with the pre stored data, to authenticate
the presence of a student. The system comprises of Arduino Nano, power
supply, and fingerprint sensor.
285
286 Arduino-Based Embedded Systems
Liquid crystal
display
(LCD)
Power Serial
Arduino
supply converter
Nano
12 V/1 A
Fingerprint
module
FIGURE 24.1
Block diagram of the system.
TABLE 24.1
Components List for a System
Component/Specification Quantity
FIGURE 24.2
A circuit diagram of the system.
288 Arduino-Based Embedded Systems
24.3 Program
24.3.1 Finger Print Circuit ‘Test Program’
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int FF_PIN1=7;
int x_PIN1=6;
int y_PIN1=5;
int z_PIN1=4;
int w_PIN1=3;
int p_PIN1=2;
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
pinMode(FF_PIN1,INPUT_PULLUP);
pinMode(x_PIN1,INPUT_PULLUP);
pinMode(y_PIN1,INPUT_PULLUP);
pinMode(z_PIN1,INPUT_PULLUP);
pinMode(w_PIN1,INPUT_PULLUP);
pinMode(p_PIN1,INPUT_PULLUP);
lcd.setCursor(0, 0);
lcd.print("Fingerprint based");
lcd.setCursor(0, 1);
lcd.print("Security System");
void loop()
{
int FF_PIN=digitalRead(FF_PIN1);
int x_PIN=digitalRead(x_PIN1);
int y_PIN=digitalRead(y_PIN1);
int z_PIN=digitalRead(z_PIN1);
int w_PIN=digitalRead(w_PIN1);
int p_PIN=digitalRead(p_PIN1);
if(FF_PIN==LOW)
{
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("send FF");
Serial.write(0xFF);
delay(20);
}
Fingerprint-Based Attendance System 289
if(x_PIN==LOW)
{
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("send 00");
Serial.write(0x00);
delay(20);
}
if(y_PIN==LOW)
{
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("send 01");
Serial.write(0x01);
delay(20);
}
if(z_PIN==LOW)
{
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("send 02");
Serial.write(0x02);
delay(20);
}
if(w_PIN==LOW)
{
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("send 03");
Serial.write(0x03);
delay(20);
}
if(p_PIN==LOW)
{
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("send 04");
Serial.write(0x04);
delay(20);
}
}
290 Arduino-Based Embedded Systems
int SEARCH_PIN=7;
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
pinMode(SEARCH_PIN,OUTPUT);
digitalWrite(SEARCH_PIN,HIGH);
lcd.setCursor(0, 0);
lcd.print("Fingerprint based");
lcd.setCursor(0, 1);
lcd.print("Security System");
}
void loop()
{
digitalWrite(SEARCH_PIN,HIGH);
delay(500);
digitalWrite(SEARCH_PIN,LOW);
delay(500);
int DATA_FINGERPRINT=Serial.read();
if(DATA_FINGERPRINT==0xFF)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("show your ");
lcd.setCursor(0, 1);
lcd.print("right thomb");
delay(20);
}
if(DATA_FINGERPRINT==0x00)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Authenticate ");
lcd.setCursor(0, 1);
lcd.print("THANKS RAJESH");
delay(20);
}
if(DATA_FINGERPRINT==0x01)
{
lcd.clear();
lcd.setCursor(0, 0);
Fingerprint-Based Attendance System 291
lcd.print("Authenticate ");
lcd.setCursor(0, 1);
lcd.print("THANKS BHUPENDRA");
delay(20);
}
if(DATA_FINGERPRINT==0x02)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Authenticate ");
lcd.setCursor(0, 1);
lcd.print("THANKS ANITA");
delay(20);
}
if(DATA_FINGERPRINT==0x03)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Authenticate ");
lcd.setCursor(0, 1);
lcd.print("THANKS CHOUDHURY");
delay(20);
}
if(DATA_FINGERPRINT==0x04)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Authenticate ");
lcd.setCursor(0, 1);
lcd.print("THANKS XXXXXXX");
delay(20);
}
}
25
Wireless Irrigation System
for Agricultural Field
25.1 Introduction
This chapter elaborates the wireless irrigation system for the agricultural
field. The idea is to measure the soil moisture of field along with the sur-
rounding temperature. On the basis of the data received from the sensors,
the motor is made “ON” or “OFF” to irrigate the fields, as per the require-
ment of the crop. The system is designed in two sections: (1) Sensor node
and (2) Remote control. Sensor node comprises of the Arduino Uno, power
supply, soil moisture sensor, temperature sensor, LCD, load (DC motor),
and the RF modem. The remote control comprises of Arduino Uno, power
supply, LCD, switch array (to send commands to operate the load), and
RF modem. All the parameters can also be displayed on LabVIEW GUI.
Figure 25.1 shows the block diagram of the system.
Arduino RF RF Arduino
Uno modem modem Uno Temperature
Power
sensor
supply
12 V/1 A
To PC Power
Relay Load
(Labview) supply
12 V/1 A
FIGURE 25.1
Block diagram of the system.
293
294 Arduino-Based Embedded Systems
TABLE 25.1
Components List for a Remote Control
Component/Specification Quantity
TABLE 25.2
Components List for a Sensor Node
Component/Specification Quantity
Figure 25.2 shows the circuit diagram for the system, connecting all the
components as per connections.
Wireless Irrigation System for Agricultural Field 297
25.3 Program
25.3.1 Remote Control
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
#define BUTTON_MODE_SELECTION 7
#define BUTTON_PIN_MOTORON 6
#define BUTTON_PIN_MOTOROFF 5
String SM_TEMP_STRING = ""; // a string to hold incoming data
boolean SM_TEMP_stringComplete = false; // whether the string
is complete
void setup()
{
lcd.begin(20,4);
Serial.begin(9600);
pinMode(BUTTON_MODE_SELECTION,INPUT_PULLUP);
pinMode(BUTTON_PIN_MOTORON,INPUT_PULLUP);
pinMode(BUTTON_PIN_MOTOROFF,INPUT_PULLUP);
SM_TEMP_STRING.reserve(200);
lcd.setCursor(0,0);
lcd.print("WIRELESS IRREGATION ");
lcd.setCursor(0,1);
lcd.print("SYSTEM at UPES......");
delay(1000);
}
void loop()
{
int BUTTON_MODE_SELECTION_digital=digitalRead(BUTTON_MODE_
SELECTION);
if (BUTTON_MODE_SELECTION_digital==LOW)
{
Serial.println(30);
if (SM_TEMP_stringComplete)
{
lcd.clear();
lcd.setCursor(0,3);
lcd.print(SM_TEMP_STRING );
delay(10);
SM_TEMP_STRING = "";
SM_TEMP_stringComplete = false;
}
}
Wireless Irrigation System for Agricultural Field 299
else if(BUTTON_MODE_SELECTION_digital==HIGH)
{
int BUTTON_PIN_MOTORON_digital=digitalRead(BUTTON_
PIN_MOTORON);
int BUTTON_PIN_MOTOROFF_digital=digitalRead(BUTTON_
PIN_MOTOROFF);
if(BUTTON_PIN_MOTORON_digital==LOW)
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("MOTOR ON");
Serial.println(10);
}
if(BUTTON_PIN_MOTOROFF_digital==LOW)
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("MOTOR OFF");
Serial.println(20);
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
SM_TEMP_STRING += inChar;
if (inChar == 0x0D)
{
SM_TEMP_stringComplete = true;
}
}
}
void setup()
{
Serial.begin(9600);
lcd.begin(20,4);
pinMode(MOTOR_RELAY, OUTPUT);
SWITCH_STRING.reserve(200);
lcd.setCursor(0,0);
lcd.print("WIRELESS IRREGATION ");
lcd.setCursor(0,1);
lcd.print("SYSTEM at UPES......");
delay(1000);
}
void loop()
{
if (SWITCH_stringComplete)
{
lcd.clear();
delay(10);
if ((SWITCH_STRING[0]=='1')&&(SWITCH_
STRING[1]=='0'))
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("MOTOR ON");
digitalWrite(MOTOR_RELAY, HIGH);
delay(20);
}
else if ((SWITCH_STRING[0]=='2')&&(SWITCH_
STRING[1]=='0'))
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("MOTOR OFF");
digitalWrite(MOTOR_RELAY, LOW);
delay(20);
}
else if ((SWITCH_STRING[0]=='3')&&(SWITCH_
STRING[1]=='0'))
{
int ANALOG_READ_SM_SENSOR_LEVEL=analogRead(SM_
SENSOR);
int ANALOG_READ_SM_SENSOR_PPM=ANALOG_READ_SM_
SENSOR_LEVEL/10;
Wireless Irrigation System for Agricultural Field 301
int ANALOG_READ_TEMP_SENSOR_
LEVEL=analogRead(TEMP_SENSOR);
int ANALOG_READ_TEMP_SENSOR_0C=ANALOG_READ_
TEMP_SENSOR_LEVEL/2;
lcd.setCursor(0,3);
lcd.print("SMSENSOR:");
lcd.print(ANALOG_READ_SM_SENSOR_PPM);
lcd.setCursor(0,2);
lcd.print("TEMP");
lcd.print(ANALOG_READ_TEMP_SENSOR_0C);
Serial.print("SMSENSOR:");
Serial.print(ANALOG_READ_SM_SENSOR_PPM);
Serial.print("TEMP:");
Serial.println(ANALOG_READ_TEMP_SENSOR_0C);
delay(20);
}
if((SWITCH_STRING[0]==0x0A))
{
if ((SWITCH_STRING[1]=='1')&&
(SWITCH_STRING[2]=='0'))
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("MOTOR ON");
digitalWrite(MOTOR_RELAY, HIGH);
delay(20);
}
else if ((SWITCH_STRING[1]=='2')&&(SWITCH_
STRING[2]=='0'))
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("MOTOR OFF");
digitalWrite(MOTOR_RELAY, LOW);
delay(20);
}
else if ((SWITCH_STRING[1]=='3')&&(SWITCH_
STRING[2]=='0'))
{
int ANALOG_READ_SM_SENSOR_LEVEL=analogRead(SM_
SENSOR);
int ANALOG_READ_SM_SENSOR_PPM=ANALOG_READ_SM_
SENSOR_LEVEL/10;
302 Arduino-Based Embedded Systems
int ANALOG_READ_TEMP_SENSOR_
LEVEL=analogRead(TEMP_SENSOR);
int ANALOG_READ_TEMP_SENSOR_0C=ANALOG_READ_
TEMP_SENSOR_LEVEL/2;
lcd.setCursor(0,3);
lcd.print("SMSENSOR:");
lcd.print(ANALOG_READ_SM_SENSOR_PPM);
lcd.setCursor(0,2);
lcd.print("TEMP");
lcd.print(ANALOG_READ_TEMP_SENSOR_0C);
Serial.print("SMSENSOR:");
Serial.print(ANALOG_READ_SM_SENSOR_PPM);
Serial.print("TEMP:");
Serial.println(ANALOG_READ_TEMP_SENSOR_0C);
delay(20);
}
SWITCH_STRING = "";
SWITCH_stringComplete = false;
}
delay(10);
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
SWITCH_STRING += inChar;
if (inChar == 0x0D)
{
SWITCH_stringComplete = true;
}
}
}
Wireless Irrigation System for Agricultural Field 303
FIGURE 25.3
Proteus simulation model for the system.
304 Arduino-Based Embedded Systems
FIGURE 25.4
A Proteus simulation model showing “MOTOR ON.”
FIGURE 25.5
A Proteus simulation model showing “MOTOR OFF.”
Index
Note: Page numbers followed by f and t refer to figures and tables respectively.
305
306 Index