0

I am working on a small project where I have to read data from different hardware and display it on android app. I am using arduino Uno to get the values from a sensor and a motor and I use a bluetooth module to send the data to the android device. I know how to read data from motor only but not from motor AND sensor. The data displayed on the arduino can be assumed as follows:

Motor: 132

Sensor: 258

Motor: 259

Sensor: 992

So first, we will read the value of the motor then the sensor then the motor and so on. Here is part of the code where I used handler and string builder to read data from the motor. How to modify the code in order to read from BOTH the motor and sensor and keep the updating the values?

Code:

Handler mHandler = new Handler()
 {
 public void handleMessage(android.os.Message msg) {
 switch (msg.what) {
 case 1: 
 byte[] readBuf = (byte[]) msg.obj;
 String strIncom = new String(readBuf, 0, msg.arg1); 
 sb.append(strIncom); 
 int endOfLineIndex = sb.indexOf("\r\n"); 
 if (endOfLineIndex > 0) { 
 String sbprint = sb.substring(0, endOfLineIndex); 
 sb.delete(0, sb.length()); 
 motor.setText(sbprint); // update TextView
 }
 break;
 }
 };
 };
asked Mar 15, 2015 at 18:11

1 Answer 1

1

You can convert each value to string before sending to bluetooth using string.contain("string"), like this:

if (sbprint.contains("C"){
 temptv.setText(sbprint);}
if (sbprint.contains("H")){
 humidtytv.setText(sbprint);} 
MichaelT
8873 gold badges8 silver badges22 bronze badges
answered Dec 25, 2019 at 8:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.