Serial.println communication with the HC-05 module

Hi. I want to send the data that I obtain from sensors from the command Serial.println to the phone through the Bluetooth module HC-05, but with the code that I'm using I can only send to the phone the data that I type in the serial monitor of the pc. I would be really grateful if someone could help me with this issue. Here is the code that I'm using: (In this case, I'm testing the module with the detection of a PIR sensor, I want to receive the "Motion detected" or "No motion" in the phone).

int sensorPin= 7;  
int val = 0; 

#include <SoftwareSerial.h>  
SoftwareSerial BSerial(2,3);  

void setup() {
  Serial.begin(9600);   
  BSerial.begin(9600);  

  pinMode(sensorPin, INPUT);
for(int i = 0; i > 30; i++) 
{
delay(1000);
}
delay(50);
}

void loop() {
if (BSerial.available()) {     
    Serial.write(BSerial.read());
  }

  if (Serial.available()) {      
    BSerial.write(Serial.read());
  }

  val = digitalRead(sensorPin);
if (val == HIGH) 
{
Serial.println("Motion detected!");
}
else 
{
Serial.println("No motion");
}

What type of sensors are you using ?
Can you read the data from the sensors and print it to the Serial monitor ?

Instead of

Serial.println("Motion detected!");

have you tried

BSerial.println("Motion detected!");

Oh, perfect, now it works, thank you so much, I'm new to programming.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.