Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino UNO, HC-05 Bluetooth Module and Android App

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Joined
Dec 4, 2011
Messages
817
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Activity points
6,492
Please let me know I wrote a arduino code to send sensor data serial port and received by my own made Android App, all is running well but problem is the ADC value is not showing in increase or decreasing manner but show 234 235 233 244, one value then next value is show after first value. All values should be display on same place where I set it.
 

...and how do you think we can help in this regard?
...without informations

Klaus
 

hello,

We can't know, on wich side could be your problem .. Arduino or Android ?
What software did you use for the Android application .. is it a standard program like "Bluetooth terminal "
or DIY with Appinventor2 or RFObasic ..or pure java ?

Bluetooth Android , is very versatil with end of message
sometime CR ( 0x0D=13) as message terminator
sometime CR + LF (0xOA=10) 2 bytes
or the revers LF + CR
also with could use RAW ascii or UTF8, UTF16
Too much details to check ...

Nota:
you can use another Phone Android to check Bluetooth exchange
with same android software (ie Bluetooth terminal" on both sides.
 

Below is my Android Studio Code for receiving 2 sensors data from 2 ADC channels A0 and A1 of Arduino UNO.
Code:
     @Override
        public void run() {
            final InputStream inputStream;
            try {
                inputStream = hc05Socket.getInputStream();
                while (!hc05Stop) {
                    byte[] buffer = new byte[256];
                    if (inputStream.available() > 0) {
                        inputStream.read(buffer);
                        int i;
                        for (i = 0; i < 7; i++) {
                            strInput = new String(buffer, 0, i);
                        }

                            fsr1 = strInput.substring(0, strInput.indexOf(","));
                            fsr2 = strInput.substring(strInput.indexOf(",") + 1);

                        FSR1.post(new Runnable() {
                                @Override
                                public void run() {                                
                                    FSR1.setText(fsr1);
                                    System.out.println(fsr1);

                                }
                            });
                       
                        FSR2.post(new Runnable() {
                            @Override
                            public void run() {
                                FSR2.setText(fsr2);
                                System.out.println(fsr2);
                            }
                        });

                    }
                    Thread.sleep(1000);
                }
            } catch (IOException e) {
// TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
// TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

Code:
#include <SoftwareSerial.h>
SoftwareSerial bt(2,3); // HC-05 bluetooth module connected here
int f1 = A0;
int f2 = A1;
int f1_data = 0;
int f2_data = 0;
void setup(){
   pinMode(f1, INPUT);
   pinMode(f2, INPUT);
   Serial.begin(9600);
   bt.begin(9600);
}
void loop(){
f1_data = analogRead(f1);
delay(50);
f2_data = analogRead(f2);
delay(50);
bt.print(f1_data);
bt.print(",");
bt.print(f1_data);
delay(1000);
}



Also exception occuring: StringIndexOutOfBoundsException: String index out of range: -1
 

hello,

try to printout the "strInput" value....to chek what you get before to separate the 2 fields of data
remember, a string must contain a zero value at the end of data ..
or a marker like CR or LF in the input stream
 
hello,

try to printout the "strInput" value....to chek what you get before to separate the 2 fields of data
remember, a string must contain a zero value at the end of data ..
or a marker like CR or LF in the input stream
Code:
    @Override
        public void run() {
            final InputStream inputStream;
            try {
                inputStream = hc05Socket.getInputStream();
                while (!hc05Stop) {
                    byte[] buffer = new byte[20];
                    if (inputStream.available() > 0) {
                        inputStream.read(buffer);

                        int i;
                        for (i = 0; i < 8; i++) {
                            strInput = new String(buffer, 0, i).trim();
                        }
                        try {
                            if (!(strInput.length() > 7)) {
                                System.out.println(strInput.length());
                                fsr1 = strInput.substring(0, strInput.indexOf(","));
                                fsr2 = strInput.substring(strInput.indexOf(",") + 1);
                            }
                        }catch (Exception e){
                            System.out.println(e);
                        }
                        FSR1.post(new Runnable() {
                                @Override
                                public void run() {                                 
                                    FSR1.setText(fsr1);
                                    System.out.println(fsr1);

                                }
                            });
                        
                        FSR2.post(new Runnable() {
                            @Override
                            public void run() {
                                FSR2.setText(fsr2);
                                System.out.println(fsr2);
                            }
                        });

                    }
                    Thread.sleep(1000);
                }
            } catch (IOException e) {
// TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
// TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

I put if condition to check if strInput > 7 then ignore otherwise come in and it is running without crash but I am not satisfied yet..
I sent a adc values of 2 sensors but sensors not connected only testing purpose adc values.
 

hello,

but I am not satisfied yet..
?????

Appinventor2 could be more easy to handle this Arduino application !
Even i am working only with Microchip PIC ..
example with 2 temperatures sensors ( LM35DZ analog or DS18B20 OWS)

HC06_Tempe_DS18B20_with_alarmes_Designer_170320.jpg
 
hello,

?????

Appinventor2 could be more easy to handle this Arduino application !
Even i am working only with Microchip PIC ..
example with 2 temperatures sensors ( LM35DZ analog or DS18B20 OWS)

View attachment 165648
But I did not use App Inventor, is it easy than Android Studio?
 

Hello,

i tried myself to use "Android Studio" , but i think it is a to heavy environnement
dedicated mainly for professional use ..
so, Yes, easier than Java ...
even pure Java could be the must, because Appinventor2 uses java !

You could build many little application with appinventor2 .

Subscribe on Google to open an account & password
then you can open "MIT APP INVENTOR"
go to the Gallery

you can IMPORT my (shared/public) application
and adapt it to you ..
or download the resulting *.apk after buiding.

on my web page ,you can access also to the PIC 12F1840 mikroC source application
to see , how i send the 2 values trough bluetooth...
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top