Hi , I want to make simple project , the project is two fire(smoke) detectors in two rooms where every smoke detector has a pic16f88 and the arduino is the controller , I wrote the code , the principle of code is the arduino send serial msgs where every pic has special msg(special number).Note :- (this step is even don't happen synchronization)
when pic receives its special msg and the pin 3(input) is high (when the fire occur) ,send serial msg(number of room) to arduino then arduino specify the room by print in termial monitor.
I simulate the code of pic in proteus and code of arduino in terminal monitor and work well.
1'st room (pic16f88) code:
char yt[3];
void main(){
ANSEL = 0;
UART1_Init(9600); // initialize UART1 module
Delay_ms(100);
TRISA = 0xFF;
while (1) {
if (UART1_Data_Ready()== 1) // if data is received
{UART1_Read_Text(yt,"o",5); // reads text until 'OK' is found
if (yt[0] == '0' && yt[1]=='0' && yt[2]=='1' && PORTA==0B00001000)
{UART1_Write_Text("001");Delay_ms(5000); }
} // sends back text } }
arduino mega code :
#include <SoftwareSerial.h>
SoftwareSerial myserial(15,14); // RX, TX
char i[4]={'a','a','a'};
char ch;
int index=0;
char array[2][4] = {{'0','0','1','o'},
{'0','0','2','o'}};
char e[4];
void setup(){
//create serial object
Serial.begin(9600);
myserial.begin(9600);
Serial.println("power on"); }
void loop(){
for (int i=0;i<2;i++){
for (int p=0;p<4;p++)
{array[i][p];
myserial.write(array[i][p]);
}
r();}
}
void r(){
//have the arduino wait to receive input
while(myserial.available() > 0){
//Read the input
Serial.println("the fire in the room :");
ch = myserial.read();
i[index]= ch ;
index++;}
index=0;
if (i[0]!='a' && i[1]!='a' && i[2]!='a' ){
Serial.print(i[0]);Serial.print(i[1]);Serial.print(i[2]);
Serial.print("\n");
i[0]='a';i[1]='a';i[2]='a';
}
}
the code hasn't error, I made the pin 3 of 1'st smoke detector always high then must print in terminal monitor the number 001(every 5 seconds) but I don't know why don't print.