Hi!
I trying to do a project that sends a simple String to my smartphone if Push Button is pressed.
The project in steps As follows:
So If Push Button is pressed then send "help" via Bluetooth to smartphone (Android) and led is light up.
Here is my code!
#include <SoftwareSerial.h>
#define ACTIVATED LOW
int txPin = 1;
int rxPin = 0;
SoftwareSerial bt(txPin,rxPin);//tr , rx
const int buttonPin = 2;
int LED_PIN = 13; // Initializing pin number
int buttonState = 0;
void setup()
{
bt.begin(9600);
Serial.begin(9600);
pinMode(LED_PIN,OUTPUT);
pinMode(buttonPin,INPUT);
digitalWrite(buttonPin,HIGH);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if(buttonState == ACTIVATED){
bt.print("help");
digitalWrite(LED_PIN,HIGH);
}else
digitalWrite(LED_PIN,LOW);
delay(2000);
}
I also have Bluetooth terminal app it work OK, But my problem is that When i press the Button Nothing happens ,
No data in SmartPhone and NO led .
I have try to send "help" to the serial monitor (via USB not Bluetooth serial.print("help")) and it work OK,
SO can I get any advice.
Arduino Mega.
HC-05 Bluetooth.
Android terminal App.
Thank.
You appear to be using software serial on the hardware serial pins 0,1 and therefore deserve all the grief you get!
either
- use other pins for software serial or
- get rid of software serial altogether, and leave Bluetooth where it is on hardware serial
If you do the latter, you need no reference to bluetooth at all, and the "help" will come up on serial monitor and Android. This approach enables you to prove your code is kosher, without incurring any complications with Bluetooth.
Hi Nick_Pyner
Thank you for your reply
I have modified the code and the pins as follows:
the code:
#include <SoftwareSerial.h>
#define ACTIVATED LOW
const int RX_PIN = 2;
const int TX_PIN = 3;
SoftwareSerial Ser(RX_PIN, TX_PIN);
const int buttonPin = 4;
int BUZER_PIN = 13; // Initializing pin number
int buttonState = 0;
void setup() //The setup function will only run once, after each powerup.It initializes and sets the initial values
{
Ser.begin(9600);
Serial.begin(9600); //Sets the baud for serial data transmission (Bits Per Second)
pinMode(BUZER_PIN,OUTPUT); //Specify behaviour of pin to work either as an input or an output
pinMode(buttonPin,INPUT);
digitalWrite(buttonPin,HIGH);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if(buttonState == ACTIVATED){
digitalWrite(BUZER_PIN,HIGH);
Ser.println("help");
delay(1000);
}
else{
digitalWrite(BUZER_PIN,LOW);
}
}
The pins:
HC-05 RXD --> DIGITAL P3 ARDUINO MEGA
TXD --> DIGITAL P2
VCC --> 3.3V
GND --> GND
And it works correctly ^____^.
I wonder now is connecting RXD AND TXD to Digital Pins not going to cause damage or burn HC-05
When running for a long time .
Thanks a lot.
I doubt that you have done or will do any damage anywhere. All you have done is spread confusion, but now you are OK!.
BUT, if you are using an HC-05 on a breakout board, you may have a problem soon because you are running a 3.6v board on 3.3v.
IF you are using a bare HC-05 module, i.e. solder connect, not pins, you are OK with 3.3v.
ALSO note that it is good practice to use a voltage divider on Arduino Tx, which you don't mention.
You might find the following background notes useful.
http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
Your code is obviously doing what you want, so just look at the pictures!