An
economical Infra-Red based home automation module, for wireless control of
electrical appliances using a very cheap TV/DVD player remote controller. The
prototyped version uses arduino uno as microcontroller, three transistors and
relays for switching three 230V/15W bulbs, IR TSOP receiver (1738), old VCR
remote controller and some passive components.
Theory of Operation:
The cheapest way to remotely control a device within a visible
range is via Infra-Red light. Almost all audio and video equipment can be
controlled this way nowadays. Due to this wide spread use the required
components are quite cheap, thus making it ideal for to use IR based control
for this project.
Infra-Red actually is normal
light with a particular colour. We humans can't see this colour because its
wave length of 950nm is below the visible spectrum. That's one of the reasons
why IR is chosen for remote control purposes, we want to use it but we're not
interested in seeing it. Another reason is because IR LEDs are quite easy to
make, and therefore can be very cheap.Unfortunately, there are many more sources of Infra-Red light. The sun is the brightest source of all, but there are many others, like: light bulbs, candles, central heating system, and even our body radiate Infra-Red light. In fact everything that radiates heat also radiates Infra-Red light. Therefore we have to take some precautions to guarantee that our IR message gets across to the receiver without errors.
Modulation is the answer to make our signal stand out above the
noise. With modulation we make the IR light source blink in a particular
frequency. The IR receiver will be tuned to that frequency, so it can ignore
everything else. The standard carrier frequency
used is 38KHz. IR TSOP 1738 has been tuned to 38 KHz, and can ignore everything
else.The method of modulating the signal depends upon the protocol used.
Protocol defines the method of encryption, and is made by the remote controller
manufacturing companies. Common protocols includes NEC (Japan based, common in
India), RC-5(Europe based,
common in India).
This project uses NEC protocol based
remote controller, that transmits Pulse Position Modulated signal at a carrier
frequency of 38KHz. Different protocols have different decoding algorithms. In serial
communication we usually speak of 'marks' (or burst) and 'spaces'. The 'space'
is the default signal, which is the off state in the transmitter case. No light
is emitted during the 'space' state. During the 'mark' state of the signal the
IR light is pulsed on and off at a particular frequency.
At the receiver side a 'space' is
represented by a high level of the receiver's output. A 'mark' is then
automatically represented by a low level. Please note that the 'marks' and
'spaces' are not the 1-s and 0-s we want to transmit. The real relationship
between the 'marks' and 'spaces' and the 1-s and 0-s depends on the protocol
that's being used. Protocol consists of several bits, grouped as address bits,
command bits, start bit, toggle bit,flag bit etc.Some of the protocols will
have more bits specifications where as some may not have.NEC Protocol:
NEC protocol has the following bit specification:
·
a 9ms
leading pulse burst as start bit
·
followed
by a 4.5ms space
·
8-bit
address ( differentiates different types of appliances of the same company)
·
8-bit
inverse of address bits (for verification only)
·
8-bit
command (distinguishes between different buttons on the remote controller)
·
8-bit
inverse of command bits (for verification only)
The NEC protocol uses pulse distance encoding of the bits. Each pulse is a 560µs long 38kHz carrier burst (about 21 cycles). A logical "1" takes 2.25ms to transmit, while a logical "0" is only half of that, being 1.125ms. The recommended carrier duty-cycle is 1/4 or 1/3.
The picture above shows a typical pulse train of the NEC protocol. With this protocol the LSB is transmitted first. A message is started by a 9ms AGC burst, which was used to set the gain of the earlier IR receivers. This AGC burst is then followed by a 4.5ms space, which is then followed by the Address and Command. Address and Command are transmitted twice. The second time all bits are inverted and can be used for verification of the received message. The total transmission time is constant because every bit is repeated with its inverted length. If you're not interested in this reliability you can ignore the inverted values, or you can expand the Address and Command to 16 bits each!

A command is transmitted only once, even when the key on the remote control remains pressed. Every 110ms a repeat code is transmitted for as long as the key remains down. This repeat code is simply a 9ms AGC pulse followed by a 2.25ms space and a 560µs burst.

For fast prototyping and decoding the protocol, an arduino based library
called IRremote.h developed and open sourced by
Ken Shirriff
The IRremote library records the duration of each (modulated) pulse sent
by the remote control. Each key on the remote corresponds to a particular code
value, which is converted to a particular sequence of pulses. The library
generates a unique value for each button press which is distinguishable from
another button press.
It records the duration of successive
pulses. If the pulse is shorter than the previous,0 is assigned. If the pulse
is the same length, 1 is assigned. If the pulse is longer, 2 is assigned. (upon
comparing on-durations with on-durations and off-durations with off-durations.)
The result is a sequence of 0's, 1's, and 2's, then hashing these values into a
32-bit hash value.
Though the prototyped version is based
upon this library, but has proved not very effective due to many limitations
(repeated key press is not processed, platform non independence etc) of the
library. To make this project more cost effective, low cost microcontrollers
like ATmega8 is being used, and direct C programming is being implemented using
standard protocol decoding algorithms and is under way to be completed soon as
a very cost effective end product module. The overall production cost of a
single module is expected to be less than Rs. 150/- .
Future Prospective:
Encrypted IR communication, resistant
to ambient daylight can be utilised for robotic competions like Robocon where there
will be instances for communication between manual and automatic bots;
The project idea can also be expanded
with GSM based mobile communication for building energy conservation modules.
Virtual Grid mapping and swarm
intelligence are some of the future prospective of this project.
Code for the prototyped version(based on IRremote.h library):
//2=484655295
//3=484687935
//1=484671615
//red=484653255
#include
<IRremote.h>
int RECV_PIN = 11;
IRrecv
irrecv(RECV_PIN);
decode_results
results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(3,OUTPUT);
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
pinMode(9,OUTPUT);
digitalWrite(9,LOW);
pinMode(10,OUTPUT);
digitalWrite(10,LOW);
}
void loop() {
if (irrecv.decode(&results))
{
//Serial.println(results.value);
if (results.value==484671615)
{
PORTB ^= (1<<0);//toggle led
Serial.println(digitalRead(8));
digitalWrite(3,HIGH);
delay(100);
digitalWrite(3,LOW);
delay(100);
}
else if(results.value==484655295)
{
PORTB ^= (1<<1);//toggle led
Serial.println(digitalRead(9));
digitalWrite(3,HIGH);
delay(100);
digitalWrite(3,LOW);
delay(100);
}
else if(results.value==484687935)
{
PORTB ^= (1<<2);//toggle led
Serial.println(digitalRead(10));
digitalWrite(3,HIGH);
delay(100);
digitalWrite(3,LOW);
delay(100);
}
else if(results.value==484653255)
{
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(3,HIGH);
delay(100);
digitalWrite(3,LOW);
delay(100);
}
irrecv.resume(); // Receive the next value
}
}


No comments:
Post a Comment