Hi,
I have a motion detection system using 2 boards. The first board is a MEK 1010 Wifi and its only job is to display data on LCD and communiacte to second board if it needs to be looking for motion or not.
There are three modes Off (0), On (1), Auto (2), if the system is in auto it checks a daylight sensor before checking PIR.
Currently the MKR 1010 is writing successfully on the Serial Monitor but the second board is not receiving. I feel like I have tried everything. The RX and TX pins are cross connected, both boards share same ground. Both PORTS are corrects and correct boards are selected.
I believe it may have something to do with the code and if its 'Serial' or 'Serial1'. I am used to working with UNO's but need to use the wifi board as later on i will need to display data on website.
I have attached code below any help is welcome.
//Master Board MKR 1010 Wifi
#include <LiquidCrystal.h>
//adding LCD library to programm
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);//LCD connections on board
int pushButtonOff = 5;//Push button conections on board
int pushButtonOn = 6;//Push button conections on board
int pushButtonAuto = 7;//Push button conections on board
int LEDOff = 1;//LED conections on board
int LEDOn = 2;//LED conections on board
int LEDAuto = 3;//LED conections on board
int systemMode = 0;//Creating Int Value for System Mode 0 = Off, 1 = On, 2 = Auto
void setup()//Setup Function initilization
{
Serial.begin(9600);
// Serial1.begin(9600);//Starts serial communications with a vaulue of 9600
lcd.begin(16,2);//Starts the LCD screen with 16 columns and 2 rows
pinMode(pushButtonOff, INPUT);//Sets push button off as an input device
pinMode(pushButtonOn, INPUT);//Sets push button on as an input device
pinMode(pushButtonAuto, INPUT);//Sets push button auto as an input device
pinMode(LEDOff, OUTPUT);//Sets LED off as an OUTPUT device
pinMode(LEDOn, OUTPUT);//Sets LED off as an OUTPUT device
pinMode(LEDAuto, OUTPUT);//Sets LED off as an OUTPUT device
lcd.clear();//Clears the LCD
lcd.setCursor(1,0);//sets LCD cursor
lcd.print("Select Mode:");//Prints text to LCD
}
void loop()
{
if (digitalRead(pushButtonOff) == HIGH && systemMode != 0)
{
systemMode = 0;
lcd.clear();//Clears the LCD
lcd.setCursor(1,0);//sets LCD cursor
lcd.print("Current Mode:");//Prints text to LCD
lcd.setCursor(1,1);//sets LCD cursor
lcd.print(systemMode);//Prints text to LCD
delay(100);
digitalWrite(LEDOff, HIGH);
digitalWrite(LEDOn, LOW);
digitalWrite(LEDAuto, LOW);
Serial.print(systemMode);
delay(1000);
}
else if(digitalRead(pushButtonOn) == HIGH && systemMode != 1)
{
systemMode = 1;
lcd.clear();//Clears the LCD
lcd.setCursor(1,0);//sets LCD cursor
lcd.print("Current Mode:");//Prints text to LCD
lcd.setCursor(1,1);//sets LCD cursor
lcd.print(systemMode);//Prints text to LCD
delay(100);
digitalWrite(LEDOff, LOW);
digitalWrite(LEDOn, HIGH);
digitalWrite(LEDAuto, LOW);
Serial.print(systemMode);
delay(1000);
}
else if(digitalRead(pushButtonOn) == HIGH && systemMode != 2)
{
systemMode = 2;
lcd.clear();//Clears the LCD
lcd.setCursor(1,0);//sets LCD cursor
lcd.print("Current Mode:");//Prints text to LCD
lcd.setCursor(1,1);//sets LCD cursor
lcd.print(systemMode);//Prints text to LCD
delay(100);
digitalWrite(LEDOff, LOW);
digitalWrite(LEDOn, HIGH);
digitalWrite(LEDAuto, HIGH);
Serial.print(systemMode);
delay(1000);
}
}
//Slave Board MKR 1000
// C++ code
//
int PIR1pin = 4;
int PIR2pin = 5;
int echoPin = 6; // ECHO pin
int LEDCountermeasure1 = 0;//LED conections on board
int LEDCountermeasure2 = 1;//LED conections on board
int LEDCountermeasure3 = 2;//LED conections on board
int LEDCountermeasure4 = 3;//LED conections on board
int LEDSystemActive = 7;
int systemMode;//Creating Int Value for System Mode 0 = Off, 1 = On, 2 = Auto
void setup()
{
Serial.begin(9600);
//Serial1.begin(9600);//Starts serial communications with a vaulue of 9600
pinMode(PIR1pin, INPUT);
pinMode(PIR2pin, INPUT);
pinMode(LEDCountermeasure1, OUTPUT);
pinMode(LEDCountermeasure2, OUTPUT);
pinMode(LEDCountermeasure3, OUTPUT);
pinMode(LEDCountermeasure4, OUTPUT);
pinMode(LEDSystemActive, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
if (Serial.available() > 0)
{
char systemModeChar = Serial.read();
systemMode = systemModeChar - '0'; //Converts Char to int
digitalWrite(LEDSystemActive, HIGH);
}
if (systemMode == 1 ||(systemMode == 2 && analogRead(A0) < 100))
//If system mode is euql to 1 it will check PIR but if it is equal to 2 it will
//check the Photoresistor then check PIR if daylight isnt detected
{
if(digitalRead(PIR1pin == HIGH || PIR2pin == HIGH))
{
Serial.println("Motion Detected");
countermesures();
}
}
}
void countermesures()
{
digitalWrite(LEDCountermeasure1, HIGH);
digitalWrite(LEDCountermeasure2, HIGH);
digitalWrite(LEDCountermeasure3, HIGH);
digitalWrite(LEDCountermeasure4, HIGH);
pulseIn(echoPin, HIGH);
delay(3000);
digitalWrite(LEDCountermeasure1, LOW);
digitalWrite(LEDCountermeasure2, LOW);
digitalWrite(LEDCountermeasure3, LOW);
digitalWrite(LEDCountermeasure4, LOW);
pulseIn(echoPin, LOW);
}