Beruflich Dokumente
Kultur Dokumente
Content s
..
Introduction
Over the last few years, the technologies of Remote control and wireless control spreads extremely fast and play a main role in our life . for example in our houses there are many devices work with remote control like TV , Video set , DVD player .. etc. in addition to that you can control your factory machines and observe them where they are working although you live in other country . Some of these important technologies are : 1- Telephone (DTMF) control system. 2- SMS control system. 3- Internet control system. 4- RF control system . This project explains one of these technologies (SMS control system) and shows how to apply it to your home ,company or factory to control any electrical or electronic devices (like motor , fan ,wash machine , TV , air conditioner , etc) and use a computer software to make a small database or history to show when these devices work and when they stop ? and who given these orders to make them ON or OFF ? .
Abstract
This project designed to control over 8 devices remotely by using SMS short message technology, so that we can control our devices from any place of the world. To make any devices ON or OFF we send a specific SMS message which contains the device name or number and the state which we want (ON , OFF). The message would be like this make a fan ON .make device 3 OFF. This SMS message we sent is received by another mobile(or gsm modem) which connected to a computer and microcontroller circuit. The Computer has software we designed it to store all received SMS messages and its time and date on a database. The microcontroller circuit controls our devices, make them ON or OFF according to SMS message, and can observe any device at any time. If we leave the home and we want to ensure if the air conditioner or other device is ON or OFF we can send a SMS message contain for exampleair conditioner state ? and we will receive another SMS message from our system contains the state of this device like this air conditioner is OFF . This system contains some security features which described in details in security part . One of these features is that if a thief entered your house or company the sensor which connected to microcontroller circuit can detect the thief and send a SMS message to your mobile and the message will be like this your house in dangerous. there is a thief . this sensor is an IR detector or receiver and IR led transmitter . they described in hardware description.
3
Project maps
1- The mechanism to control any device :
send a message from any mobile to know the state of any device
receivng this message by anoter mobile (this mobile attatched to our system)
PC sending an order to microcontroller to know the state of the device. the microcontroller check the device state and send this inofrmation to computer (PC) pc make a mobile send a sms contians the state of device
message received to the user and contains the state of the device
5
computer send message to a house owner " your house is attacing from a theif"
Hardware description
1- Microcontroller : A microcontroller is a single-chip computer. Micro suggests that the device is small, and controller suggests that it is used in control applications. Another term for microcontroller is embedded controller, since most of the microcontrollers are built into (or embedded in) the devices they control. The function of a microcontroller is not constant like other ICs . the function of a microcontroller can be change by a programming process. So, if we have two microcontroller (e.g. pic16f877a) each one may be has a different function although they are same. All microcontrollers operate on a set of instructions (or the user program) stored in their memory. A microcontroller fetches the instructions from its program memory one by one, decodes these instructions, and then carries out the required operations. Microcontrollers have traditionally been programmed using the assembly language of the target device. Although the assembly language is fast, it has several disadvantages. An assembly program consists of mnemonics, which makes learning and maintaining a program written using the assembly language difficult. Also, microcontrollers manufactured by different firms have different assembly languages, so the user must learn a new language with every new microcontroller he orshe uses. Microcontrollers can also be programmed using a high-level language, such as BASIC,PASCAL, or C. High-level languages are much easier to learn than assembly languages. They also facilitate the development of large and complex programs.
Pic16f877a 2-GSM modem : GSM modem is a kind of modems that work with SIM card and we can connect it to computer via serial communication or USB . The modem can send SMS and receive it and other operations, but the most important operation to us is send and receive sms messages. We can read the forward message and send message by giving order to gsm modem these order which a gsm modem can understand it are AT commands.
GSM modem
Transostors
Resistors
10
How relay works? A relay is an electrically operated switch. Current flowing through the coil of the relay creates a magnetic field which attracts a lever and changes the switch contacts. The coil current can be on or off so relays have two switch positions and most have double throw (changeover) switch contacts as shown in the diagram.
Relays allow one circuit to switch a second circuit which can be completely separate from the first. For example a low voltage battery circuit can use a relay to switch a 230V AC mains circuit. There is no electrical connection inside the relay between the two circuits, the link is magnetic and mechanical. The coil of a relay passes a relatively large current, typically 30mA for a 12V relay, but it can be as much as 100mA for relays designed to operate from lower voltages. Most ICs (chips) cannot provide this current and a transistor is usually used to amplify the small IC current to the larger value required for the relay coil. The maximum output current for the popular 555 timer IC is 200mA so these devices can supply relay coils directly without amplification.
some shapes of relays Protection diodes for relays : Transistors and ICs must be protected from the brief high voltage produced when a relay coil is switched off. The diagram shows how a signal diode (eg 1N4148) is connected 'backwards' across the relay coil to provide this protection. Current flowing through a relay coil creates a magnetic field which collapses suddenly when the current is switched off. The sudden collapse of the magnetic field induces a brief high voltage across the relay coil which is very likely to
12
The device requires four external 1uF capacitors for its operation.
14
Communication Protocols
1- RS232 serial communication protocol : the RS-232 serial communication protocol is a standard protocol used in asynchronous serial communication. It is the primary protocol used over modem lines and many devices .
Serial communication is basically the transmission or reception of data one bit at a time. Today's computers generally address data in bytes or some multiple thereof. A byte contains 8 bits. A bit is basically either a logical 1 or zero. Every character on this page is actually expressed internally as one byte. The serial port is used to convert each byte to a stream of ones and zeroes as well as to convert a streams of ones and zeroes to bytes. The serial port contains a electronic chip called a Universal Asynchronous Receiver/Transmitter (UART) that actually does the conversion.
15
Figure 1 At this point you may want to know what is the duration of a bit. In other words, how long does the signal stay in a particular state to define a bit. The answer is simple. It is dependent on the baud rate. The baud rate is the number of times the signal can switch states in one second. Therefore, if the line is operating at 9600 baud, the line can switch states 9,600 times per second. This means each bit has the duration of 1/9600 of a second or about 100 sec. When transmitting a character there are other characteristics other than the baud rate that must be known or that must be setup. These characteristics define the entire interpretation of the data stream.
16
19
What can I do if I dont find the RS232 connector ? Some laptops and modern desktop computer dont have RS232 connector . The solution of this problem is to use (RS232 to USB converter). This converter Plugs directly into your computers USB port for a simple easy way to connect RS232 output devices. The steps to use this converter are : 1- Connect it to computer . 2- Install the driver (attached with it CD ). 3- Now we can use RS232 serial communication and its name may be com4 or COM5 , COM6 ,,,,,,, etc . determined by driver software.
20
21
22
Important AT command used to Test and Design: 1) ATD To dial a voice call from the modem. 2) AT+IPR To set the baud rate for the modem ( here for our application the baud rate is set as 9600) 3) ATA To answer an incoming call. 4) AT+CHUP To hang up the initiated call. 5) AT+CFUN To set the phone functionality. Set to 0 to deactivate the modem. 6) AT+CLIP To identify caller number this command is set to 1 7) AT+CLIR For calling line Identification Restriction. 8) AT+CNUM To identify the subscriber number. 9) AT+CMGR To read the message at particular location .The location number is given as index. 10) AT+CMGD To delete the received message 11) AT+CMGS To send the message. 12) AT+CMGF To change the message format to PDU or Text mode. 13) AT+CMGL To see all the list of messages. 14) ATE To enable and disable command echo.
23
Microcontroller Programming
1234567Steps to program a microcontroller : Write a code by any microcontroller compilers like MikroC . Build the project to get a hex file. Put a microcontroller in a programmer ( burner) circuit . Connect a burner to your computer . Open a software which can write hex file to microcontroller like picpgm,winpic. Etc. Choose the hex file from browse buttom and burn . Now, your microcontroller is ready to make it in your electronic circuit to do the determined job.
How to build your owner programmer ( Burner ) ? You can buy the programmer from microchip or from other company but it cost will be very cheep if you build it yourself.
This programmer name is JDM programmer (shown in figure) and its circuit is not complex and it has a little of compnenets. The circuit diagram of the programmer is shown on the next figure.
24
JDM programmer
How to connect the programmer to your PC ? We need a serial cable (male female ) or ( female female) depended on your connector in a programmer .
25
26
Write your C source code using the built-in Code Editor (Code and Parameter Assistants, Syntax Highlighting, Auto Correct, Code Templates, andmore) Use the included mikroC libraries to dramatically speed up the development: data acquisition, memory, displays, conversions, communicationsPracticallyallP12,P16,andP18chipsaresupported. Monitor your program structure, variables, and functions in the Code Explorer. Generate commented, human-readable assembly, and standard HEX compatible with all programmers. Inspect program flow and debug executable logic with the integrated Debugger. Get detailed reports and graphs: RAM and ROM map, code statistics, assemblylisting,callingtree,andmore provided plenty of examples for users to expand, develop, and use as building bricks in your projects. Copy them entirely if you deem fit thats why we included them with the compiler.
Mikroc Libraries : mikroC provides a set of libraries which simplify the initialization and use of PIC MCU and its modules: Hardware/PIC-specific Libraries
ADC Library CAN Library CANSPI Library Compact Flash Library EEPROM Library Ethernet PIC18FxxJ60 Library SPI Ethernet Library Flash Memory Library Graphic LCD Library T6963C Graphic LCD Library IC Library
27
Keypad Library LCD Library LCD Custom Library LCD8 Library Manchester Code Library Multi Media Card Library OneWire Library PS/2 Library PWM Library RS-485 Library Software IC Library Software SPI Library Software UART Library Sound Library SPI Library USART Library USB HID Library Util Library SPI Graphic LCD Library Port Expander Library SPI LCD Library SPI LCD8 Library SPI T6963C Graphic LCD Library
ANSI C Ctype Library ANSI C Math Library ANSI C Stdlib Library ANSI C String Library
Miscellaneous Libraries
Conversions Library Trigonometry Library sprint Library Setjmp Library Time Library
28
char data; void main() { trisc=0; // all portc pins are output (C0,C1,.C7) . Usart_Init(9600); // Baudrate of serial communication is 9600 while(1){ if(usart_data_ready()==1) // when receiving data { data=usart_read(); // read data and store it in variable if(data=='G') portc.f0=1;// make a device ON } } }
In our project the computer receive sms messages through GSM modem like open the door then the computer send a character or data to microcontroller via RS232 this char may be like the last example G or anything we want after that the microcontroller make one pin high, this pin connected to Relay switch circuit which connected to a motor of the door . the motor will be on and the door will be opened. So our microcontroller code is very simple it just contains if statements and some variables and using of USART library (which make serial communication very easy) .
29
30
Certain PICmicros with two USART modules, such as P18F8520, require you to specify the module you want to use. Simply append the number 1 or 2 to a function name. For example, Usart_Write2(); Also, for the sake of backward compabitility with previous compiler versions and easier code management, MCU's with multiple USART modules have USART library which is identical to USART1 (i.e. you can use Usart_Init() instead of Usart_Init1() for Usart operations). Usart_Init Prototype void Usart_Init(const unsigned long baud_rate); Returns Nothing. Description Initializes hardware USART module with the desired baud rate. Refer to the device data sheet for baud rates allowed for specific Fosc. If you specify the unsupported baud rate, compiler will report an error. Requires You need PIC MCU with hardware USART. Usart_Init needs to be called before using other functions from USART Library. Example This will initialize hardware USART and establish the communication at 2400 bps: Usart_Init(2400); Usart_Data_Ready Prototype unsigned short Usart_Data_Ready(void); Returns Function returns 1 if data is ready or 0 if there is no data. Description Use the function to test if data in receive buffer is ready for reading. Requires USART HW module must be initialized and communication established before using this function. See Usart_Init.
31
32
Software description
In our project we designed software by using C# .net, This software has many jobs : 1- Deal with GSM modem by using serial communication via AT commands. 2- It is an interface between GSM modem and microcontroller ciruit. 3- Store all sms messages and its time and date. 4- Manage a security operations and permissions manage a security operation to our system by using password to all users . each user has his own password and this password must be written on the beginning of his sms messages. And there are permissions given to user.
Visual studio .net framework (shown in the picture) we use it to design our software .
33
This is the main screen of our software which supervise the sms messages and show who send this message ,the time of send , the date and the text of SMS. There is a button allow us to go to User and Permissons.
34
This screen control the user accounts and permissions of each user . these permissions are : 1- make a device ON. 2- make a device OFF. 3- Ask about the state of the device .
35
Refrences
1- Advanced PIC Microcontroller Projects in C ,Dogan Ibrahim , Newnes. 2- MikroC help. 3- pic16f877a datasheet . 4- max232 datasheet . 5- the fastest way to master programming microcontroller ,Ahmad Fayed , Free EBook. http://qariya.com/vb/showthread.php?t=40760 6- wavecom AT commands manual for wavecom GSM modems.
36