1

Currently, I have an Arduino Uno set up, with a HC-SRO4 ultrasonic sensor printing distances of objects in front of it on a scale from 1-15 to the serial monitor. I want to attach the HC-05 bluetooth module and do the following: First, it will read the values from the serial monitor. Then, I would like the HC-05 module to take these numbers and continuously send it to my Android app, which will then process what to do with the numbers.

I understand the Android part may be out of scope of this forum, but please try to help me with taking data from the serial monitor and have it transmit the data.

Here is the code I have for the ultrasonic sensor:

const int trigPin = 9; 
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
}
void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
}
  • 3
    You don't have to take data from serial monitor. Just use the same data and send it via HC-05. You only have to add instructions to your current sketch. For debugging purposes, keep sending data to serial monitor while you work on the Android part of it. – user31481 Sep 9 '17 at 11:47
  • What is the actual code used to get the HC-05 to transmit the data so that my Android app can pick it up? – Sanjiv Prasad Sep 9 '17 at 12:46
  • 1
    You're using an uno so you'll need to use the software serial library. Get the hc05 working with software serial. Run a Bluetooth terminal monitor on your Android and make sure you can see the hc05 output. – Squats Sep 9 '17 at 13:29
1

First, it will read the values from the serial monitor. Then, I would like the HC-05 module to take these numbers and continuously send it to my Android app, which will then process what to do with the numbers.

No. What you do is you connect your Bluetooth module to two digital pins, which you'll use, along with the SoftwareSerial library, just the way you are using currently the Serial object. Look at the SoftwareSerial examples in the IDE.

Before you use the HC-05 module, and transmit data, you'll have to make sure it is set up properly (baud rate, name, PIN code, etc). Plenty of code and tutorials on Google about that.

0

Use software serial library and connect your HC-05 TX RX pins accordingly, to transmit/recieve the ultrasonic data using bluetooth. From playstore you will get bluetooth terminal software. Install it in your smart phone. Now connect your phone's bluetooth to HC-05 using that software. Now you can see in that app, all data you are receiving via bluetooth. you can also transmit data using that app. If you want to develop your own app, maybe you can check out MIT app inventor. Simple and fast.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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