-
-
Save Lif3line/1c2029fb561d77958b15 to your computer and use it in GitHub Desktop.
#include <avr/sleep.h> | |
#include <SoftwareSerial.h> | |
SoftwareSerial blueSerial(3, 9); // RX, TX pins | |
int relayActive = false; | |
int relayPin = 7; | |
void setup() { | |
blueSerial.begin(9600); // Set baud rate | |
pinMode(relayPin, OUTPUT); | |
digitalWrite(relayPin, HIGH); | |
attachInterrupt(1, toggleRelay, RISING); // Interupt for wake up | |
blueSerial.print("Initialised\n\r"); | |
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Lowest power mode | |
sleep_enable(); | |
sleep_mode(); // Go to sleep | |
} | |
void loop() { | |
sleep_mode(); | |
} | |
void toggleRelay() { | |
blueSerial.print("Woah much intteruption!\n\r"); | |
if (!relayActive) { | |
digitalWrite(relayPin, LOW); | |
} else { | |
digitalWrite(relayPin, HIGH); | |
} | |
relayActive = !relayActive; | |
} |
This is really old, but should trigger off any rising edge on the serial interrupt. I think a modernised version would use attachInterrupt(digitalPinToInterrupt(RX_PIN), toggleRelay, RISING);
to make sure we're attached to the correct interrupt.
This is really old, but should trigger off any rising edge on the serial interrupt. I think a modernised version would use
attachInterrupt(digitalPinToInterrupt(RX_PIN), toggleRelay, RISING);
to make sure we're attached to the correct interrupt.
Unfortunately, I still don't understand. Which command should we send after connecting with the Bluetooth module? Also, rx and tx pins are not used as interrupts, as far as I know, in order to use them as interrupts, they must be defined as digital pins using software serial, as you did in the code.
Ah past me was too clever for current me clearly. Well assuming the attached interrupt is correct then it should trigger off any serial message, so no specific command. Connect to the Bluetooth with something that supports a serial terminal then any data sent across the serial will trigger the relay toggle.
It's clear now thank you. Is it appropriate to use the hc06 bluetooth module according to this code? Also do I need to use tx-rx pins or digital 1 / 2 (interrupt) pins?
No worries, I had this running with either a HC05 or HC06 module, so that should be fine. I think you'll need tx-rx pins for the serial then the mapping to a digital pin to attach the interrupt to. If software serial already does that then you should be set.
So should this command be used:
"attachInterrupt(digitalPinToInterrupt(RX_PIN)"
instead of ;
"attachInterrupt(1,
also even though the bluetooth connection is established, ("Initialised\n\r") message is not coming to the application screen I use on the phone.
hi, which command do i need to send through serial terminal to wake up?