Arduino Home-Automation PDF
Arduino Home-Automation PDF
TSOP 1738
Page 1
1. ARDUINO UNO
1.1 Introduction to Arduino UNO
Arduino is a popular open-source single-board microcontroller, descendant of the opensource Wiring platform, designed to make the process of using electronics in multidisciplinary projects more accessible. The hardware consists of a simple open hardware design for the Arduino board with an Atmel AVR processor and onboard input/output support. The software consists of a standard programming language compiler and the boot loader that runs on the board. Arduino hardware is programmed using a Wiring-based language (syntax and libraries), similar to C++ with some slight simplifications and modifications, and a Processingbased integrated development environment. Current versions can be purchased pre-assembled;. Additionally, variations of the Italianmade Arduinowith varying levels of compatibilityhave been released by third parties; some of them are programmed using the Arduino software.The Arduino project received an honorary mention in the Digital Communities category at the 2006 Prix Ars Electronica.
Page 2
An Arduino board consists of an 8-bit Atmel AVR microcontroller with complementary components to facilitate programming and incorporation into other circuits. An important aspect of the Arduino is the standard way that connectors are exposed, allowing the CPU board to be connected to a variety of interchangeable add-on modules known as shields. Official Arduinos have used the megaAVR series of chips, specifically the ATmega8, ATmega168, ATmega328, ATmega1280, and ATmega2560. A handful of other processors have been used by Arduino compatibles. Most boards include a 5 volt linear regulator and a 16 MHz crystal oscillator (or ceramic resonator in some variants), although some designs such as the LilyPad run at 8 MHz and dispense with the onboard voltage regulator due to specific form-factor restrictions. An Arduino's microcontroller is also pre-programmed with a boot loader that simplifies uploading of programs to the on-chip flash memory, compared with other devices that typically need an external programmer.
At a conceptual level, when using the Arduino software stack, all boards are programmed over an RS-232 serial connection, but the way this is implemented varies by hardware version. Serial Arduino boards contain a simple inverter circuit to convert between RS-232level and TTL-level signals. Current Arduino boards are programmed via USB, implemented using USB-to-serial adapter chips such as the FTDI FT232. Some 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 ISP programming is used.
The Arduino board exposes most of the microcontroller's I/O pins for use by other circuits. The Diecimila, now superseded by the Duemilanove, for example, provides 14 digital I/O pins, six of which can produce pulse-width modulated signals, and six analog inputs. These pins are on the top of the board, via female 0.1 inch headers. Several plug-in application shields are also commercially available.
The Arduino Nano, and Arduino-compatible Bare Bones Board and Boarduino boards provide male header pins on the underside of the board to be plugged into solderless breadboards.
Page 3
Page 4
void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: }
setup()
The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board.
loop()
After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.
Page 5
1.4 Software
Arduino Software
A screenshot of the Arduino IDE showing the "Blink" program, a simple beginner program.
Developer(s)
Arduino Software
Stable release
Written in
Java
Operating system
Cross-platform
Type
License
Website
http://arduino.cc
Page 6
The Arduino IDE is a cross-platform application written in Java, and is derived from the IDE for the Processing programming language and the Wiringproject. It is designed to introduce programming to artists and other newcomers unfamiliar with software development. It includes a code editor with features such as syntax highlighting, brace matching, and automatic indentation, and is also capable of compiling and uploading programs to the board with a single click. There is typically no need to edit makefiles or run programs on a command-line interface. Although building on command-line is possible if required with some third-party tools such as Ino.
The Arduino IDE comes with a C/C++ library called "Wiring" (from the project of the same name), which makes many common input/output operations much easier. Arduino programs are written in C/C++, although users only need define two functions to make a runnable program:
setup() a function run once at the start of a program that can initialize settings loop() a function called repeatedly until the board powers off
A typical first program for a microcontroller simply blinks a LED on and off. In the Arduino environment, the user might write a program like this:[15] #define LED_PIN 13 void setup () { pinMode (LED_PIN, OUTPUT); }
void loop () { digitalWrite (LED_PIN, HIGH); // turn on the LED delay (1000); // wait one second (1000 milliseconds) digitalWrite (LED_PIN, LOW); // turn off the LED delay (1000); // wait one second } For the above code to work correctly, the positive side of the LED must be connected to pin 13 and the negative side of the LED must be connected to ground. The above code would not be seen by a standard C++ compiler as a valid program, so when the user clicks the "Upload to I/O board" button in the IDE, a copy of the code is written to a temporary file with an extra include header at the top and a very simple main() function at the bottom, to make it a valid C++ program. The Arduino IDE uses the GNU toolchain and AVR Libc to compile programs, and uses avrdude to upload programs to the board. For educational purposes there is third party graphical development environment called Minibloq available under a different open source license.
Page 7
Page 8
1. Click the Driver tab on the Arduino Uno properties window, then click
Update Driver...
Page 9
4. Click Next.
5. Click Close.
Page 10
6. The Arduino Uno should now be listed under Ports(COM&LPT) in the Windows Device Manager.
Page 11
Basic Usage
IRremote acts like 2 libraries, one for sending and one for receiving. Usually it's easiest to find the codes to transmit by first using the receiver.
Receiving
IRrecv irrecv(receivePin) Create the receiver object, using a name of your choice. irrecv.enableIRIn() Begin the receiving process. This will enable the timer interrupt which consumes a small amount of CPU every 50 s. irrecv.decode(&results) Attempt to receive a IR code. Returns true if a code was received, or false if nothing received yet. When a code is received, information is stored into "results". results.decode_type: Will be one of the following: NEC, SONY, RC5, RC6, or UNKNOWN. results.value: The actual IR code (0 if type is UNKNOWN) results.bits: The number of bits used by this code results.rawbuf: An array of IR pulse times results.rawlen: The number of items stored in the array irrecv.resume() After receiving, this must be called to reset the receiver and prepare it to receive another code. irrecv.blink13(true) Enable blinking the LED when during reception. Because you can't see infrared light, blinking the LED can be useful while troubleshooting, or just to give visual feedback.
Page 12
2. Description of reciver TSOP17-The TSOP17.. series are miniaturized receivers forinfrared remote control systems. PIN diode and preamplifier are assembled on lead frame, the epoxy package is designed as IR filter. The demodulated output signal can directly be decoded by a microprocessor. TSOP17.. is the standard IR remote control receiver series, supporting all major transmission codes.
Fig.2.1 TSOP1738 Receiver Features Photo detector and preamplifier in one package Internal filter for PCM frequency Improved shielding against electrical field disturbance TTL and CMOS compatibility Output active low Low power consumption High immunity against ambient light Continuous data transmission possible (up to 2400 bps)
Page 13
Protocol Details:
The basics of the protocol are well known. The handset contains a keypad and a transmitter integrated circuit (IC) driving an IR LED. The command data is a Manchester coded bitstream modulating a 36 kHz carrier. (Often the carrier used is 38 kHz or 40 kHz, apparently due to misinformation about the actual protocol.) The IR signal from the transmitter is detected by a specialized IC with an integral photo-diode, and is amplified, filtered, and demodulated so that the receiving device can act upon the received command. RC-5 only provides a one-way link, with information traveling from the handset to the receiving unit. The command comprises 14 bits:
A start bit, which is always logic 1 and allows the receiving IC to set the proper gain. A field bit, which denotes whether the command sent is in the lower field (logic 1 = 0 to 63 decimal) or the upper field (logic 0 = 64 to 127 decimal). The field bit was added later by Philips when it was realized that 64 commands per device were insufficient. Previously, the field bit was combined with the start bit. Many devices still use this original system. A control bit, which toggles with each button press. This allows the receiving device to distinguish between two successive button presses (such as "1", "1" for "11") as opposed to the user simply holding down the button and the repeating commands being interrupted by a person walking by, for example. A five-bit system address, that selects one of 32 possible systems. A six-bit command, that (in conjunction with the field bit) represents one of the 128 possible RC-5 commands.
The 36 kHz carrier frequency was chosen to render the system immune to interference from TV scan lines. Since the repetition of the 36 kHz carrier is 27.778 s and the duty factor is 25%, the carrier pulse duration is 6.944 s. Since the high half of each symbol (bit) of the RC-5 code word contains 32 carrier pulses, the symbol period is 64 x 27.778 s = 1.778 ms, and the 14 symbols (bits) of a complete RC-5 code word takes 24.889 ms to transmit. The code word is repeated every 113.778 ms (4096 / 36 kHz) as long as a key remains pressed. (Again, please note that these timings are not strictly followed by all manufacturers, due to a lack of widespread distribution of accurate information on the RC-5 protocol.)
Page 14
Page 15
Page 16
4) Circuit diagram :-
Page 17
Programme:-
void onoff(int p); int FAN = 7; int LIGHT1 = 2; int AC =13 int RECV_PIN =5; IRrecv irrecv(RECV_PIN); decode_results results; long a,e; int p; void setup() { long a=0,b=0,c=0,d=0; pinMode(1,OUTPUT); pinMode(7,OUTPUT); pinMode(2,OUTPUT); pinMode(13,OUTPUT); Serial.begin(9600); irrecv.enableIRIn(); irrecv.blink13(true); }
//function for switching on/off the device //Declaration: Device-1 is connected to the 7th pin //Declaration: Device-1 is connected to the 2nd pin //Declaration: Device-1 is connected to the 13th pin //Declaration: Receiver is connected to the 3rd pin //Declaration of Receiving object //received code stored in results will be decoded //variables for decoding //variable for device-choice //Initialize the settings and runs once tine
//Declaration:Pin-1 act as output pin //Declaration:Pin-7 act as output pin //Declaration:Pin-2 act as output pin //Declaration:Pin-13 act as output pin //Serially receives at 9600 baud rate // Start the receiver //LED at 13th pin will blink, if IR receiver receives
Page 18
//value store in decimal in variable a //Serially print value in serial shif monitor
{ e = results.value,DEC; switch (e) { case 12582919: p=7; delay(1000); onoff(p); break; case 12582914: p=2; delay(1000); onoff(p); break; // Syntax to CALL a Function //code of 2nd button of remote //selecting of 2nd device // Syntax to CALL a Function //code of 7th button of remote //selecting of 7th device //value store in decimal in variable e //for checking a code for device
Page 19
default: loop(); } } } void onoff(int p) { label: long m=0; irrecv.resume(); delay(700); irrecv.decode(&results); m= results.value,DEC; if(m == 12583021) { digitalWrite(p,HIGH); } if(m == 12583022) { digitalWrite(p,LOW); } } if(m == 0) { goto label; } return; } //continuous loop until m0 //to switch on the device //checking code for on button //to switch on the device //code of on-off button will store in m in decimal //checking code for on button //reset the receiver for receiving next time
Page 20