Microprocessor and Systems Lab Electrical Engineering Uet Taxila Home Automation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

MICROPROCESSOR AND SYSTEMS LAB

ELECTRICAL ENGINEERING
UET TAXILA
HOME AUTOMATION

Submitted By:

M. Kashif Hassan 15-EE-132

Malik Ahmad 15-EE-180

Talha Habib 15-EE-160

Submitted To:

Engr. Komal

1|Page
After analyzing various protocols, we started working on SONY protocol. It appears that 3
versions of the protocol exist: 12-bit, 15-bit and 20-bit versions. All versions have 7 bits reserved
for the command. The 12-bit version has 5 bits reserved for the address, while the 15-bit version
has 8 bits reserved for the address. Oddly enough the 20-bit version has a 7-bit command and a 5-
bit address length. The extra 8 bits, which follow the address, are called the extended bits. I can
only assume that the extended bits extend either the address range or the command range. But
when would you ever need more than 128 keys anyway.

Sony TV remote:
When you press a button on the remote, the LED sends a special code assigned to that key as a
beam of infrared light pulses. The infrared receiver on the appliance in turn receives that beam of
infrared light pulses and converts it into electrical impulses that correspond to the key code, and
sends those impulses to a computer that controls the appliance. There is a slight problem with
sending on and off pulses of light to represent the binary bits of 1's and 0's--how can the receiver
tell if no signal represents a 0 or just that the remote control is done sending? The Sony protocol
solution is to make a 0 bit a "space" that is .8 milliseconds long, a 1 that is 1.2ms long. Modulation:
The SIRC protocol uses pulse width encoding of the bits. The pulse representing a logical "1" is a
1.2ms long burst of the 40kHz carrier, while the burst width for a logical "0" is 0.6ms long. All
bursts are separated by a 0.6ms long space interval. Th recommended carrier duty-cycle is 1/4 or
1/3.

Protocol:

The picture above shows a typical pulse train of the 12-bit SIRC protocol. With this protocol the
LSB is transmitted first. The start burst is always 2.4ms wide, followed by a standard space of
0.6ms. Apart from signaling the start of a SIRC message this start burst is also used bit is a "space"
that is 1.2 ms long, and a start bit is a "space" that is 2.4 ms long. There is a pause of 0.68 ms
between bits. So when the infrared pulses are being received, a 2.4 ms space pulse is recognized
as a start pulse, a 1.2 ms space pulse is recognized as the 1, and a 0.8 ms space pulse is recognized
as a 0. This is what makes the coding of a remote controller different from RTTY. The picture at
right illustrates the serial stream sent when key 0 is pressed. Overlaid on the oscilloscope pattern
are labels for the individual bits. to adjust the gain of the IR receiver. Then the 7-bit Command is

2|Page
transmitted, followed by the 5- bit Device address. In this case Address 1 and Command 19 is
transmitted. Commands are repeated every 45ms (measured from start to start) for as long as the
key on the remote control is held down. After 12 or 15 bits the receiver must wait at least 10ms to
make sure that no more pulses follow. That way the receiver can decide which one of the 3 possible
SIRC protocols it is receiving.

COMPONENTS

Power supply
ATmega16 AVR Microcontroller
Relay driver IC
7806 regulator
IR Sensor
Relay:
2N2222A Transistor
IR Receiver
IR Remote
Bulbs

Block Diagram:

3|Page
CONNECTIONS:
Connections of atmega16
Pin 16 of atmega16 is connected to tsop1738 ir reciver.
Pin 33-40 (portA) are declared as output ports.
Pin 10 and 30 are shorted and connected to Vcc. Pin 11 and 31 are shorted and connected
to ground.
Connections of ULN2803
Pin 1 is connected to pin 40 of atmega16.
Pin 2 is connected to pin 39 of atmega16.
Pin 16 and 17 are connected to two relays, separately.
CIRCUIT DIAGRAM

4|Page
5|Page
TSOP 1738:
The TSOP 1738 is a member of IR remote control receiver series. This IR sensor module
consists of a PIN diode and a pre-amplifier which are embedded into a single package. The
output of TSOP is active low and it gives +5V in off state. When IR waves, from a source, with a
center frequency of 38 kHz incident on it, its output goes low.

Relay

Relay is an electromagnetic device which is used to isolate two circuits electrically and connect
them magnetically. They are very useful devices and allow one circuit to switch another one
while they are completely separate. They are often used to interface an electronic circuit
(working at a low voltage) to an electrical circuit which works at very high voltage. For example,
a relay can make a 5V DC battery circuit to switch a 230V AC mains circuit. Thus a small sensor
circuit can drive, say, a fan or an electric bulb. A relay switch can be divided into two parts:
input and output. The input section has a coil which generates magnetic field when a small
voltage from an electronic circuit is applied to it. This voltage is called the operating voltage.
Commonly used relays are available in different configuration of operating voltages like 6V, 9V,
12V, 24V etc. The output section consists of contactors which connect or disconnect
mechanically. In a basic relay there are three contactors: normally open (NO), normally closed
(NC) and common (COM). At no input state, the COM is connected to NC. When the operating

6|Page
voltage is applied the relay coil gets energized and the COM changes contact to NO. Different
relay configurations are available like SPST, SPDT, and DPDT etc, which have different number
of changeover contacts. By using proper combination of contactors, the electrical circuit can be
switched on and off. Get inner details about structure of a relay switch The Pin description of th

CODE
#include <mega16.h>

#include <delay.h>

#define relay1 PORTA.0

#define relay2 PORTA.1

#define relay3 PORTA.2

#define relay4 PORTA.3

unsigned char pulseCount, timerCount, count, code, address;

7|Page
//*********************************************************************
//Function to read IR message from the detector
//Return value contains code in upper byte and address in lower byte
//*********************************************************************

void read_IR ()

pulseCount=0, code = 0, address = 0;

while(pulseCount < 7)

while(PIND & 0x04);

TCNT0 = 0;

while(!(PIND & 0x04));

pulseCount++;

timerCount = TCNT0;

if(timerCount > 14)

code = code | (1 << (pulseCount-1));

else

code = code & ~(1 << (pulseCount-1));

pulseCount = 0;

while(pulseCount < 5)

while(PIND & 0x04);

TCNT0 = 0;

8|Page
while(!(PIND & 0x04));

pulseCount++;

timerCount = TCNT0;

if(timerCount > 14)

address = address | (1 << (pulseCount-1));

else

address = address & ~(1 << (pulseCount-1));

}}

void relays()

if (address != 1)

{return;}

switch(code)

case 1: {

relay1=~relay1;

break;

case 2:

relay2=~relay2;

break;

case 3;

9|Page
{

relay3=~relay3;

break;

case 4:

relay4=~relay4;

break;

case 21:

relay1=~relay1;

relay2=~relay2;

relay3=~relay3;

relay4=~relay4;

break;

} }}

interrupt [EXT_INT0] void ext_int0_isr(void)

{ #asm("cli")

TCNT0 = 0;

while(!(PIND & 0x04));

count = TCNT0;

if(count < 30) //to verify start pulse (2.4 ms long)

delay_ms(20);

10 | P a g e
#asm("sei")

return;

read_IR();

relays();

delay_ms(250);

#asm("sei")

void main(void)

PORTA=0x00;

DDRA=0xFF;

PORTD=0x00;

DDRD=0x00;

TCCR0=0x03;

TCNT0=0x00;

GICR|=0x40;

MCUCR=0x02;

GIFR|=0x40;

#asm("sei")

while (1){}}

Reference; http://freecodesforrobotics.blogspot.com/

11 | P a g e
12 | P a g e

You might also like