Arduino

fossil

Well-Known Member
Joined
Apr 22, 2009
Messages
214
Reaction score
0
Location
Umzinto
Hey guys.I need help with a safe operated via bluetooth.I'm using the arduino UNO with the bluetooth bee shield.This what I got so far.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// serial port
long DATARATE = 38400; // default data rate for BT Bee

char inChar = 0;
int LED = 13; // Pin 13 is connected to a LED on many Arduinos

void setup() {

// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(DATARATE);

// bluetooth bee setup
Serial.print("\r\n+STWMOD=0\r\n"); // set to slave
delay(1000);
Serial.print("\r\n+STNA=DSC\r\n"); // DSC = digital setting circles
delay(1000);
Serial.print("\r\n+STAUTO=0\r\n"); // don't permit auto-connect
delay(1000);
Serial.print("\r\n+STOAUT=1\r\n"); // existing default
delay(1000);
Serial.print("\r\n +STPIN=0000\r\n"); // existing default
delay(2000); // required

// initiate BTBee connection
Serial.print("\r\n+INQ=1\r\n");
delay(2000); // wait for pairing

pinMode(LED, OUTPUT);
}

void loop() {

lcd.setCursor(0, 1);
// test app:
// wait for character,
// a returns message, h=led on, l=led off
if (Serial.available()) {
inChar = Serial.read();

if (inChar == 'a') {
Serial.print("connected"); // test return connection
lcd.print("connected!");
}

if (inChar == 'h') {
digitalWrite(LED, HIGH); // on

lcd.print("LED ON!");}

if (inChar == 'l') {
digitalWrite(LED, LOW); // off
lcd.print("LED OFF!");
}

}

}

As you can see this is a test program when a 'h' is sent a LED comes on,when a "l' is sent the comes off and 'a' is test to test the connection.Now the problem is changing it so I can test for a 4 digit password with only two outcomes.If the password= serial read then LED on and if not LED off.
 
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// serial port
long DATARATE = 38400; // default data rate for BT Bee

char inChar = 0;
int LED = 13; // Pin 13 is connected to a LED on many Arduinos
char password[5] = "abcd";
int charcnt = 0;

void setup() {

// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(DATARATE);

// bluetooth bee setup
Serial.print("\r\n+STWMOD=0\r\n"); // set to slave
delay(1000);
Serial.print("\r\n+STNA=DSC\r\n"); // DSC = digital setting circles
delay(1000);
Serial.print("\r\n+STAUTO=0\r\n"); // don't permit auto-connect
delay(1000);
Serial.print("\r\n+STOAUT=1\r\n"); // existing default
delay(1000);
Serial.print("\r\n +STPIN=0000\r\n"); // existing default
delay(2000); // required

// initiate BTBee connection
Serial.print("\r\n+INQ=1\r\n");
delay(2000); // wait for pairing

pinMode(LED, OUTPUT);
}

void loop() {

lcd.setCursor(0, 1);
// test app:
// wait for character,
// a returns message, h=led on, l=led off
if (Serial.available()) {
inChar = Serial.read();

if (password[charcnt] == inChar)
charcnt++;


if (charcnt == 4)
digitalWrite(LED, HIGH); // on
else
{
digitalWrite(LED, LOW); // off
charcnt = 0;
}



}

}


So what does this do:
takes a char from the serial
compares it against the password
if the char matches then prepares for next char
-- if it does not match then reset
once a count of 4 chars match then the led is turned on
 
Last edited:
When I'm entering the password must I enter it 1 digit at a time(a,b,c,d) or can I send abcd together?I'm using a bluetooth terminal on my phone which waits for me to enter whatever info I want and then I click send.It's not like a keypad one digit at a time.
 
Top
Sign up to the MyBroadband newsletter
X