I want to wake up my arduino uno via a serial message sent from another arduino over software serial (pins 11, 12) . I want to use the pin change interrupt. I have enclosed the codes for both the sender and the receiver . However , things are not working as expected.Plz, help me out.
Connections: pin 11 of one arduino connected to pin 12 of other arduino and vice versa.
//Sleeping arduino
#include <avr/sleep.h>
#include <SoftwareSerial.h>
#define RXpin 11
SoftwareSerial mySerial(11,12);
volatile boolean triggered=false;
void sleepNow(){
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_mode();
}
ISR (PCINT3_vect){
triggered=true;
}
void setup() {
// put your setup code here, to run once:
mySerial.begin(28800);
Serial.begin(9600);
digitalWrite(RXpin,LOW);
//pin change interrupt
PCMSK0 |=bit(PCINT3);
PCIFR |=bit(PCIF0);
PCICR |=bit(PCIE0);
}
void loop() {
// put your main code here, to run repeatedly:
if(triggered==true){
triggered=false;
Serial.println("Woken!");
delay(500);
if(mySerial.available()){
int data=mySerial.parseInt();
Serial.println(data);
}
else{
Serial.println("Sleeping Now");
delay(500);
sleepNow();
}
}
//Code for sender
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11,12);
int otp=1;
void setup() {
// put your setup code here, to run once:
mySerial.begin(28800);
}
void loop() {
// put your main code here, to run repeatedly:
if(otp==1){
otp=0;
char otwp='W';
mySerial.write(otwp);
delay(90);
int data=42;
mySerial.write(data);
}
}