i used hc-06 bluetooth module and arduino uno i'm using this on my bike i wanted to make my bike off when my phone is out of range.. but i' dont know how to do it. i tryed searching but no luck..
heres the code...
/*
simple LED test
*/
char val; // variable to receive data from the serial port
const byte Relay1 = 2; // LED connected to pin 2 (on-board LED)
const byte Relay2 = 3;
void setup()
{
pinMode(Relay1, OUTPUT); // pin 2 () as OUTPUT
pinMode(Relay2, OUTPUT); // pin 3 (on-board LED) as OUTPUT
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
Serial.begin(9600); // start serial communication at 115200bps
}
void loop()
{
if ( Serial.available() > 0 ) // if data is available to read
{
val = Serial.read(); // read it and store it in 'val'
if ( val == 'a' ) // if 'a' was received led 2 is switched off
{
digitalWrite(Relay1, HIGH); // turn Off pin 2
}
if ( val == 'A' ) // if 'A' was received led 2 on
{
digitalWrite(Relay1, LOW); // turn ON pin 2
}
if ( val == 'b' ) // if 'b' was received led 3 is switched off
{
digitalWrite(Relay2, HIGH); // turn Off pin 3
}
if ( val == 'B' ) // if 'B' was received led 3 on
{
digitalWrite(Relay2, LOW); // turn ON pin 3
} //else (ledpin = 3, LOW) //set led pin 3 to low state
}
}
I don't know you detect when a bluetooth device is out of range but you should not be planning to reset your Arduino when that happens. Just treat it as another state of your program and call the appropriate function to take whatever action you require.
i'm using arduino to power on and start my motorcycle.. and i wanted to make my bike off when my phone is out of range..
i'm using 2 relays to power on my bike, 1 relay for ignition and the other for my starter button..
the ignition relay stays on until i turn it off.. i'v been wondering how to make my relay off when its out of range..
If only there's a way to detect when my bluetooth is disconnected
i'm using Arduino Uno R3 and HC-06
here is the sketch that i'm using
/*
simple LED test
*/
char val; // variable to receive data from the serial port
const byte Relay1 = 2; // LED connected to pin 2 (on-board LED)
const byte Relay2 = 3;
void setup()
{
pinMode(Relay1, OUTPUT); // pin 2 () as OUTPUT
pinMode(Relay2, OUTPUT); // pin 3 (on-board LED) as OUTPUT
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
Serial.begin(9600); // start serial communication at 115200bps
}
void loop()
{
if ( Serial.available() > 0 ) // if data is available to read
{
val = Serial.read(); // read it and store it in 'val'
if ( val == 'a' ) // if 'a' was received led 2 is switched off
{
digitalWrite(Relay1, HIGH); // turn Off pin 2
}
if ( val == 'A' ) // if 'A' was received led 2 on
{
digitalWrite(Relay1, LOW); // turn ON pin 2
}
if ( val == 'b' ) // if 'b' was received led 3 is switched off
{
digitalWrite(Relay2, HIGH); // turn Off pin 3
}
if ( val == 'B' ) // if 'B' was received led 3 on
{
digitalWrite(Relay2, LOW); // turn ON pin 3
} //else (ledpin = 3, LOW) //set led pin 3 to low state
}
}
sometimes a bluetooth or gsm module for that matter can loose connection even thou within range.... a reset of that module sometimes do wonders
some modules have a slow blinking light when connected... maybe he could use that on an input pin...
and say if no action on the input pin for 5 sec, turn off the output pin that turns on the module... wait 5 sec and then turn it on again.... but maybe allow for 10 sec to get the connecttion up again
i'v a battery voltage meter.. and my battery charges while running...
and i can also start with my key.. no way for the arduino to stop
my phone might fail on me... but, i would not overtake or speed with arduino taking over my motorcycle..
i just wanted to learn anyway.. i wanted to know if my module and arduino has this function.. i may be able to use it in my room lighs and fans .. so it turns off when i leave...
Is it possible to write a program to run on your phone which would send a message to the Arduino every few seconds? If the message stopped coming the Arduino would know there was a problem.