Você está na página 1de 5

Control Appliances using SMS

Published November 22, 2011 | By Abbas Abdullahi The aim of this project, Control Appliances via SMS using sim300cz gsm modem and ATMega16, is to use GSM technology to automate and remotely control various household appliances. This project will aid student and developers to make use of sim300cz gsm modem in automation process. This design can be futher developed for

more robust home automation. The transmit TXD of the mega16 connected to receive RXD of SIM300CZ and transmit TXD of the SIM300CZ connected to receive RXD of the mega16, once sms message Device1 ON or Device1 OFF is sent from mobile phone, the sim300cz will receive and send to microcontroller, the microcontroller will check the command and ON or OFF any of the relay. The relay can be connected to any device.

Component: 1. ATMega16 Microcontroller 2. SIM300CZ GSM Modem 3. 6V Relay 4. 4MHZ Crystal Oscillator 5. 22pf Capacitor 6. 1k resistor 7. 1N4007 diodes 8. 2N222 transistor 9. 4k7 resistor You can get the component at www.microscale-embbed.com

Source code

The source code is written using C language:

#include <avr/io.h>

#include <avr/interrupt.h> #include <string.h> #include <util/delay.h> unsigned int i=0; char enter=0x0D; char ctrZ=0x1A; void USARTInit() { //Set Baud rate UCSRA=0; UBRRL = 51; UBRRH = 0; UCSRC=(1<<URSEL)|(3<<UCSZ0); //Enable The receiver and transmitter UCSRB=(1<<RXEN)|(1<<TXEN)|(1<<RXCIE); } char get_char() { //Wait untill a data is available while(!(UCSRA & (1<<RXC))) { } return UDR; } void put_char(char data) { //Wait untill the transmitter is ready while(!(UCSRA & (1<<UDRE))) { } //Now write the data to USART buffer UDR=data; } void put_str(char* str) { unsigned char len; len=strlen(str); for(int i=0;i<len;i++) { _delay_ms(100); while((UCSRA & 0x20) == 0x0); UDR=str[i]; } } int main (void) {

// set PORTA for output DDRA |= (1<<PA2) | (1<<PA1) | (1<<PD0); PORTA &= ~(1<<PA2) | (1<<PA1) | (1<<PA0); USARTInit(); _delay_ms(1000); send("AT"); put_str(dummy); while(get_char()!='O'); while(get_char()!='K');//Waiting for modem response put_str("ATE0"); put_str (dummy); while(get_char()!='O'); while(get_char()!='K');//Waiting for modem response put_str ("AT+CMGF=1"); put_str (dummy); while(get_char()!='O'); while(get_char()!='K');//Waiting for modem response put_str ("AT+CNMI=2,2,0,0,0"); put_str (dummy); while(get_char()!='O'); while(get_char()!='K');//Waiting for modem response while(1) { rx[i]=get_char(); i++; if(rx[i-2]==13 && rx[i-1]==10) { rx[i-1]=''; rx[i-2]=''; i=0; if(strcmp(rx,"device1 ON")==0) { PORTA |= (1<<PA0); _delay_ms(1000); put_str ("AT"); put_str (enter); put_str ("AT+CMGS=\"+gsm number\""); need to add your gsm number here e.g +2348033870967 put_str (enter); put_str ("device1 ON "); put_str (ctrZ); } if(strcmp(rx,"device1 OFF")==0) {

// you

PORTA |= (1<<PA1); _delay_ms(1000); put_str ("AT"); put_str (enter); put_str ("AT+CMGS=\"+gsm number\""); put_str (enter); put_str ("device1 OFF "); put_str (ctrZ); } if(strcmp(rx,"device2 ON")==0) { PORTA |= (1<<PA2); _delay_ms(1000); put_str ("AT"); put_str (enter); put_str ("AT+CMGS=\"+gsm number\""); put_str (enter); put_str ("device2 ON"); put_str (ctrZ); } if(strcmp(rx,"device2 OFF")==0) { PORTA |= (1<<PA2); _delay_ms(1000); put_str ("AT"); put_str (enter); put_str ("AT+CMGS=\"+gsm number\""); put_str (enter); put_str ("device2 OFF"); put_str (ctrZ); } if(strcmp(rx,"device3 ON")==0) { PORTA |= (1<<PA2); _delay_ms(1000); put_str ("AT"); put_str (enter); put_str ("AT+CMGS=\"+gsm number\""); put_str (enter); put_str ("device3 ON"); put_str (ctrZ); } if(strcmp(rx,"device3 OFF")==0) { PORTA |= (1<<PA2); _delay_ms(1000); put_str ("AT"); put_str (enter); put_str ("AT+CMGS=\"+gsm number\""); put_str (enter); put_str ("device3 OFF"); put_str (ctrZ); }

} } }

Você também pode gostar