Hello !
i want to send and recieve data from my phone to arduino using HC05.
my first question : is it possible or not
if yes i tried every tuto on the net and no answer
i made an app, i want to now the led status on my arduino and send it to the phone and turn on/off the led from my phone all this with the same app.
thx
(deleted)
It is certainly possible. I have a couple of applications running that communicate between my Android tablet and Arduino processors with HC05 Bluetooth modules.
Is your phone Android or Apple? What Arduino board?
hi and thx for the answer
i use arduino uno - HC05 - androide phone
my wiring :
HC05 to arduino
VCC to 3.3v
GND to GND
txd and rxd to 10,11
my code
/* ===============================================================
Project : 2clairage De mon Studio
Author : Shaker Balegh
Created : 3rd Jan 2020
Arduino IDE : 1.8.10
Version : 1.2
================================================================== */#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
#define baudrate 9600#define CH1 8 // Connect Digital Pin 8 on Arduino to CH1 on Relay Module
#define CH2 7 // Connect Digital Pin 7 on Arduino to CH2 on Relay Module
#define CH3 4 // Connect Digital Pin 4 on Arduino to CH3 on Relay Module
#define CH4 2 // Connect Digital Pin 2 on Arduino to CH4 on Relay ModuleString msg;
SoftwareSerial hc05(rxPin ,txPin);
void setup(){
pinMode(rxPin,INPUT);
pinMode(txPin,OUTPUT);Serial.begin(9600);
Serial.println("ENTER AT Commands:");
hc05.begin(baudrate);
hc05.println("Hello U!");
delay(50);//Setup all the Arduino Pins
pinMode(CH1, OUTPUT);
pinMode(CH2, OUTPUT);
pinMode(CH3, OUTPUT);
pinMode(CH4, OUTPUT);digitalWrite(CH1, HIGH);
digitalWrite(CH2, HIGH);
digitalWrite(CH3, HIGH);
digitalWrite(CH4, HIGH);}
void loop(){readSerialPort();
if(msg!="") {
hc05.println(msg);
}
if (msg.length() > 0)
{if (msg == "Door:ON") {digitalWrite(CH1, LOW);} //turn light on
if (msg == "Door:OFF") {digitalWrite(CH1, HIGH);} //turn light offif (msg == "Hall:ON") {digitalWrite(CH2, LOW);} //turn light on
if (msg == "Hall:OFF") {digitalWrite(CH2, HIGH);} //turn light offif (msg == "Bed:ON") {digitalWrite(CH3, LOW);} //turn light on
if (msg == "Bed:OFF") {digitalWrite(CH3, HIGH);} //turn light offif (msg == "Other:ON") {digitalWrite(CH4, LOW);} //turn light on
if (msg == "Other:OFF") {digitalWrite(CH4, HIGH);} //turn light off
}
}
void readSerialPort(){
msg="";
while (hc05.available()) {
delay(3);
if (hc05.available() > 0) {
char c = hc05.read(); //gets one byte from serial buffer
msg += c; //makes the string readString
}
}
}
my app attached
(deleted)
sorry
Txd 10
Rxd 11
VCC to 3.3v
The HC05 modules that I have are 5V units. On the back of the module there is "Level 3.3V Power 3.6V--6V.
That means that the power (Vcc) should be 5V and the input signal (RX) limited to 3.3V. I use a voltage divider to drop the Uno 5V TX to 3.3V for the module RX.
Here is a simple test program that I use with the Serial Bluetooth Terminal app (available in Play Store). Pin 10 (Uno RX) goes to TX on the HC05. Pin 11 (Uno TX) goes to HC05 RX through the voltage divider. Use the phone settings to pair and connect the HC05 module and then, in Serial Terminal, choose and connect the HC05.
#include <SoftwareSerial.h>
SoftwareSerial btSerial(10, 11);
void setup()
{
Serial.begin(9600);
Serial.println("Bluetooth test program");
btSerial.begin(9600);
btSerial.println("Bluetooth test program");
}
void loop(void)
{
if(Serial.available())
{
btSerial.print(char(Serial.read()));
}
if(btSerial.available())
{
Serial.print(char(btSerial.read()));
}
}
If your module is different than the one that I described, post a link to where you got it so we know what you have.
The HC05 modules that I have are 5V units. On the back of the module there is "Level 3.3V Power 3.6V--6V.
That means that the power (Vcc) should be 5V and the input signal (RX) limited to 3.3V. I use a voltage divider to drop the Uno 5V TX to 3.3V for the module RX.
i think this is my first mistake so i'll try to fix it first
Here is a simple test program that I use with the Serial Bluetooth Terminal app (available in Play Store). Pin 10 (Uno RX) goes to TX on the HC05. Pin 11 (Uno TX) goes to HC05 RX through the voltage divider. Use the phone settings to pair and connect the HC05 module and then, in Serial Terminal, choose and connect the HC05.
what i try to do is sending data from my app and reciving data to the same app
i'll send some pic of my HC05
thx a lot
what i try to do is sending data from my app and reciving data to the same app
The code that i posted is tested and I know that it works. Wouldn't it be nice to know that the Bluetooth works by itself with tested code before moving on? Then try with your app. Baby steps.
okay i'll try
but i want to add that with my code i can send to my up or receive from not both at the same time
i can send to my up or receive from not both at the same time
Not sure what that means.
1. Build the following circuit between your UNO and HC05.
Figure-1:
2. Check that red LED of HC05 is blinking at about 1 Hz.
3. Open BT Terminal of your Android Phone and pair it with HC05 of UNO; after pairing, the red LED of HC05 will blink once a while.
4. Upload the following sketch in your UNO.
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // SRX, STX
void setup()
{
Serial.begin(9600);
BTserial.begin(9600);
Serial.println("BTserial has started at 9600 Bd.");
pinMode(13, OUTPUT);
digitalWrite(13, LOW); //L is OFF
}
void loop()
{
byte n = BTserial.available();
if (n != 0)
{
char x = BTserial.read();
if ( x == '1')
{
digitalWrite(13, HIGH); //L is ON
}
else
{
if (x == '2')
{
digitalWrite(13, LOW); //L is OFF
}
}
}
}
5. Send 1 from ASCII Mode Smart Phone; check that L (built-in LED) of UNO is ON.
6. Send 2 from ASCII Mode Smart Phone; check that L is OFF.
7. Upload the following sketch in UNO.
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // SRX, STX
char myMsg[6];
void setup()
{
Serial.begin(9600);
BTserial.begin(9600);
Serial.println("BTserialhas started at 9600 Bd.");
pinMode(13, OUTPUT);
digitalWrite(13, LOW); //L is OFF
}
void loop()
{
byte n = BTserial.available();
if (n != 0)
{
char x = BTserial.read();
if ( x == '1')
{
digitalWrite(13, HIGH); //L is ON
}
else
{
if (x == '2')
{
digitalWrite(13, LOW); //L is OFF
}
}
}
n = Serial.available();
if(n == 5)
{
for(int i=0; i<5; i++)
{
myMsg[i] = Serial.read();
}
myMsg[5] = '\0'; //insert null-character
BTserial.print(myMsg);
memset(myMsg, 0, 5); //array reset
}
}
8. Enter any 5-character word from the InputBox of the Serial Monitor (Fig-2) of IDE and then click on the Send button. Check that the same message has appeared on the BT Screen of Smart Phone.
Figure-2:
Hi again !
GolamMostafa
everything works fine
Hello everybody
well, to make things much easier, what I want to do is : get my relay status high or low send it to my phone app and with a button turn the relay status high or low (with the same app)
thx