Pages: [1]   Go Down
Author Topic: Arduino control via Bluetooth  (Read 1553 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi to all,

This is my first topic to arduino.cc forum and I already have some questions.
I will appreciate very much if you could help me.

I’m using two Arduino Uno R3, a pair of Bluesmirf modules ( https://www.sparkfun.com/products/10269 ), some tact buttons and some relays.
My plan is by pressing a button at the master arduino, a relay will open at the slave arduino.

Phillipe Cantin from his blog helps me very much ( http://phillipecantin.blogspot.gr/2012/01/arduino-bluetooth-link.html ) and I have managed by pressing a button at the master, a led blinks at the slave. But the led is not blinking very much. I can barely see it. You can download and see if you want a video demonstrating for what I’m talking about from here: http://we.tl/fsUVrcs72K

Can you please help me to go further at my project?

Thank you in advance.


That is the code I have used so far.
Code:
//Master code
const int buttonPin = 2;
const int ledPin =  8;
int buttonState = 0;
void setup() {
  Serial.begin(115200);
  Serial.print("$$$");
  delay(100);
  Serial.println("SM,1");  delay(100);
  Serial.println("C,0006664E48D5");
  delay(100);
  Serial.println("---");
  pinMode(ledPin, OUTPUT);     
  pinMode(buttonPin, INPUT);
 
  //Give the module some time to enable the connection
  delay(1000);
}
void loop() {
  //Read the button sate
  buttonState = digitalRead(buttonPin);
 
  //Send the 'command' to the salve module
  //
  //Note: a good optimization would be to only send the button state when it changes
  if (buttonState == HIGH) {         
    Serial.println('1'); 
  }
  else {
    Serial.println('0'); 
  }
 
  //Wait a little so you don't digitalRead and println to often 
  delay(100);
}

Code:
//Slave code
const int buttonPin = 2;
const int ledPin =  8;
int buttonState = 0;
void setup() {
  Serial.begin(115200);
  Serial.print("$$$");
  delay(100);
  Serial.println("SM,0");
  delay(100);
  Serial.println("---");
 
  //Give the module some time to enable the connection
  delay(2000);
}
int incomingByte = 0;
void loop() {
  //If something is being received on the serial port
  if (Serial.available() > 0) {
 
    // read the incoming byte:
    incomingByte = Serial.read();
 
    //Set the LED acording to the byte received
    if (incomingByte == '1') {         
      digitalWrite(ledPin, HIGH); 
    }
    else { //incomingByte != '1'
      digitalWrite(ledPin, LOW);
    }
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the slave code you don't declare the pin mode.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the slave code you don't declare the pin mode.
I did that and it works!!
Thank you!!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

yes, it works! smiley-cool
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again,

I got another question. I have connected a 12v relay at Pin8 and a led after that, without changing the existing code,
using this diagram:

but the relay won't works.
Can you please tell me what is wrong and it doesn't works?

Thank you in advance.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any suggestions guys?
Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 7
Posts: 1545
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

check the 12v suplly  is there ornot?

check arduino ground and 12v power supply gnd are connected?

on the transistor base just apply 5v from the arduino and check for relay working
Logged

"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੂਂ !

Pages: [1]   Go Up
Jump to: