Serial data sent to arduino through app displayed on mobile

hI,
my app receive 2 values from arduino through bluetooth connection the data displayed correctly when i press on led on button it turns led on and data @ index 1 appeared preceding by sent value how i remove it

bluetooth_smart_home_3.aia (3.3 KB) bluetuth_led_temp.txt (1.5 KB)

How is the Arduino send code?

Serial.println (????

One way to erase part of a text is by using the block:
replace all text
segment
repacement

1 Like

Hi,
can you show me how to modify current program

Show Arduino code.

#include <dht.h>
char incoming_value=0;
String text;
String value;
dht DHT;
int tempPin1 = A0;
int timer=0;

void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop() {
readstatus();
//readstatus1();
readtemp();

}

void readtemp()
{
int chk = DHT.read11(tempPin1);
value = (String) DHT.temperature + "," + (String) DHT.humidity ;
Serial.println(value);
//Serial.println(DHT.temperature);
//Serial.println(DHT.humidity);
delay(200);
}

void readstatus()
{while (Serial.available())
{ delay(100);
char c = Serial.read();
text += c;
}
if (text.length() > 0)
{
Serial.print(text);
if (text == "1")
{
digitalWrite(13, HIGH);
}
if (text == "0")
{
digitalWrite(13, LOW);
}
text = "";
}
}

void readstatus1()
{
if(Serial.available()>0)
{ char c = Serial.read();
text += c;
incoming_value = Serial.read();
Serial.print(incoming_value);
//Serial.println("\n");

if (incoming_value=="1")
digitalWrite(13, HIGH);
else if (incoming_value=="0")
digitalWrite(13, LOW);
}
incoming_value = "";
}

void readstatus2(){
if (Serial.available()>0);
{
char data = Serial.read();
Serial.print(data);
if(data == "1")
{
digitalWrite(13, HIGH);
}
else if (data == "0")
{
digitalWrite(13, LOW);
}
data = "";
}
}

In procedures readstatus and readstatus1 and readstatus2,
comment out the

  • Serial.print(incoming_value) and
  • Serial.print(incoming_value) and
  • Serial.print(data).

Then you won't have to worry about removing them from the data stream on the other end.