Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Fireplace Protoype
- //I used a Arduino Uno and BlueSMiRF Silver http://www.sparkfun.com/products/10269
- // Project page:
- //Connections:
- // BlueSMiRF Uno
- // --------- to ---------
- // VCC 5V
- // Gnd Gnd
- // TX-0 D6 (Uno's RX - defined below)
- // RX-1 D7 (Uno's TX - defined below)
- #include <SoftwareSerial.h>
- //define the receive and transmit pins for the bluetooth to communicate with Uno
- #define RxD 6
- #define TxD 7
- int turnONvalue=0;
- int led = 12;
- //Base connection method for a slave device taken from
- SoftwareSerial blueToothSerial(RxD,TxD);
- void setupBlueToothConnection(){
- Serial.println("Setting up Bluetooth Link");
- delay(1000);
- blueToothSerial.begin(115200); //Begins Bluetooth serial connection. Set Bluetooth BaudRate to default baud rate 115200
- delay(1000);
- Serial.println("Sending: +INQ=0");
- sendBlueToothCommand("\r\n+INQ=0\r\n");
- delay(2000);
- Serial.println("Sending: +STWMOD=0");
- sendBlueToothCommand("\r\n+STWMOD=0\r\n");
- sendBlueToothCommand("\r\n+STNA=ArduinoBT\r\n");
- Serial.println("Sending: +STNA=ArduinoBT");
- sendBlueToothCommand("\r\n+STAUTO=0\r\n");
- Serial.println("Sending: +STAUTO=0");
- sendBlueToothCommand("\r\n+STOAUT=1\r\n");
- Serial.println("Sending: +STOAUT=1");
- sendBlueToothCommand("\r\n+STPIN=0000\r\n");
- Serial.println("Sending:+STPIN=0000");
- delay(2000); // This delay is required.
- sendBlueToothCommand("\r\n+INQ=1\r\n");
- Serial.println("Sending: +INQ=1");
- delay(2000); // This delay is required.
- blueToothSerial.flush();
- }
- /* turned off as it did not work, but kept just in case
- //Checks if the response "OK" is received.
- void CheckOK(){
- char a,b;
- while(1){
- Serial.println("checking OK main loop");
- if(int len = blueToothSerial.available()){
- a = blueToothSerial.read();
- if('O' == a){
- b = blueToothSerial.read();
- if('K' == b){
- Serial.println("BLUETOOTH OK");
- while( (a = blueToothSerial.read()) != -1){
- Serial.print(a);
- }
- break;
- }
- }
- }
- }
- while( (a = blueToothSerial.read()) != -1){
- Serial.print(a);
- }
- }
- */
- //Send the command to Bluetooth
- void sendBlueToothCommand(char command[]){
- blueToothSerial.print(command);
- //CheckOK();
- Serial.println("done sending command, hehe");
- }
- void setup(){
- pinMode(led, OUTPUT);
- Serial.begin(9600); // begins testing serial connection - to test in Arduino IDE via Tools | Serial Monitor
- setupBlueToothConnection();
- }
- void loop() {
- if (turnONvalue==22){ // check to see if 22 is sent (ON button)
- digitalWrite(led, HIGH);
- } else if (turnONvalue==44){ // check to see if 44 is sent (OFF button)
- digitalWrite(led, LOW);
- }
- //check if 1 byte is sent
- if (blueToothSerial.available() == 1) { // if one byte is sent via the ON or OFF buttons from the app
- turnONvalue=blueToothSerial.read();
- }
- else {
- //blueToothSerial.println("Invalid Data was received");
- Serial.println("Invalid Data was received");
- char a;
- while( (a = blueToothSerial.read()) != -1){
- Serial.println(a);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment