5

I need help with my Arduino code. Here is my setup:

LM35 connected to Arduino with output connected to Analog 0.

Temperature computation work and serial monitor displays the correct reading.

I want to connect via Bluetooth to an Android app to display the temperature.

It displays it a few times but 98% of the time it doesn't display it on the app. I'm thinking the problem may be in the code that I have:

#include <SoftwareSerial.h>

#define RxD 6
#define TxD 7

float temp;
int temperaturePin = 0;
float  temp1;
SoftwareSerial blueToothSerial(RxD, TxD);

void setup() {
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
}

void loop() {
  temp = analogRead(temperaturePin);
  temp1 = temp * 0.48828125;
  Serial.print(temp1);
  delay(1000);
  blueToothSerial.print(temp1);
  delay(1000);
}

I just really want to make it simple. Kindly help.

closed as off-topic by Chris Stratton, MatsK, user31481, gre_gor, KIIV Oct 14 '17 at 6:31

  • This question does not appear to be about Arduino, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are you using the HC-05 Bluetooth module? – Adrian Nov 20 '15 at 23:52
  • yes - I figured it out already Adrian. the code found on this link is simpler and it worked [link] (pastebin.com/343EUh4v). I just need to run the code first in arduino before putting/connecting the bluetooth shield – coollearner Nov 22 '15 at 15:15
  • 3
    I'm voting to close this question as off-topic because the asker reports in comments that it has been solved, however in an illogical manner. – Chris Stratton Oct 13 '17 at 17:01
0

You need to terminate the string sent by adding blueToothSerial.println(""); after blueToothSerial.print(temp1);. As it is the code doesn't terminate the temperature string with an LF char, and the Android app thinks it hasn't received the full string yet.

void loop() {
  temp = analogRead(temperaturePin);
  temp1 = temp * 0.48828125;
  Serial.print(temp1);
  delay(1000);
  blueToothSerial.print(temp1);
  blueToothSerial.println("");
  delay(1000);
}
-2

try to use Pin 1 and 2 for your bluetooth and change the code

  • Can you explain more? This is pretty brief. Change the code to what? – Nick Gammon Aug 19 '16 at 11:22
  • 1
    This is a very bad idea - these would incompletely overlap the hardware serial pins. And of course answers with no explanation are suspect, even when (unlike this) there could be some logic behind them. – Chris Stratton Oct 13 '17 at 17:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.