Go Down

Topic: Bluetooth Data Log Help (Read 178 times) previous topic - next topic

mpeli

Hello. I just bought my first arduino uno last summer and I am now trying get acquainted with my new device. I am currently working with a microphone that outputs sound levels via LEDs (got the program and idea from here: https://www.youtube.com/watch?v=lsW3upcvsxg) and a bluetooth module HC-05 (6pin). My project is simple, print the information that the microphone sends to the LEDs on an android via the bluetooth module. My real problem is, I have no idea what code to use. I currently have this code for the microphone and led function:
Code: [Select]
void setup() {
  pinMode(DO_pin, INPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  Serial.begin(9600);
}
 
void loop() {

    if (sound > 31) {
    digitalWrite(led1, HIGH);
  }
    if (sound < 31) {
    digitalWrite(led1, LOW);
  }
    if (sound > 35) {
    digitalWrite(led2, HIGH);
  }
    if (sound < 35) {
    digitalWrite(led2, LOW);
  }
    if (sound > 40) {
    digitalWrite(led3, HIGH);
  }
    if (sound < 40) {
    digitalWrite(led3, LOW);
  }
    if (sound > 45) {
    digitalWrite(led4, HIGH);
  }
    if (sound < 45) {
    digitalWrite(led4, LOW);
  }
    if (sound > 50) {
    digitalWrite(led5, HIGH);
  }
    if (sound < 50) {
    digitalWrite(led5, LOW);
  }
  sound = analogRead(AO_pin);
  Serial.print(digitalRead(DO_pin));
  Serial.print("-");
  Serial.println(analogRead(AO_pin));

 
 
}

As mentioned before, I want to be able to print the data via bluetooth on an android phone. I would appreciate if someone could provide me with the code necessary for such function.
Note: It is my first project with arduino uno. I have no expertise with arduino programming. 
Thanks in advance.

Nick_Pyner

Assuming the code you post works:

1. you appear to have an analogue read in the range of 30 > 50, variable name sound, which is used to light the LEDs.

2. If you use any pin other than D0,D1 for the input, you can use D0,D1 for connection to bluetooth in the normal manner.

3. You can then  simply Serial.println(sound) to Bluetooth, which may then be sent to phone. If you use Bluetooth Graphics Terminal, you can show the output on a live graph.

The code looks junky and incomplete, there is surely a better way than this. For bluetooth,
you might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino


PaulS

Quote
My project is simple, print the information that the microphone sends to the LEDs on an android via the bluetooth module.
This does not make sense.

The "information that the microphone sends to the LEDs" is nonsense. The microphone does not send any data anywhere. The Arduino pulls data from the microphone.

Based on the value read from the microphone, it turns zero or more LEDs on.

You could send that value to the Android.

Quote
I would appreciate if someone could provide me with the code necessary for such function.
If the bluetooth device is connected to the hardware serial port, the code is already there. If it is connected to other pins, you need to create an instance of SoftwareSerial, and use that instance's print() or println() method to send the data to the bluetooth device.
The art of getting good answers lies in asking good questions.

mpeli

#3
Sep 14, 2016, 08:01 pm Last Edit: Sep 14, 2016, 08:07 pm by mpeli
Assuming the code you post works:

1. you appear to have an analogue read in the range of 30 > 50, variable name sound, which is used to light the LEDs.

2. If you use any pin other than D0,D1 for the input, you can use D0,D1 for connection to bluetooth in the normal manner.

3. You can then  simply Serial.println(sound) to Bluetooth, which may then be sent to phone. If you use Bluetooth Graphics Terminal, you can show the output on a live graph.

The code looks junky and incomplete, there is surely a better way than this. For bluetooth,
you might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino


Thank you for the quick response. Yes, the code works (even though junky) and lights up the correct led when needed. The D0 and D1 are available for the BT connection. I was using those notes to understand a bit the arduino and bluetooth, but I still have some problems. My idea was to be able to recieve the range data as a spreadsheet on the celphone via bluetooth. As stated before, my knowledge on the matter is very limited, hence I requested help. If you could see the video link posted on the top, you can see all the connections made on the arduino.

This does not make sense.

The "information that the microphone sends to the LEDs" is nonsense. The microphone does not send any data anywhere. The Arduino pulls data from the microphone.

Based on the value read from the microphone, it turns zero or more LEDs on.

You could send that value to the Android.
If the bluetooth device is connected to the hardware serial port, the code is already there. If it is connected to other pins, you need to create an instance of SoftwareSerial, and use that instance's print() or println() method to send the data to the bluetooth device.
I am sorry for the vague and incomplete explanation. My knowledge is limited on the matter. The Bluetooth turns on but the leds immediately light up andstead of reading the microphone. I am sure there may be a faulty connection on the 5v side. Any help on the matter is welcomed

Go Up