Anda di halaman 1dari 68

1.

INTRODUCTION

1
CHAPTER 2
Block Diagram for Industrial Disaster Management

Power supply
LPG Sensor sector
Transistor

Bluetooth
Module
Fire sensor
MICRO CONTROLLER
SECTOR

Machine
Servo
Overvibrated
Motor
Sensor
Transistor
Machine
Overheat Buttons
Sensor
DC Motor

Block diagram of Industrial Disaster Management Buzzer

CHAPTER 3

2
DEVICES USED

3.1.MICROCONTROLLER

A microcontroller is a compact microcomputer designed to govern the


operation of embedded systems in motor vehicles, robots, office machines,
complex medical devices, mobile radio transceivers, vending machines, home
appliances, and various other devices. A typical microcontroller includes
a processor, memory, and peripherals.

3.2.ARDUINO UNO

The Arduino Uno is a microcontroller board based on the ATmega328


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM
outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a
power jack, an ICSP header, and a reset button.

3.3.SENSORS
LPG Sensor
Fire Sensor
Machine Overheat Sensor
Machine Overvibrate Sensor
12V DC Motor
Servo Motor
Buzzer
Bluetooth Module

CHAPTER 4

3
Program to Operate the KIT

#include <Servo.h>

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
#define buz 9
#define motor 8
#define Enter 10
#define Exit 11
Servo door;
int fire,fire_machine,lpg,vibration=0;
char a;

void setup()
{
door.attach(12);
door.write(50);
mySerial.begin(9600);
pinMode(buz,OUTPUT);
pinMode(motor,OUTPUT);
pinMode(Enter,INPUT_PULLUP);
pinMode(Exit,INPUT_PULLUP);
digitalWrite(buz,LOW);
digitalWrite(motor,HIGH);

delay(2500);
}

void loop()

4
{
lpg=analogRead(A0);
fire=analogRead(A1);
fire_machine=analogRead(A2);
vibration=analogRead(A4);
if(digitalRead(Enter)==LOW)
{
door_open();
}

if(digitalRead(Exit)==LOW)
{
door_close();
}

fire=analogRead(A1);
if(fire>750) //Fire detection, SMS
{
mySerial.println("+919030465235/Fire Detected");
digitalWrite(motor,LOW);
door_open();
while(fire>750)
{
buzzer();
fire=analogRead(A1);
}
delay(4000);
door_close();
}
//=================================================
fire_machine=analogRead(A2);

5
if(fire_machine>750) //Machine Overheated, SMS
{
mySerial.println("+919030465235/Machine Overheated");
digitalWrite(motor,LOW);
door_open();
while(fire_machine>750)
{
buzzer1();
fire_machine=analogRead(A2);
}
delay(4000);
door_close();
}

//=================================================
lpg=analogRead(A0);
if(lpg>850) //LPG detection, SMS
{
digitalWrite(motor,LOW);
mySerial.println("+919030465235/LPG Detected");
door_open();
while(lpg>850)
{
buzzer2();
lpg=analogRead(A0);
}
delay(4000);
door_close();
}
//=====================
if(vibration>1000)

6
{
delay(2000);
vibration=analogRead(A4);
if(vibration>1000)
{
digitalWrite(motor,LOW);
mySerial.println("+919030465235/Machine Overvibrated");
door_open();
digitalWrite(buz,HIGH);
delay(5000);
while(vibration>1000)
{
vibration=analogRead(A4);
}

digitalWrite(buz,LOW);
delay(4000);
door_close();
}
}

void door_open()
{
door.write(140);

7
void door_close()
{
door.write(50);

}
void buzzer()
{
for(a=0;a<12;a++)
{
digitalWrite(buz,HIGH);
delay(200);
digitalWrite(buz,LOW);
delay(200);
}
}
void buzzer1()
{
for(a=0;a<6;a++)
{
digitalWrite(buz,HIGH);
delay(400);
digitalWrite(buz,LOW);
delay(400);
}
}
void buzzer2()
{
for(a=0;a<10;a++)
{
digitalWrite(buz,HIGH);

8
delay(300);
digitalWrite(buz,LOW);
delay(100);
}
}

9
CHAPTER 5
Power supply and Regulation

Ever since the dawn of Arduino, one question has been asked over and
over again: "what kind of DC adapter can I use to power my Arduino?"

The short answer is: 9 to 12V DC, 250mA or more, 2.1mm plug, centre pin
positive.

The long answer is that an off-the shelf Arduino adapter:

must be a DC adapter (i.e. it has to put out DC, not AC);

should be between 9V and 12V DC (see note below);

must be rated for a minimum of 250mA current output, although you


will likely want something more like 500mA or 1A output, as it gives you the
current necessary to power a servo or twenty LEDs if you want to.

10
must have a 2.1mm power plug on the Arduino end, and

the plug must be "centre positive", that is, the middle pin of the plug
has to be the + connection.

These important details are often contained right on the adapter. Here's
a picture of an adapter ideally suited to powering the Arduino. The important
info is underlined in red here:

As you can see, it has all the right stuff: 12V, DC, and a little picture
that shows you that the middle pin is positive.

Current rating: Since you'll probably be connecting other things to the


Arduino (LEDs, LCDs, servos) you should get an adapter that can supply at
least 500mA, or even 1000 mA (1 ampre). That way you can be sure you have
enough juice to make each component of the circuit function reliably.

One final note. The Arduino's on-board regulator can actually handle
up to 20V or more, so you can actually use an adapter that puts out 20V DC.
The reasons you don't want to do that are twofold: you'll lose most of that
voltage in heat, which is terribly inefficient. Secondly, the nice 9V pin on the

11
Arduino board will actually be putting out 20V or so, which could lead to
potential disaster when you connect something expensive to what you thought
was the 9V pin. Our advice is to stick with the 9V or 12V DC adapter.

12
CHAPTER-6
ARDUINO UNO

Arduino is an open source, computer hardware and software company,


project, and user community that designsand manufactures microcontroller kits
for building digital devices and interactive objects that can sense and control
objects in the physical world. The project's products are distributed as open-
source hardware and software, which are licensed under the GNU Lesser
General Public License (LGPL) or the GNU General Public License (GPL),
[1]
permitting the manufacture of Arduino boards and software distribution by
anyone. Arduino boards are available commercially in preassembled form, or
as do-it-yourself kits.

Arduino board designs use a variety of microprocessors and controllers. The


boards are equipped with sets of digital and analog input/output (I/O) pins that
may be interfaced to various expansion boards (shields) and other circuits. The
boards feature serial communications interfaces, including Universal Serial
Bus (USB) on some models, which are also used for loading programs from
personal computers. The microcontrollers are typically programmed using a
dialect of features from the programming languages C and C++. In addition to
using traditional compiler toolchains, the Arduino project provides
an integrated development environment (IDE) based on
the Processing language project.

The Arduino project started in 2003 as a program for students at


the Interaction Design Institute Ivrea in Ivrea, Italy, aiming to provide a low-
cost and easy way for novices and professionals to create devices that
interact with their environment using sensors and actuators. Common
examples of such devices intended for beginner hobbyists include
simple robots, thermostats, and motion detectors.

13
Arduino

Arduino Uno SMD R3

The
Developer Arduino name Arduino comes
from a bar in Ivrea,
Manufacturer Many Italy, where some of
the founders of the
project used to meet.
Type Single-board
The bar was named
microcontroller
after Arduino of
Ivrea, who was the
Operating None
margrave of
system
the March of
Ivrea and King of
CPU Atmel AVR (8- Italy from 1002 to
bit), 1014.
ARM Cortex-
M0+ (32-bit), 6.1 HISTORY
ARM Cortex-
M3 (32-bit),
Intel
14
Quark (x86) (32-
The origin of the Arduino project started at the Interaction Design
Institute Ivrea (IDII) in Ivrea, Italy. At that time, the students used a BASIC
Stamp microcontroller at a cost of $100, a considerable expense for many
students. In 2003, Colombian student Hernando Barragn created the
development platform Wiring as a Master's thesis project at IDII, under the
supervision of Massimo Banzi and Casey Reas, who are known for work on
the Processing language. The project goal was to create simple, low cost tools
for creating digital projects by non-engineers. The Wiring platform consisted
of a printed circuit board (PCB) with an ATmega168 microcontroller, an IDE
based on Processing and library functions to easily program the
microcontroller.

In 2003, Massimo Banzi, with David Mellis, another IDII student, and
David Cuartielles, added support for the cheaper ATmega8 microcontroller to
Wiring. But instead of continuing the work on Wiring, they copied the Wiring
source code and renamed it as a separate project, called Arduino.

The initial Arduino core team consisted of Massimo Banzi, David


Cuartielles, Tom Igoe, Gianluca Martino, and David Mellis, but Barragn was
not invited to participate.

Following the completion of the Wiring platform, lighter and less-


expensive versions were distributed in the open-source community.

Adafruit Industries, a New York City supplier of Arduino boards, parts,


and assemblies, estimated in mid-2011 that over 300,000 official Arduinos had
been commercially produced, and in 2013 that 700,000 official boards were in
users' hands.

6.2 HARDWARE:

Arduino is open-source hardware. The hardware reference designs are


distributed under a Creative Commons Attribution Share-Alike 2.5 license and

15
are available on the Arduino website. Layout and production files for some
versions of the hardware are also available. The source code for the IDE is
released under the GNU General Public License, version 2. Nevertheless, an
official Bill of Materials of Arduino boards has never been released by Arduino
staff.

Although the hardware and software designs are freely available


under copyleft licenses, the developers have requested that the
name Arduino be exclusive to the official product and not be used for derived
works without permission. The official policy document on use of the Arduino
name emphasizes that the project is open to incorporating work by others into
the official product. Several Arduino-compatible products commercially
released have avoided the project name by using various names ending
in arduino.

An early Arduino board with an RS-232 serial interface (upper left) and
an Atmel ATmega8 microcontroller chip (black, lower right); the 14 digital I/O
pins are at the top, the 6 analog input pins at the lower right, and the power
connector at the lower left.

Most Arduino boards consist of an Atmel 8-bit


AVR microcontroller (ATmega8, ATmega168, ATmega328, ATmega1280,
ATmega2560) with varying amounts of flash memory, pins, and features. The
32-bit Arduino Due, based on the Atmel SAM3X8E was introduced in

16
2012. The boards use single or double-row pins or female headers that
facilitate connections for programming and incorporation into other circuits.
These may connect with add-on modules termed shields. Multiple, and
possibly stacked shields may be individually addressable via an IC serial bus.
Most boards include a 5 V linear regulator and a 16 MHz crystal
oscillator or ceramic resonator. Some designs, such as the LilyPad, run at
8 MHz and dispense with the onboard voltage regulator due to specific form-
factor restrictions.

Arduino microcontrollers are pre-programmed with a boot loader that


simplifies uploading of programs to the on-chip flash memory. The default
bootloader of the Aduino UNO is the optiboot bootloader. Boards are loaded
with program code via a serial connection to another computer. Some serial
Arduino boards contain a level shifter circuit to convert between RS-232 logic
levels and transistortransistor logic (TTL) level signals. Current Arduino
boards are programmed via Universal Serial Bus (USB), implemented using
USB-to-serial adapter chips such as the FTDI FT232. Some boards, such as
later-model Uno boards, substitute the FTDI chip with a separate AVR chip
containing USB-to-serial firmware, which is reprogrammable via its own ICSP
header. Other variants, such as the Arduino Mini and the unofficial Boarduino,
use a detachable USB-to-serial adapter board or cable, Bluetooth or other
methods, when used with traditional microcontroller tools instead of the
Arduino IDE, standard AVR in-system programming (ISP) programming is
used.

17
An official Arduino Uno R2 with descriptions of the I/O
locations

The Arduino board exposes most of the microcontroller's I/O pins for
use by other circuits. The Diecimila, Duemilanove, and current Uno provide 14
digital I/O pins, six of which can produce pulse-width modulated signals, and
six analog inputs, which can also be used as six digital I/O pins. These pins are
on the top of the board, via female 0.1-inch (2.54 mm) headers. Several plug-in
application shields are also commercially available. The Arduino Nano, and
Arduino-compatible Bare Bones Board and Boarduino boards may provide
male header pins on the underside of the board that can plug into
solderless breadboards.

Many Arduino-compatible and Arduino-derived boards exist. Some are


functionally equivalent to an Arduino and can be used interchangeably. Many
enhance the basic Arduino by adding output drivers, often for use in school-
level education, to simplify making buggies and small robots. Others are
electrically equivalent but change the form factor, sometimes retaining
compatibility with shields, sometimes not. Some variants use different
processors, of varying compatibility.

6.3 Official boards


The original Arduino hardware was produced by the Italian company
Smart Projects. Some Arduino-branded boards have been designed by the
American companies SparkFun Electronics and Adafruit Industries. As of
2016, 17 versions of the Arduino hardware have been commercially produced.

The Arduino project provides the Arduino integrated development


environment (IDE), which is a cross-platform application written in the
programming language Java. It originated from the IDE for the
languages Processing and Wiring. It includes a code editor with features such
as text cutting and pasting, searching and replacing text, automatic

18
indenting, brace matching, and syntax highlighting, and provides simple one-
click mechanisms to compile and upload programs to an Arduino board. It also
contains a message area, a text console, a toolbar with buttons for common
functions and a hierarchy of operation menus.

A program written with the IDE for Arduino is called a sketch.


[42]
Sketches are saved on the development computer as text files with the file
extension .ino. Arduino Software (IDE) pre-1.0 saved sketches with the
extension .pde.

The Arduino IDE supports the languages C and C++ using special rules
of code structuring. The Arduino IDE supplies a software library from
the Wiring project, which provides many common input and output
procedures. User-written code only requires two basic functions, for starting
the sketch and the main program loop, that are compiled and linked with a
program stub main() into an executable cyclic executive program with
the GNU toolchain, also included with the IDE distribution. The Arduino IDE
employs the program avrdude to convert the executable code into a text file in
hexadecimal encoding that is loaded into the Arduino board by a loader
program in the board's firmware.

A minimal Arduino C/C++ sketch, as seen by the Arduino IDE


programmer, consist of only two functions:[43]

setup: This function is called once when a sketch starts after power-up
or reset. It is used to initialize variables, input and output pin modes, and other
libraries needed in the sketch.[44]

loop: After setup has been called, function loop is executed repeatedly
in the main program. It controls the board until the board is powered off or is
reset. Most Arduino boards contain a light-emitting diode (LED) and a load
resistor connected between pin 13 and ground, which is a convenient feature

19
for many tests and program functions.[46] A typical program for a beginning
Arduino programmer blinks an LED repeatedly.

6.4 APPLICATIONS

Xoscillo, an open-source oscilloscope[50]

Arduinome, a MIDI controller device that mimics the Monome

OBDuino, a trip computer that uses the on-board diagnostics interface


found in most modern cars

Ardupilot, drone software and hardware

Gameduino, an Arduino shield to create retro 2D video games

ArduinoPhone, a do-it-yourself cellphone

Water quality testing platform

Automatic titration system based on Arduino and stepper motor

Low cost data glove for virtual reality applications

Impedance sensor system to detect bovine milk adulteration

Homemade CNC using Arduino and DC motors with close loop control
by Homofaciens

DC motor control using Arduino and H-Bridge

6.5 RECOGNITION

20
The Arduino project received an honorary mention in the Digital
Communities category at the 2006 Prix Ars Electronical

6.6 TRADEMARK

In early 2008, the five cofounders of the Arduino project created a


company, Arduino LLC, to hold the trademarks associated with Arduino. The
manufacture and sale of the boards was to be done by external companies, and
Arduino LLC would get a royalty from them. The founding bylaws of Arduino
LLC specified that each of the five founders transfer ownership of the Arduino
brand to the newly formed company.

At the end of 2008, Gianluca Martino's company, Smart Projects,


registered the Arduino trademark in Italy and kept this a secret from the other
cofounders for about two years.

This was revealed when the Arduino company tried to register the
trademark in other areas of the world (they originally registered only in the
US), and discovered that it was already registered in Italy. Negotiations with
Gianluca and his firm to bring the trademark under control of the original
Arduino company failed. In 2014, Smart Projects began refusing to pay
royalties. They then appointed a new CEO, Mr. Musto, who renamed the
company to Arduino SRL and created a website named arduino.org, copying
the graphics and layout of the original Arduino.cc. This resulted in a rift in the
Arduino development team. All Arduino boards are still available to consumers
so the implications of this are uncertain. In January 2015, Arduino LLC file a
lawsuit against Arduino SRL.

In May 2015, Arduino LLC created the worldwide trademark


"Genuino", used as brand name outside the United States.

21
At the World Maker Faire in New York on October 1, 2016, Arduino
LLC co-founder and CEO Massimo Banzi and Arduino SRL CEO Federico
Musto announced the merger of the two arduino companies.

The Arduino BT is a microcontroller board originally was based on


the ATmega168, but now is supplied with the 328 (datasheet) and the
Bluegiga WT11 bluetooth module (details and datasheet [pdf]). It supports
wireless serial communication over bluetooth (but is not compatible with
Bluetooth headsets or other audio devices). It has 14 digital input/output pins
(of which 6 can be used as PWM outputs and one can be used to reset
the WT11 module), 6 analog inputs, a 16 MHz crystal oscillator, screw
terminals for power, an ICSP header, and a reset button. It contains everything
needed to support the microcontroller and can be programmed wirelessly over
the Bluetooth connection. Instructions are available for getting started with the
Arduino BT

Arduino BT Front

22
Arduino back

6.7 Arduino Controller

Arduino is an open source electronics board or minicomputer. Arduino


is designed to make electronic more accessible to artists, hobbyists and anyone
interested in creating interactive objects or environments [7]. The first arduino
was introduced in 2005, which is aimed to provide an inexpensive and easy
way to professionals, to create devices, or different attractive projects. Arduino
boards are in preassembled form. For programming arduino board, arduino
integrated development environment (IDE) is used, which supports for C and
C++ programming languages.

23
An arduino board consists of an Atmel 8, 16, 32 bit AVR controller.
An important aspect of the arduino is its standard connectors, which lets users
connect arduino board to variety of modules known as shields.
6.8 Arduino Block Diagram

CHAPTER 7
ATmega328

The ATmega328 is a single-chip microcontroller created by Atmel in


the megaAVR family.

24
ATmega328

7.1 Specifications

The Atmel 8-bit AVR RISC-based microcontroller combines


32 kB ISP flash memory with read-while-write
capabilities,1 kB EEPROM,2 kB SRAM, 23 general purpose I/O lines, 32
general purpose working registers, three flexible timer/counters with compare
modes, internal and external interrupts, serial programmable USART, a byte-
oriented 2-wire serial interface, SPI serial port, 6-channel 10-bit A/D
converter (8-channels in TQFP and QFN/MLF packages),
programmable watchdog timer with internal oscillator, and five
software selectable power saving modes. The device operates between 1.8-5.5
volts. The device achieves throughput approaching1 MIPS per MHz

25
Parameter Value

CPU type 8-bit AVR

Performance 20 MIPS at 20 MHz[2]

Flash memory 32 Kb

SRAM 2 Kb

EEPROM 1 Kb

Pin count 28-pin PDIP, MLF, 32-pin TQFP, MLF[2]

Maximum
operating 20 MHz
frequency

Number of
16
touch channels

Hardware
QTouch No
Acquisition

Maximum I/O
26
pins

External
24
interrupts

USB Interface No

USB Speed No 26
7.2 Series Alternatives
A common alternative to the ATmega328 is the "picoPower"
ATmega328P. A comprehensive list of all other member of the megaAVR
series can be found on the Atmel website.

7.3 Applications
As of 2013 the ATmega328 is commonly used in many projects and
autonomous systems where a simple, low-powered, low-cost micro-controller
is needed. Perhaps the most common implementation of this chip is on the
popular Arduino development platform, namely the Arduino Uno and Arduino
Nano models.

7.4 Programming
Reliability qualification shows that the projected data retention failure
rate is much less than 1 PPM over 20 years at 85 C or 100 years at 25 C.

Parallel program mode[2]

Programming I/
Pin Name Function
signal O

RDY/BSY PD1 O High


means the
MCU is
ready for
a new
command,
otherwise

27
busy.

Output
Enable
OE PD2 I
(Active
low)

Write
Pulse
WR PD3 I
(Active
low)

Byte
Select 1
BS1 PD4 I (0 = Low
byte, 1 =
High byte)

XTAL
XA0 PD5 I Action bit
0

XTAL
XA1 PD6 I Action bit
1

PAGEL PD7 I Program


memory
and
EEPROM
Data Page

28
Load

BS2 PC2 I Byte


Select 2
Serial Programming[2] (0 = Low
byte, 1 =
2nd High
Symbo Pin
I/O Description byte)
l s

DATA PC[1:0]:PB[5:0] I/ Bi-


Serial data
MOSI PB3 I O directional
in
data bus
(Output
Serial Data
MISO PB4 O when OE
out
is low)

SCK PB5 I Serial Clock

Programming mode is entered when PAGEL (PD7), XA1 (PD6), XA0


(PD5), BS1 (PD4) is set to zero. [2] RESET pin to 0V and VCC to 0V. VCC is set
to 4.5 - 5.5V. Wait 60 s, and RESET is set to 11.5 - 12.5 V. Wait more than
310 s.[2] Set XA1:XA0:BS1:DATA = 100 1000 0000, pulse XTAL1 for at
least 150 ns, pulse WR to zero. This starts the Chip Erase. Wait until
RDY/BSY (PD1) goes high. XA1:XA0:BS1:DATA = 100 0001 0000, XTAL1
pulse, pulse WR to zero. This is the Flash write command.[2] And so on..

29
Serial data to the MCU is clocked on the rising edge and data from the
MCU is clocked on the falling edge. Power is applied to V CC while RESET and
SCK are set to zero. Wait for at least 20 ms and then the Programming Enable
serial instruction 0xAC, 0x53, 0x00, 0x00 is sent to the MOSI pin. The second
byte (0x53) will be echoed back by the MCU

7.5 Block Diagram of ATmega328

The table below gives a description for each of the pins, along with their
function.

30
Pin
Description Function
Number

1 PC6 Reset

2 PD0 Digital Pin (RX)

3 PD1 Digital Pin (TX)

4 PD2 Digital Pin

5 PD3 Digital Pin (PWM)

6 PD4 Digital Pin

7 Vcc Positive Voltage (Power)

8 GND Ground

9 XTAL 1 Crystal Oscillator

10 XTAL 2 Crystal Oscillator

11 PD5 Digital Pin (PWM)

12 PD6 Digital Pin (PWM)

13 PD7 Digital Pin

14 PB0 Digital Pin

15 PB1 Digital Pin (PWM)

16 PB2 Digital Pin (PWM)

17 PB3 Digital Pin (PWM)

18 PB4 Digital Pin

19 PB5 Digital Pin

20 AVCC Positive voltage for ADC (power)

21 AREF Reference Voltage

22 GND Ground

23 PC0 Analog Input

24 PC1 Analog Input

25 PC2 Analog Input

26 PC3 Analog Input

27 PC4 Analog Input

28 PC5 Analog Input

31
As stated before, 20 of the pins function as I/O ports. This means they
can function as an input to the circuit or as output. Whether they are input or
output is set in the software. 14 of the pins are digital pins, of which 6 can
function to give PWM output. 6 of the pins are for analog input/output.

2 of the pins are for the crystal oscillator. This is to provide a clock
pulse for the Atmega chip. A clock pulse is needed for synchronization so that
communication can occur in synchrony between the Atmega chip and a device
that it is connected to.

The chip needs power so 2 of the pins, Vcc and GND, provide it power
so that it can operate. The Atmega328 is a low-power chip, so it only needs
between 1.8-5.5V of power to operate.

The Atmega328 chip has an analog-to-digital converter (ADC) inside


of it. This must be or else the Atmega328 wouldn't be capable of interpreting
analog signals. Because there is an ADC, the chip can interpret analog input,
which is why the chip has 6 pins for analog input. The ADC has 3 pins set
aside for it to function- AVCC, AREF, and GND. AVCC is the power supply,
positive voltage, that for the ADC. The ADC needs its own power supply in
order to work. GND is the power supply ground. AREF is the reference voltage
that the ADC uses to convert an analog signal to its corresponding digital
value. Analog voltages higher than the reference voltage will be assigned to a
digital value of 1, while analog voltages below the reference voltage will be
assigned the digital value of 0. Since the ADC for the Atmega328 is a 10-bit
ADC, meaning it produces a 10-bit digital value, it converts an analog signal to
its digital value, with the AREF value being a reference for which digital
values are high or low. Thus, a portrait of an analog signal is shown by this
digital value; thus, it is its digital correspondent value.

32
The last pin is the RESET pin. This allows a program to be rerun and start
over.

33
CHAPTER 8
Basic Components
8.1 Diode
In electronics, a diode is a component that restricts the direction of
movement of charge carriers. Essentially, it allows an electric current to flow in
one direction, but blocks it in the opposite direction. Today the most common
diodes are made from semiconductor materials such as silicon or germanium.

Diode
8.2 Semiconductor Diodes
Most modern diodes are based on semiconductor P-N junctions. In a P-
N diode, conventional current can flow from the P-type side (the anode) to the
N-type side (the cathode), but not in the opposite direction. A semiconductor
diode s current-voltage, or I-V, characteristic curve is ascribed to the behaviour
of the so-called depletion layer or depletion zone which exists at the P-N
junction between the differing semiconductors. When a P-N junction is first
created, conduction band (mobile) electrons from the N-doped region diffuse
into the P-doped region where there is a large population of holes (places for
electrons in which no electron is present) with which the electrons recombine.
When a mobile electron recombines with a hole, the hole vanishes and the
electron is no longer mobile. Thus, two charge carriers have vanished. The
region around the P-N junction becomes depleted of charge carriers and thus
behaves as an insulator.

8.3 Voltage regulator


7805 Voltage regulator
5V DC Voltage Regulator Data Sheet / Specs

Voltage Regulator
The 7805 provides circuit designers with an easy way to regulate DC
voltages to 5v. Encapsulated in a single chip/package (IC), the 7805 is a
positive voltage DC regulator that has only 3 terminals. They are: Input
voltage, Ground, Output Voltage. Although the 7805 were primarily designed
for a fixed-voltage output (5V). 7812 Voltage regulator
12V DC Voltage Regulator Data Sheet / Specs The 78012 provides circuit
designers with an easy way to regulate DC voltages to 12v. Encapsulated in a
single chip/package (IC), the 78012 is a positive voltage DC regulator that has
only 3 terminals. They are: Input voltage, Ground, Output Voltage. Although
the 78012 were primarily designed for a fixed-voltage output (12V). 7812
Voltage regulator It is indeed possible to use external components in order to
obtain DC output voltages of: 5V, 6V, 8V, 9V, 10V, 12V, 15V, 18V, 20V, 24V.
Note that the input voltage must, of course, be greater than the required output
voltage, so that it can be regulated downwards.

8.4 Capacitor
In the Regulated power supply the rating of the chosen capacitor filter
is 1000F.
A capacitor (originally known as condenser) is a passive two-terminal
electrical component used to store energy in an electric field. The forms of
practical capacitors vary widely, but all contain at least two electrical
conductors separated by a dielectric (insulator); for example, one common
construction consists of metal foils separated by a thin layer of insulating film.
Capacitors are widely used as parts of electrical circuits in many common
electrical devices.When there is a potential difference (voltage) across the
conductors, a static electric field develops across the dielectric, causing
positive charge to collect on one plate and negative charge on the other plate.
Energy is stored in the electrostatic field. An ideal capacitor is characterized by
a single constant value, capacitance, measured in farads. This is the ratio of the
electric charge on each conductor to the potential difference between them.

Capacitor
The capacitance is greatest when there is a narrow separation between
large areas of conductor, hence capacitor conductors are often called "plates,"
referring to an early means of construction. In practice, the dielectric between
the plates passes a small amount of leakage current and also has an electric
field strength limit, resulting in a breakdown voltage, while the conductors and
leads introduce an undesired inductance and resistance. Capacitors are widely
used in electronic circuits for blocking direct current while allowing alternating
current to pass, in filter networks, for smoothing the output of power supplies,
in the resonant circuits that tune radios to particular frequencies, in electric
power transmission systems for stabilizing voltage and power flow, and for
many other purposes.
8.5 Transistor
An NPN transistor can be considered as two diodes with a shared
anode. In typical operation, the base-emitter junction is forward biased and the
basecollector junction is reverse biased. In an NPN transistor, for example,
when a positive voltage is applied to the baseemitter junction, the equilibrium
between thermally generated carriers and the repelling electric field of the
depletion region becomes unbalanced, allowing thermally excited electrons to
inject into the base region. These electrons wander (or "diffuse") through the
base from the region of high concentration near the emitter towards the region
of low concentration near the collector. The electrons in the base are called
minority carriers because the base is doped p-type which would make holes the
majority carrier in the base.

Transistor
Transistors can be regarded as a type of switch, as can many electronic
components. They are used in a variety of circuits and you will find that it is
rare that a circuit built in a school Technology Department does not contain at
least one transistor. They are central to electronics and there are two main
types; NPN and PNP. Most circuits tend to use NPN. There are hundreds of
transistors which work at different voltages but all of them fall into these two
categories.
Transistors are manufactured in different shapes but they have three
leads (legs). The BASE - which is the lead responsible for activating the
transistor.The COLLECTOR - which is the positive lead.The EMITTER -
which is the negative lead. The diagram below shows the symbol of an NPN
transistor. They are not always set out as shown in the diagrams to the left and
right, although the tab on the type shown to the left is usually next to the
emitter.

8.6 Resistors
A resistor is a passive two-terminal electrical component that
implements electrical resistance as a circuit element. The current through a
resistor is in direct proportion to the voltage across the resistor's terminals.
Thus, the ratio of the voltage applied across a resistor's terminals to the
intensity of current through the circuit is called resistance. This relation is
represented by Ohm's law: where I is the current through the conductor in units
of amperes, V is the potential difference measured across the conductor in units
of volts, and R is the resistance of the conductor in units of ohms. More
specifically, Ohm's law states that the R in this relation is constant,
independent of the current. Resistors are common elements of electrical
networks and electronic circuits and are ubiquitous in electronic equipment.
Practical resistors can be made of various compounds and films, as well as
resistance wire (wire made of a high-resistivity alloy, such as nickel-chrome).
Resistors are also implemented within integrated circuits, particularly analog
devices, and can also be integrated into hybrid and printed circuits.
Resistor
The electrical functionality of a resistor is specified by its resistance:
common commercial resistors are manufactured over a range of more than nine
orders of magnitude. When specifying that resistance in an electronic design,
the required precision of the resistance may require attention to the
manufacturing tolerance of the chosen resistor, according to its specific
application. The temperature coefficient of the resistance may also be of
concern in some precision applications. Practical resistors are also specified as
having a maximum power rating which must exceed the anticipated power
dissipation of that resistor in a particular circuit: this is mainly of concern in
power electronics applications. Resistors with higher power ratings are
physically larger and may require heat sinks. In a high-voltage circuit, attention
must sometimes be paid to the rated maximum working voltage of the resistor
CHAPTER 9
SENSORS
9. BUZZER
9.1 what is Buzzer
A buzzer or beeper is an audio signaling device, which may be
mechanical, electromechanical or piezoelectric. Typical uses of buzzers and
beepers include alarm devices. These devices are output transducers converting
electrical energy. A Buzzer or Beeper is a signaling device, usually electronic,
typically used in automobiles, household appliances such as microwave ovens,
or game shows. It most commonly consists of a number of switches or sensors
connected to a control unit that determines if and which button was pushed or a
preset time has lapsed, and usually illuminates a light on the appropriate button
or control panel, and sounds a warning in the form of a continuous or
intermittent buzzing or beeping sound.

9.2 Operation
As power is applied this mechanical device will energize and by doing
so interrupt the power source and the cycle continue until the power is
removed. The frequency of oscillation is strictly dependent on mechanical
inertia. The piezo buzzer produces sound based on reverse of the piezoelectric
effect. The generation of pressure variation or strain by the application of
electric potential across a piezoelectric material is the underlying principle.
These buzzers can be used alert a user of an event corresponding to a switching
action, counter signal or sensor input. They are also used in alarm circuits. The
buzzer produces a same noisy sound irrespective of the voltage variation
applied to it. It consists of piezo crystals between two conductors. When a
potential is applied across these crystals, they push on one conductor and pull
on the other. This, push and pull action, results in a sound wave.
Most buzzers produce sound in the range of 2 to 4 kHz. The Red lead is
connected to the Input and the Black lead is connected to Ground. Initially this
device was based on an electromechanical system which was identical to an
electric bell without the metal gong (which makes the ringing noise). Often
these units were anchored to a wall or ceiling and used the ceiling or wall as a
sounding board. Another implementation with some AC-connected devices
was to implement a circuit to make the AC current into a noise loud enough to
drive a loudspeaker and hook this circuit up to an 8-ohm speaker.

Fig 4.1: Buzzer


Nowadays, it is more popular to use a ceramic-based piezoelectric
sounder which makes a high-pitched tone. Usually these were hooked up to
"driver" circuits which varied the pitch of the sound or pulsed the sound on and
off. In game shows it is also known as a "lockout system" because when one
person signals ("buzzes in"), all others are locked out from signaling. Several
game shows have large buzzer buttons which are identified as "plungers". The
buzzer is also used to signal wrong answers and when time expires on many
game shows, such as Wheel of Fortune, Family Feud and The Price is Right.
The word "buzzer" comes from the rasping noise that buzzers made when they
were electromechanical devices, operated from stepped-down AC line voltage
at 50 or 60 cycles. Other sounds commonly used to indicate that a button has
been pressed are a ring or a beep.
Block Diagram of Buzzer

10. DC Motor section

In any electric motor, operation is based on simple electromagnetism.


A current-carrying conductor generates a magnetic field; when this is then
placed in an external magnetic field, it will experience a force proportional to
the current in the conductor, and to the strength of the external magnetic field.
As you are well aware of from playing with magnets as a kid, opposite (North
and South) polarities attract, while like polarities (North and North, South and
South) repel. The internal configuration of a DC motor is designed to harness
the magnetic interaction between a current-carrying conductor and an external
magnetic field to generate rotational motion.
Let's start by looking at a simple 2-pole DC electric motor (here red represents
a magnet or winding with a "North" polarization, while green represents a
magnet or winding with a "South" polarization).
Fig. 9.1 Diagram of DC Motor

Every DC motor has six basic parts -- axle, rotor (a.k.a., armature), stator,
commutator, field magnet(s), and brushes. In most common DC motors (and
all that beamers will see), the external magnetic field is produced by high-
strength permanent magnets1. The stator is the stationary part of the motor --
this includes the motor casing, as well as two or more permanent magnet pole
pieces. The rotor (together with the axle and attached commutator) rotate with
respect to the stator. The rotor consists of windings (generally on a core), the
windings being electrically connected to the commutator. The above diagram
shows a common motor layout -- with the rotor inside the stator (field)
magnets. The geometry of the brushes, commutator contacts, and rotor
windings are such that when power is applied, the polarities of the energized
winding and the stator magnet(s) are misaligned, and the rotor will rotate until
it is almost aligned with the stator's field magnets. As the rotor reaches
alignment, the brushes move to the next commutator contacts, and energize the
next winding. Given our example two-pole motor, the rotation reverses the
direction of current through the rotor winding, leading to a "flip" of the rotor's
magnetic field, driving it to continue rotating.
In real life, though, DC motors will always have more than two poles
(three is a very common number). In particular, this avoids "dead spots" in the
commutator. You can imagine how with our example two-pole motor, if the
rotor is exactly at the middle of its rotation (perfectly aligned with the field
magnets), it will get "stuck" there. Meanwhile, with a two-pole motor, there is
a moment where the commutator shorts out the power supply (i.e., both
brushes touch both commutator contacts simultaneously). This would be bad
for the power supply, waste energy, and damage motor components as well.
Yet another disadvantage of such a simple motor is that it would exhibit a high
amount of torque "ripple" (the amount of torque it could produce is cyclic with
the position of the rotor).

10.1 Principle of Operation


Like all electric motors or generators, torque is produced by the
principle of Lorentz force, which states that any current-carrying conductor
placed within an external magnetic field experiences a torque or force known
as Lorentz force. Advantages of a brushed DC motor include low initial cost,
high reliability, and simple control of motor speed.Disadvantages are high
maintenance and low life-span for high intensity uses. Maintenance involves
regularly replacing the brushes and springs which carry the electric current, as
well as cleaning or replacing the commutator. These components are necessary
for transferring electrical power from outside the motor to the spinning wire
windings of the rotor inside the motor.
Fig. 8.1 DC motor

In our project we use a DC gear motor which is shown below

Fig. 8.2 DC Geared Motor

10.2 Schematic diagram of Machine (dc motor)


11.LM 35 Sensor

The main part which is responsible for converting temperature into


voltage is LM 35 temperature sensor which acts as a transducer which converts
temperature into electrical quantity (voltage).
The LM35 series are precision integrated-circuit temperature sensors,
whose output voltage is linearly proportional to the Celsius (Centigrade)
temperature. The LM35 thus has an advantage over linear temperature sensors
calibrated in Kelvin, as the user is not required to subtract a large constant
voltage from its output to obtain convenient Centigrade scaling. The LM35
does not require any external calibration or trimming to provide typical
accuracies of 14C at room temperature and 34cover a full 55 to +150C
temperature range. Low cost is assured by trimming and calibration at the
water level. The LM35s low output impedance, linear output, and precise
inherent calibration make interfacing to readout or control circuitry especially
easy. It can be used with single power supplies, or with plus and minus
supplies. As it draws only 60 A from its supply, it has very low self-heating,
less than 0.1C in still air. The LM35 is rated to operate over a 55 to +150C
temperature range, while the LM35C is rated for a 40 to +110C range (10
with improved accuracy).
The LM35 series is available packaged in hermetic TO-46 transistor
packages, while the LM35C, LM35CA, and LM35D are also available in the
plastic TO-92 transistor package. The LM35D is also available in an 8-lead
surface mount small outline package and a plastic TO-220 package.

11.1 Features:
Calibrated directly in Celsius (Centigrade)

Linear + 10.0 mV/C scale factor

0.5C accuracy guarantee able (at +25C)

Rated for full 55 to +150C range

Suitable for remote applications

Low cost due to wafer-level trimming

Operates from 4 to 30 volts

Less than 60 A current drain

Low self-heating, 0.08C in still air

Nonlinearity only 14C typical

Low impedance output, 0.1 W for 1 mA load

11.2 Block diagram of LM35:


11.3 Applications:

The LM35 can be applied easily in the same way as other integrated-
circuit temperature sensors. It can be glued or cemented to a surface and its
temperature will be within about 0.01C of the surface temperature. This
presumes that the ambient air temperature is almost thesame as the surface
temperature; if the air temperature were much higher or lower than the surface
temperature, the actual temperature of the LM35 die would be at an
intermediate temperature between the surface temperature and the air
temperature. This is expecially true for the TO-92 plastic package, where the
copper leads are the principal thermal path to carry heat into the device, so its
temperature might be closer to the air temperature than to the surface
temperature. To minimize this problem, be sure that the wiring to the LM35, as
it leaves the device, is held at the same temperature as the surface of interest.
The easiest way to do this is to cover up these wires with a bead of epoxy
which will insure that the leads and wires are all at the same temperature as the
surface, and that the LM35 dies temperature will not be affected by the air
temperature.
The TO-46 metal package can also be soldered to a metal surface
or pipe without damage. Of course, in that case the V terminal of the circuit
will be grounded to that metal. Alternatively, the LM35 can be mounted inside
a sealed-end metal tube, and can then be dipped into a bath or screwed into a
threaded hole in a tank. As with any IC, the LM35 and accompanying wiring
and circuits must be kept insulated and dry, to avoid leakage and corrosion.
This is especially true if the circuit may operate at cold temperatures where
condensation can occur. Printed-circuit coatings and varnishes such as
Humiseal and epoxy paints or dips are often used to insure that moisture
cannot corrode the LM35 or its connections. These devices are sometimes
soldered to a small light-weight heat fin, to decrease the thermal time constant
and speed up the response in slowly-moving air. On the other hand, a small
thermal mass may be added to the sensor, to give the steadiest reading despite
small deviations in the air temperature. Like most micro power circuits, the
LM35 has a limited ability to drive heavy capacitive loads. The LM35 by itself
is able to drive 50 pf without special precautions. If heavier loads are
anticipated, it is easy to isolate or decouple the load with aresistor;. Or you can
improve the tolerance of capacitance with a series R-C damper from output to
ground.
When the LM35 is applied with a 200W load resistor as it is relatively
immune to wiring capacitance because the capacitance forms a bypass from
ground to input, not on the output. However, as with any linear circuit
connected to wires in a hostile environment, its performance can be affected
adversely by intense electromagnetic sources such as relays, radio transmitters,
motors with arcing brushes, SCR transients, etc, as its wiring can act as a
receiving antenna and its internal junctions can act as rectifiers. For best results
in such cases, a bypass capacitor from VIN to ground and a series R-C damper
such as 75W in series with 0.2 or 1 F from output to ground are often useful.
LM 35 is measure the temperature in degree Celsius unlike LM 34
which measure the temperature in Fahrenheit.

11.4 PIN DIAGRAM OF LM 35:

12. VIBRATION SENSOR

12.1 I N T R O D U C T I O N

This sensor buffers a piezoelectric transducer. As the transducer is


displaced from the mechanical neutral axis, bending creates strain within the
piezoelectric element and generates voltages. This sensor works on 5v. It
gives Digital high (5V) output whenever vibration is detected. The Vibration
Sensor Detector is designed for the security practice When Vibration Sensor
Alarm recognizes movement or vibration, it sends a signal to controller.
It works on electromechanical principle. Vibration velocity sensors
operate in accordance with the electrodynamics principle and are used for
measuring the bearing absolute vibration based on the piezoelectric effect.
Change in resistance due to the force acting on it and convert it into 4 -20 mA.
We have piezoelectric sensor which detects the vibration created on the
surface. We can also use shock sensor to detect vibrations.

12.2 P I N C O N F I G U R AT I O N

1. VCC : Input voltage (2.5 5V)


2. GND : Ground.
3. D0 : Digital OUT.

1.VCC
2 .G
ND
3.D-OUT
12.3 F E AT U R E S
Operating voltage: 5V DC
Output pattern: digital pulse
Frequency Range: 0.5HZ ~ 20HZ
Low cost

12.4 A D VA N TA G E S
Since the output is of digital pattern it is easy to use
Immune to water and oil on the object surface
High stability, with few secular changes

12.5 A P P L I C AT I O N S
Measurements on Structures or Machinery Casings: Accelerometers
and Velocity Sensors
These sensors detect high frequency vibration signals related to bearing
supports, casing and foundation resonances, vibration in
turbine/compressor vanes, defective roller or ball bearings, noise in
gears, etc.

12.6 D E V I C E I M A G E

Vibration Sensor
12.7 Block Diagram for Vibration Sensor
13. MQ-06 Gas Sensor
13.1 FEATURES
* High sensitivity to LPG, iso-butane, propane
* Small sensitivity to alcohol, smoke.
* Fast response .
* Stable and long life
* Simple drive circuit
13.2 APPLICATIONS

They are used in gas leakage detecting equipments in family and


industry, are suitable for detecting of LPG, iso-butane, propane, LNG, avoid
the noise of alcohol and cooking fumes and cigarette smoke.

13.3 SPECIFICATIONS
A. Standard Work Condition

D. Structure and configuration, basic measuring circuit


Structure and configuration of MQ-6 gas sensor is shown as Fig. 1
(Configuration A or B), sensor composed by micro AL2O3 ceramic tube, Tin
Dioxide (SnO2) sensitive layer, measuring electrode and heater are fixed into a
crust made by plastic and stainless steel net. The heater provides necessary
work conditions for work of sensitive components. The enveloped MQ-6 have
6 pin ,4 of them are used to fetch signals, and other 2 are used for providing
heating current.
Electric parameter measurement circuit is shown as Fig.2
E. Sensitivity characteristic curve
Fig.2 sensitivity characteristics of the MQ-6
13.4 SENSITVITY ADJUSTMENT

Resistance value of MQ-6 is difference to various kinds and various


concentration gases. So, When using this components, sensitivity adjustment is
very necessary. we recommend that you calibrate the detector for 1000ppm of
LPG concentration in air and use value of Load resistance ( RL) about
20K(10K to 47K). When accurately measuring, the proper alarm point
for the gas detector should be determined after considering the temperature and
humidity influence.
13.5 Block Diagram of LPG Sensor

13.6 Image of GAS Sensor

MQ-06 Sensor
CHAPTER 10
Servo Motor

Tiny and lightweight with high output power. Servo can rotate approximately
180 degrees (90 in each direction), and works just like the standard kinds but
smaller. You can use any servo code, hardware or library to control these
servos. Good for beginners who want to make stuff move without building a
motor controller with feedback & gear box, especially since it will fit in small
places. It comes with a 3 horns (arms) and hardware.

14.1 Specifications

Weight: 9 g
Dimension: 22.2 x 11.8 x 31 mm approx.
Stall torque: 1.8 kgfcm
Operating speed: 0.1 s/60 degree
Operating voltage: 4.8 V (~5V)
Dead band width: 10 s
Temperature range: 0 C 55 C

Position "0" (1.5 ms pulse) is middle, "90" (~2 ms pulse) is all the way to the
left. "-90" (~1 ms pulse) is middle, "90" (~2 ms pulse) is all the way to the
right, " the left. ms pulse) is all the way to the right,

The servo motor has three leads. The color of the leads varies between
servo motors, but the red lead is always 5V and GND will either be black or
brown. The other lead is the control lead and this is usually orange or yellow.
This control lead is connected to digital pin 9.The servo is conveniently
terminated in a socket into which we can push jumper wires, to link it to the
breadboard and then to the Arduino.

Servos have integrated gears and a shaft that can be precisely


controlled. Standard servos allow the shaft to be positioned at various angles,
usually between 0 and 180 degrees. Continuous rotation servos allow the
rotation of the shaft to be set to various speeds.Servos draw considerable
power, so if you need to drive more than one or two, you'll probably need to
power them from a separate supply (i.e. not the +5V pin on your Arduino
CHAPTER 11
HC-05 BLUETOOTH MODULE

15.1 INTRODUCTION

In this guide, I will explain how to use Arduino to change the settings
of the ubiquitous HC-05 Bluetooth module using the AT command set. The
HC-05 comes with a rich set of AT commands to perform various tasks such as
changing the module's default settings including changing the pass code, the
device name, and module's default settings including changing the pass code,
the device name, and the baud rate. But the process of switching the HC-05
into AT command mode for first time users of the module is not straight
forward and the docs takes short cuts. There are a couple of ways to do this. I
have picked the one I think is the easiest I will do my best to illustrate the
process in simple to follow steps. You can find the full set of AT commands in
the attached datasheet.

15.2 BACKGROUND

The HC-05 Bluetooth module and its siblings are by far the most
popular and in expensive Bluetooth modules used for RF communications by
microcontroller hackers. It costs less than $10 on ebay and it's easy to
implement. I have published two guides based on the HC-05 Bluetooth
module. The first guide explains how to use the HC-05 with the Arduino. The
second is an Android app that simplifies controlling Arduino from your smart
phone over Bluetooth using the HC-05. In both cases, the default settings for
the HC-05 were fine.
In the process of using the HC-05 for a project, I ran into a situation
where I needed to change the defaults for the module. For example, the default
baud rate on the HC-05 is 9600. That's slow for high-speed transmission. The
HC-05 can go as high as 1382400 baud rate according to the HC-05 reference.
Also, the HC-05 has a default device name of HC-05. Having two or more of
those devices in the same area can be confusing. You can use an AT command
to change the device name. Also, the pin code default is 1234. You may wish to
change that for some projects to ensure basic security.
After spending some time searching the web I realized many people are
having a hard time changing the default settings for the HC-05. Switching the
HC-05 from data transmission mode to configuration mode, to send AT
commands to the HC05, involves a few wiring and software acrobatics. Add to
the mix all the variations of the HC Bluetooth module family and the various
vendor settings and you get the picture.

15.3 WARNING
The HC-05 is a 3.3V system but the breakout board offers current
limiting resistors for some protection. While it's not advisable to keep the HC-
05 connected to the 5V Arduino Uno pins, for this short exercise I decided to
skip the voltage dividers which I use to drop 5V to 3.3V. I advise you to use
voltage dividers whenever you connect the HC-05 pins to 5V pins such as the
Arduino Uno. If you skip the voltage divider, do so at your own risk.
Step 1: Components & Wiring
I have tested this guide with the following:

PARTS

HC-05 Bluetooth module (Bluetooth over serial)

Arduino Uno R3

Breadboard & jumper wires

Arduino IDE

WIRING

HC-05 GND --- Arduino GND Pin

HC-05 VCC (5V) --- Arduino 5V

HC-05 TX --- Arduino Pin 10 (soft RX)

HC-05 RX --- Arduino Pin11 (soft TX)

HC-05 Key (PIN 34) --- Arduino Pin 9


Step 2: The Arduino Code for HC-05 Command Mode

This arduino program (hc_05.ino) does two things. it takes the at commands
you enter from the arduino ide serial monitor and sends those commands to the
hc-05. the program then reads the output of the hc-05 and displays it on the
arduino ide serial monitor. you can also use a terminal emulator such as tera
term instead of the arduino serial monitor. the arduino communicates with the
hc-05 using the software serial ports while the arduino communicates with the
user via the serial monitor.

/*

AUTHOR: HazimBitar(techbitar)

DATE:Aug29,2013
LICENSE: Publicdomain(use at your own risk)

CONTACT: techbitar at gmail dot com(techbitar.com)

*/

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()

pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key

pin) HIGH to switch module to AT mode

digitalWrite(9, HIGH);

Serial.begin(9600);

Serial.println("Enter AT commands:");

BTSerial.begin(38400); // HC-05 default speed in AT command

more

void loop()

// Keep reading from HC-05 and send to Arduino Serial Monitor

if (BTSerial.available())

Serial.write(BTSerial.read());
// Keep reading from Arduino Serial Monitor and send to HC-05

if (Serial.available())

BTSerial.write(Serial.read());

Step 3: Steps to Switch the HC-05 Into Command


Mode
For the HC-05 module to switch to AT command mode, the HC-05 pin
34 (often referred to as the Key pin) needs to pulled HIGH but in a certain
order of events explained below. When the HC-05 enters the AT command
mode, it will communicate at 38400 baud rate. Follow these steps in the stated
order to switch to the HC-05 to AT command mode.

1. Wire the HC-05 and Arduino Uno per instructions.

2. BEFORE YOU CONNECT THE ARDUINO TO THE USB remove the


VCC (power) red wire from the HC-05 so it's not getting any power from
the Arduino. All other wires are still connected.

3. Now connect the Arduino Uno to the USB cable extended from your
PC.

4. Make sure the HC-05 module is NOT PAIRED with any other
Bluetooth device.

5. Re-connect the Arduino Uno 5V wire to the HC-05's VCC (5V power)
pin.

6. The HC-05 LED will blink on and off at about 2 second intervals. Now
the HC-05 is in AT command mode ready to accept commands to change
configuration and settings.

7. To test if everything is wired correctly, open the Serial Monitor from


the Arduino IDE and type "AT" and click SEND. You should see an "OK"

8. If you don't see an "OK" check your wiring.

Step 4: Example HC-05 AT Commands

You can send AT Commands to the HC-05 from the Arduino IDE Serial
Monitor while the Arduino is running the attached Arduino program.
I have listed a few popular AT commands that will change the HC-05 device
name, pass code, and speed. You will find a full set of AT commands from the
attached HC-05 reference PDF file.

(remove double quotes from AT command)

To return HC-05 to mfg. default settings: "AT+ORGL"

To get version of your HC-05 enter: "AT+VERSION?"

To change device name from the default HC-05 to let's say MYBLUE
enter: "AT+NAME=MYBLUE"

To change default security code from 1234 to 2987 enter:


"AT+PSWD=2987"

To change HC-05 baud rate from default 9600 to 115200, 1 stop bit, 0
parity enter: "AT+UART=115200,1,0"

Anda mungkin juga menyukai