Embedded System Ch-5 Part-2

Download Report

Transcript Embedded System Ch-5 Part-2

Prepared By: H.D.Shukla
ULN2803
 Each of the digital i/o pins on the Arduino can only source or
sink 40mA, and pushing the Arduino past these limits may
damage it. If you need to get a little more power out of your
outputs, try using a Darlington ULN2803.
 The Darlington chip can source up to 500mA of current out each
pin, and operates at up to 50V, so it's beefy enough to drive
motors, incandescent bulbs, relays, solenoids and more.
 The ULN2803APG / AFWG Series are high−voltage,
high−current darlington drivers comprised of eight NPN
darlington pairs. All units feature integral clamp diodes for
switching inductive loads. Applications include relay, hammer,
lamp
and
display
(LED)
drivers.
Connection of ULN2803 with relay
Interfacing of relay by using
ULN2803
Code
#define RELAY1 0
#define RELAY2 1
#define RELAY3 2
#define RELAY4 3
void setup()
{
// Initialise the Arduino data pins for OUTPUT
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
}
void loop()
{
digitalWrite(RELAY1,HIGH);
//Turn on RELAY - 1
delay(1000);
digitalWrite(RELAY1,LOW);
//Turn off RELAY - 2
digitalWrite(RELAY2,HIGH);
delay(2000);
digitalWrite(RELAY2,LOW);
digitalWrite(RELAY3,HIGH);
delay(2000);
digitalWrite(RELAY3,LOW);
digitalWrite(RELAY4,HIGH);
delay(2000);
digitalWrite(RELAY4,LOW);
}
What is bootloader?
 Atmel AVRs are great little ICs, but they can be a bit tricky to
program. You need a special programmer and some fancy .hex
files, and its not very beginner friendly. The Arduino has largely
done away with these issues. They’ve put a .hex file on their AVR
chips that allows you to program the board over the serial port,
meaning all you need to program your Arduino is a USB cable.
 The bootloader is basically a .hex file that runs when you turn on
the board. It is very similar to the BIOS that runs on your PC. It
does two things. First, it looks around to see if the computer is
trying to program it. If it is, it grabs the program from the
computer and uploads it into the ICs memory (in a specific
location so as not to overwrite the bootloader). That is why when
you try to upload code, the Arduino IDE resets the chip. This
basically turns the IC off and back on again so the bootloader
can start running again. If the computer isn’t trying to upload
code, it tells the chip to run the code that’s already stored in
memory. Once it locates and runs your program, the Arduino
continuously loops through the program and does so as long as
the board has power.
Burning the bootloader
 To burn the bootloader, you'll need to buy an AVR-ISP (in-
system
programmer),
USBtinyISP
or
build
aParallelProgrammer. The programmer should be
connected to the ICSP pins (the 2 by 3 pin header) - make
sure you plug it in the right way. The board must be
powered by an external power supply or the USB port.
 Make sure you have the right item selected in the Tools |
Board menu. Then, just launch the appropriate command
from the Tools > Burn Bootloader menu of the Arduino
environment. Burning the bootloader may take 15 seconds
or more, so be patient.
How to burn bootloader?
 For a quick easy programmer we recommend looking into
the AVR Pocket Programmer (Windows only) Or, you can use
the official Atmel AVR MKII programmer.
 The AVR Pocket Programmer or most cheaper options will work
just fine for most applications, but they may have problems with
some boards, specifically ones with lots of memory like the
ATMega2560 based boards.
Continue….
 In circuit serial programmer
 It’s very uncommon to program ICs before they are
soldered onto a PCB. Instead, most microcontrollers
have what’s called an in-system programming (ISP)
header. Particularly, some IC manufacturers, such as
Atmel and Microchip, have a specialized ISP method for
programming their ICs. This is referred to as in-circuit
serial programming (ICSP) Most Arduino and Arduino
compatible boards will have a 2x3 pin ICSP header on
them. Some may even have more than one depending on
how many ICs live on the PCB. It breaks out three of
the SPI pins (MISO, MOSI, SCK), and power, ground,
and reset. These are the pins you’ll need to connect your
programmer to in order to reflash the firmware on your
board.
Continue…
Continue….
 Once you have located the six ICSP pins on your
board, it’s time to hook up your programmer to the
board. You can use a programming cable to connect
the two, or, if you don’t have a cable, you can just use
some male-to-female jumper wires.
 If you are using a programmer such as the MKII or the
Pocket Programmer, your setup should look
something like this:
Continue…
 Now, after connecting above circuit diagram follow these
steps
 Step1: Select your appropriate target board. Tools -> Board
Continue…
 Step2: Now select the proper programmer that you have chosen
for the burning of program on arduino. Tools -> Programmer
Continue…
 Step 3: Now you are ready to burn bootloader on your
arduino board. Just select Tools -> Burn bootloader
ATmega8 Basic Circuit diagram
Arduino basic circuit diagram
Design Embedded Development
Board
 Suppose you have an Arduino board, and you want to
run a code independently on another blank Atmega8
IC.
 First of all, u need to burn a bootloader on to the
atmega8, using the Arduino as an ISP.
 Once the bootloader is uploaded, u can now upload a
simple sketch like Led blink on the new IC, and check
whether the program works by connecting the IC on
the breadboard.
 Once checked on the breadboard, u can now go
happy-soldering on a pcb.
Continue…
 Step 1 :Upload ArduinoISP code on ur UNO
Connect ur UNO to ur PC via the USB cable and
go to File -> Examples -> ArduinoISP and upload this
sketch.
 Step 2 :Burn the bootloader
Connect ur Atmega (Atmega8 in my case) to the
UNO via a breadboard as shown.
Continue…
 Now get the arduino IDE
 then u burn the bootloader in 2 steps :
 Step 1: Select Arduino NG or older w/ Atmega8
Bcoz this board used
Atmega8 and so the bootloader for Atmega8 would b selected.
Step: 2 Now select Tools -> Burn Bootloader -> w/ Arduino as ISP. Because you
are loading bootloader on ATmega8 with the help of Arduino.
Home Automation using Arduino
 Ever wanted to make your home automated? Wanted
to control the lights, fan and other appliances from
your smartphone? Or wanted a tutorial about
connected devices and getting started with it? DIY
Android Home Automation will show you how to
make your home automated using an android
smartphone. This requires you to have no experience
of android programming at all, as a free application is
included for you to develop. Using this android
application you will be able to control your lights, air
conditioning, door locks ,etc all from your
smartphone. This system uses bluetooth to connect
with your device and control the various appliances in
your home.
Software and Hardware
requirement
 Software
 Arduino IDE : Arduino .
 Eclipse for android programming (optional, not
required).
 Hardware
 Arduino / Arduino Clone or make your own custom




Arduino board with this tutorial.
A 5v TTL -UART Bluetooth module like : JY-MCU
BT_BOARD (Cheaper) or Bluesmirf Gold/Silver.
Five 5V SPDT relays like : 5V relay.
Prototype board or breadboard.
Connecting wires.
How does it work?
 Android Home Automation project comes with a free
application called “DIY SmartHome” . This application
controls the various appliances connected to your arduino
and relays. When the toggle buttons on the application are
pressed, corresponding bluetooth signals are sent from
your android phone to the bluetooth module you have
hooked up to your arduino. The arduino finds out which
signal was sent and compares it to the predefined signals
assigned for each appliance. When it identifies that signal,
then the arduino activates the relay hooked up to its digital
pin by passing 5V through it. Thus the relay is switched ON
and the corresponding appliance connected to the relay is
turned ON as well. To switch it OFF , arduino passes a 0V
or logic low to its digital pin.
Block Diagram
Circuit Diagram
Circuit Diagram
Connection
 The connection diagram for arduino is as shown. For
setting up this system , wiring connections have to be
made between the arduino and bluetooth module and
also with the relays. Here, the bluetooth module’s Tx is
connected to arduino Rx (digital pin 0) and the
module’s Rx to arduino Tx (digital pin 1). 5V and GND
of the module is connected to the arduino’s 5V and
GND.
 The relay your using is SPDT, it has 5 pins on the under
side. As shown above , here pins 1 and 3are the coil
pins. 1 is connected to the arduino digital pin and 3 is
connected to arduino GND. 2 is the common contact
in the relay to which you have to connect the power for
your appliance (AC 230V), and 4 is the pin to which
you have to connect your appliance wire.
PCB Layout
Code
void setup()
{
Serial.begin(115200);//Change the baud rate value
depending on the default baud rate of your bluetooth
module, for Bluesmirf-115200 and for JY-MCU-9600
pinMode(2, OUTPUT);//Light1 pin
pinMode(3, OUTPUT);//Light2 pin
pinMode(4, OUTPUT);//Light3 pin
pinMode(5, OUTPUT);//AC pin
pinMode(6, OUTPUT);//Door Lock
}
void loop()
{
int a=0;
if(Serial.available())
{
val=Serial.read();
Serial.println(int(val));//Display received value on Serial Monitor
if(int(val)==49)//Turn Light1 ON
digitalWrite(2,HIGH);
else if (int(val)==50)//Turn Light1 OFF
digitalWrite(2,LOW);
if(int(val)==51)//Turn Light2 ON
digitalWrite(3,HIGH);
else if(int(val)==52)//Turn Light2 OFF
digitalWrite(3,LOW);
if(int(val)==53)//Turn Light3 ON
digitalWrite(4,HIGH);
else if(int(val)==54)//Turn Light3 OFF
digitalWrite(4,LOW);
if(int(val)==55)//Turn AC ON
digitalWrite(5,HIGH);
else if(int(val)==56)//Turn AC OFF
digitalWrite(5,LOW);
if(int(val)==57)//Lock the DOOR
digitalWrite(6,HIGH);
else if(int(val)==48)//Unlock the DOOR
digitalWrite(6,LOW);
}
}
Download android application and
setting up Bluetooth
 To download the android application to your phone, copy t
.apk file of android application to your phone from the PC
and then click on it from the phone to install it.
 Once you have installed the application, before opening it
you need to pair and connect with your bluetooth module.
For this, you need to power the arduino and bluetooth
module and then turn ON the bluetooth of your phone and
make it visible to other devices. After that, search for new
devices in bluetooth, select your bluetooth module from
the list, enter the pairing code when prompted , it is usually
’1234′ or ’0000′ .
Continue…
 Note the name of your device , in this case it is “HC-
06″. After pairing with the system, go to the “DIY
SmartHome” application and enter the name of your
bluetooth module you noted earlier (case-sensitive)
and click “OK”. After that the phone will get connected
to your system , and on clicking the respective buttons,
the appliances turn ON/OFF. Have fun with your new
DIY Android Home Automation system
Connection Bluetooth
Interfacing RF transmitter with
Arduino
 RF transmitter technical specification
1. Product Model: MX-FS-03V
2. Launch distance :20-200 meters (different voltage,
different results)
3. Operating voltage :3.5-12V
4. Dimensions: 19 * 19mm
5. Operating mode: AM
6. Transfer rate: 4KB / S
7. Transmitting power: 10mW
8. Transmitting frequency: 315Mhz
9. An external antenna: 25cm ordinary multi-core or
single-core line
10. Pinout from left → right: (DATA; VCC; GND)
Continue…
 RF receiver technical specification
1. Product Model: MX-05V
2. Operating voltage: DC5V
3. Quiescent Current: 4mA
4. Receiving frequency:315Mhz
5. Receiver sensitivity:-105DB
6. Size: 30 * 14 * 7mm
Circuit Diagram
Code for RF transmitter
#include <VirtualWire.h>
char *controller;
void setup()
{
pinMode(13,OUTPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
}
void loop()
{
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,1);
delay(2000);
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(2000);
}
Code for RF receiver
#include <VirtualWire.h>
void setup()
{
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(12);
vw_setup(4000); // Bits per sec
pinMode(13, OUTPUT);
vw_rx_start();
// Start the receiver PLL running
}
void loop()
{
int buf[VW_MAX_MESSAGE_LEN];
int buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if(buf[0]=='1')
{
digitalWrite(13,1);
}
if(buf[0]=='0')
{
digitalWrite(13,0);
}
}
}