Home automation

Post your requests and ideas for the mikroElektronika website & forums.
Post Reply
Author
Message
mmjatta
Posts: 1
Joined: 21 May 2013 14:57

Home automation

#1 Post by mmjatta » 22 Mar 2014 01:34

Hi! am doing a simple project on home automation and i came up with a problem with my if statement the print wrong words in virtual terminal...please HELP... below are my code and attached is my circuit.. am using mikroc and proteus.



//Devices pins
sbit buzzer at RD0_bit;
sbit fridge at RD1_bit;
sbit security at RD2_bit;
sbit sitting at RD3_bit;
sbit power at RD4_bit;
sbit sensor at RD5_bit;


// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
// End LCD module connections

unsigned char beeps = 0;
char turn;



void sensing();
void beepBuzzer();

void received(char * receive) //received message from user
{
UART1_Write(13); //<CR> mean Enter
UART1_Write_Text(receive); //Message sent to the user
UART1_Write(13); //<CR> mean Enter

Delay_ms(100);
}

void beepBuzzer(){
if(beeps > 0){
buzzer = ~buzzer;
beeps--;
}
}

void sendTxt(char * message)
{
UART1_Write_Text("AT+CMGF=1"); //select text mode for sms
UART1_Write(0x0D); //<CR> mean Enter
UART1_Write_Text("AT+CMGS=");
Delay_ms(100);
UART1_Write(0x22); //" double qoute
Delay_ms(200);
UART1_Write_Text("0714672893"); // Your Telephone Number
Delay_ms(200);
UART1_Write(0x22); //" double qoute
UART1_Write(0x0D); //<CR> mean Enter
Delay_ms(200);
UART1_Write_Text(message); //Message sent to the user
UART1_Write(0x0D); //<CR> mean Enter
Delay_ms(200);
UART1_Write(26); //Ctr +Z
Delay_ms(200);
UART1_Write(0x0D);
Delay_ms(100);
}



void main() {

TRISD.F0 = 0;
TRISD.F1 = 0;
TRISD.F2 = 0;
TRISD.F3 = 0; //Set PORTA as output

TRISD.F4 = 1;
TRISD.F5 = 1; //Set PORTD 0 AND 1 as INput




PORTD = 0; //Initialize PORTD to 0
ADCON1 = 0; // Configure AN pins as digital

Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
LCD_OUT(1,1,"HOME AUTOMATION") ;

uart1_init(9600); // Initialize serial port
delay_ms(100);

UART1_Write_Text("SYSTEM READY");
UART1_Write(13);


while(1){



if (UART1_Data_Ready()) // If data is received,
{
turn = UART1_Read(); // read the received data,

}

if( turn == 'a')//turning the Fridge ON
{
received("Fridge is ON");
fridge=1;
turn= '\0' ;
}


else if( turn == 'b')//turning the Fridge OFF
{
received("Fridge is OFF");
fridge=0;
turn= '\0' ;
}


else if( turn == 'c')//turning the Security lights ON
{
received("Security lights are ON");
security=1;
turn= '\0' ;
}


else if( turn == 'd')//turning the Security lights OFF
{
received("Security lights are OFF");
security=0;
turn= '\0' ;
}


else if( turn == 'e')//turning the sitting lights ON
{
received("Sitting lights are ON");
sitting=1;
turn= '\0' ;
}


else if( turn == 'f') //turning the Sitting lights OFF
{
received("Sitting lights are OFF");
sitting=0;
turn= '\0' ;
}


if(sensor = 1){
while(sensor = 1){
delay_ms(100);
}
Lcd_Cmd(_LCD_CLEAR);
LCD_OUT(2,1,"INTRUDER ALERT!!") ;
sendTxt("INTRUDER");
beeps = 20; //Edit to alter length of buzzer beeps
}

if(power = 1){
while(power = 1){
delay_ms(100);
}
Lcd_Cmd(_LCD_CLEAR);
LCD_OUT(2,1,"POWER OFF") ;
sendTxt("POWER IS OFF");
PORTD = 0; //PORTD to 0
}

else if(power = 0){
while(power = 0){
delay_ms(100);
}
Lcd_Cmd(_LCD_CLEAR);
LCD_OUT(2,1,"POWER ON") ;
sendTxt("POWER IS ON");
}


}


}[/color]
Attachments
Proteus image
Proteus image
Capture.JPG (126.3 KiB) Viewed 5977 times

jayanthd
Posts: 630
Joined: 08 May 2013 18:31
Location: Bangalore

Re: Home automation

#2 Post by jayanthd » 07 Apr 2014 10:03

Zip and attach your complete mikroe project files. It will be easier to make changes.
[HW:] EasyPIC v7, mikroProg PIC, AVR, STM32, PSoC, Tiva, 8051
[SW:] mikroC PRO PIC, dsPIC, PIC32, AVR, ARM, 8051
mikroBasic PRO PIC, dsPIC, PIC32, AVR, ARM, 8051
mikroPascal PRO PIC, dsPIC, PIC32, AVR, ARM, 8051
Visual GLCD, Visual TFT

Post Reply

Return to “Website & Forums Wishlist”