Transmitting Voltage Value

Is there anything wrong with my code?

I have already tested bluetooth communication using another code on arduino and its working. I can send strings to a test app called “s2 Terminal for Bluetooth”. I also receive the strings typed in this app in my serial monitor. So I confident to say that the problem is not in the hardware and wires connections.

I also have tested the hardware measuring temperature and voltage. Its working and displays the results correctly. The problem is when I try to merge both.


/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "3473f8737181435c96f0f379817e96c8";

/*
The simplest TMP 36 Thermometer
*/
const int analogIn = A4;

int RawValue= 0;
double Voltage = 0;
double tempC = 0;
double tempF = 0;
BlynkTimer timer;



void setup(){  
 Serial.begin(9600);
 Blynk.begin(Serial3, auth); //I'm using pins 15 and 14 for RX and TX

  Serial.println("Waiting for connections...");
  timer.setInterval(1000L, myTimerEvent);
  
}

void myTimerEvent()
{


  RawValue = analogRead(analogIn);
  Voltage = (RawValue / 1023.0) * 5000; // 5000 to get millivots.
  tempC = (Voltage-500) * 0.1; // 500 is the offset
  tempF = (tempC * 1.8) + 32; // conver to F  
  Serial.print("Raw Value = " );  // shows pre-scaled value                    
  Serial.print(RawValue);      
  Serial.print("\t milli volts = "); // shows the voltage measured     
  Serial.print(Voltage,0); //
  Serial.print("\t Temperature in C = ");
  Serial.print(tempC,1);
  Serial.print("\t Temperature in F = ");
  Serial.println(tempF,1);
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5,  Voltage);
}

void loop(){

  Blynk.run();
  timer.run();
  
}

Serial Monitor:

Configuration of bluetooth and data stream - blynk

There is no need in delay(1000) call at the end of myTimerEvent

I removed that delay, but it’s still not transmitting. I have already tested the code without the bluetooth, just printing the voltage values on serial monitor and it works. Thx for your fast reply!

Are you trying to setup Software Serial on the same pins as the standard, hardware UART? This will not work!

I changed to port 14 (tx3) and port 15 (rx3), but still not working. I’m using arduino mega 2560. Thx for your help!

Then DON’T use Software Serial… use Serial1, Serial2 or Serial3 depending on the pins you chose.

NOTE the Sketch builder examples for the Mega and BT/BLE are incorrect… they should be using Serial1 as in this example

Sure! If it’s Mega, forget about SoftSerial!
…And show us the serial output from serial :slight_smile:

I tried to upload a picture, but It did not work. Well, I have done the changes, but I still cant receive voltage stream on superchart. Thx for your answer again, even if not working I was able to learn :slight_smile:

Well, I have done the changes, but I still cant receive voltage stream on superchart. Thx for your answer again, even if not working I was able to learn :slight_smile:

Make sure you have the serial pins wired properly… RX on the Mega goes to TX on the BT module and visa versa.

And did you connect to the module properly in the App itself?

Copy and paste text of your serial monitors output instead of screenshot.

Blynk Logo

v0.5.2 on Arduino Mega

[83] Connecting…
[2184] Logintimeout
[5184] Connecting…

Best to just keep posting new info into new posts… not everyone goes back and reads your changes :stuck_out_tongue_winking_eye: I fixed your post so it shows the images (you had the closing backticks in the wrong place).

You still need to setup Serial3 with the correct begin() and BAUD commands, just like any serial port.

2 Likes

Exactly. There is no Serial3.begin(baudrate); in your code.
AND as @Gunner pointed, it NEEDS TO BE CORRECT baudrate. Those BT modules are not automatically adopted to baudrate - It needs to match on both sides. It SHOULD BE 9600 as a factory setting, but you need to make sure it is.

1 Like

Sorry for late response, I did what marvin7 and Gunner appointed and its now working. I’m here to give you this feedback and also to say thank you for both. You were nice and kept helping me, my sincere thanks to you! :slight_smile:

2 Likes

nice project

1 Like