Arduino UNO + BLE HM-10 and MIT app inventor. Desperately need help

Sorry in advance if this is long or in the wrong section, I am still figuring out where to put questions like these. I feel like they fit in multiple categories.

Alright it’s been about 1 week of utter frustration in trying to get this to work with only error after error that never ends.

The reason I want to control this LED is just to get started with understanding how to use this module but I can’t even do that.

All I’m trying to do is control an LED with this bluetooth module and my arduino using an app on my android phone. I have searched endless times and looked at this link from marco_c to get started:

I tried doing exactly what they said on the blog after reading it through even though I couldn’t grasp some parts. But I could never get the sketch parts from the blog since marco_c said they weren’t able to upload it for reasons.

I’ve tried making an app for the phone using evothings but apparently they don’t support BLE so I am using MIT app inventor 2 now but I just can’t seem to get it right.

Whenever I think I get it right, suddenly the sketch just doesn’t upload and gives me “error uploading sketch” or it never finishes uploading and just hangs. I heard online that the 0 and 1 DPs must be disconnected when uploading a sketch and then reconnected to the tx and rx of the bluetooth module after so that’s what I’ve been doing. Otherwise it actually doesn’t work through my experience.

I’m sorry if this is asking a lot but if anyone has some basic code for the MIT thing and a sketch ( I don’t mind copying pictures if that’s all you have) that I can at least study or use myself just to understand more.

If you don’t have a sketch or anything then I have a couple small questions that I’m still stuck on.

In MIT app inventor I don’t understand what all the addresses do. I have no idea whether to put the exact address for the bluetooth module (serial and characteristic, I know which those are), or just something different. Each tutorial I watch uses a completely different method of connecting the two.

My educated guess is that the service uuid is 0000ffe0-0000-1000-8000-00805f9b34fb
and the characteristic uuid is 0000ffe1-0000-1000-8000-00805f9b34fb
But they don’t do anything for me.

Another question is how can I get the serial monitor to tell me…anything? All throughout this process I haven’t seen anything printed on the monitor or the arduino program tells me COM3 is busy so I can’t open it. I know to include the library and put “Serial.begin(9600);” and how to print on it using “Serial.println or just print”

I will put the last sketch I’ve been trying to use here for anyone who wants to see.

#include <SoftwareSerial.h>

#include <LedControl.h>

#include <BLEPeripheral.h>


#define LED 7

BLEPeripheral blePeripheral;  // BLE Peripheral Device 
BLEService ControlLED("19B10010-E8F2-537E-4F6C-D104768A1214"); // BLE AnalogRead Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedIntCharacteristic LEDStatus("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite  );
int bluetoothTx = 0;
int bluetoothRx = 1 ;
int incom = 0;
int last_incom = 0;

void setup() {
  Serial.begin(9600);
  // set Light pin to output mode
  // set advertised local name and service UUID:
  blePeripheral.setLocalName("ControlLED");
  blePeripheral.setAdvertisedServiceUuid(ControlLED.uuid());

  // add service and characteristic:
  blePeripheral.addAttribute(ControlLED);
  blePeripheral.addAttribute(LEDStatus);

  // begin advertising BLE Light service:
  blePeripheral.begin();

  Serial.println("BLE AnalogRead service.");
  pinMode(LED, OUTPUT);
}

void loop() {
  // listen for BLE peripherals to connect:

  BLECentral central = blePeripheral.central();
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      //Serial.println(LEDStatus.written());
      if (LEDStatus.written())
      {
        incom = LEDStatus.value();
        Serial.print("incom ");
        Serial.println(incom);
        if (incom != last_incom)
        {
          if (incom == 1)  //integer 1
          {
            Serial.println("LED On");
            digitalWrite(LED, HIGH);
          }
          else             //integer 0 in our case
          {
            Serial.println("LED Off");
            digitalWrite(LED, LOW);
          }
        }
        last_incom = incom;
      }
    }
    delay(100);
  }

  // when the central disconnects, print it out:
  Serial.print(F("Disconnected from central: "));
  Serial.println(central.address());
}

And I will attach my MIT thing

Thanks so much to anyone who at least read this because I’m sure it’s a lot and probably asking too much but I’m completely at a loss here and can’t get anything right no matter what I do.

You have a number of unrelated issues going on here. The key is to divide and conquer:

Dean_Bean: Whenever I think I get it right, suddenly the sketch just doesn't upload and gives me "error uploading sketch" or it never finishes uploading and just hangs. I heard online that the 0 and 1 DPs must be disconnected when uploading a sketch and then reconnected to the tx and rx of the bluetooth module after so that's what I've been doing. Otherwise it actually doesn't work through my experience.

Upload errors are unrelated to your app or your Arduino sketch. As you say, connecting anything to the Arduino pins 0 and 1 can cause an upload to fail because on common Arduino boards such as Uno, Nano, Mega those pins are used for serial communication for the computer which is used to upload sketches to your Arduino.

Dean_Bean: Another question is how can I get the serial monitor to tell me...anything? All throughout this process I haven't seen anything printed on the monitor or the arduino program tells me COM3 is busy so I can't open it. I know to include the library and put "Serial.begin(9600);" and how to print on it using "Serial.println or just print"

Forget about the Bluetooth module and the App. Write a simple sketch that simply prints something and make sure you can see it on the Serial Monitor:

void setup() {
  Serial.begin(9600);
  while(!Serial){}
  Serial.println("hello");
}

void loop() {}

Note this line:

Serial.begin(9600);

That configures serial communication at 9600 baud. You also need to set the baud rate menu at the bottom right corner of Serial Monitor to 9600. You can set other baud rates than 9600 but they always must match between the sketch and the Serial Monitor.

Note that pins 0 and 1 on standard Arduino boards are also used for serial communication with your computer. That means if you connect something to those pins it could interfere with your ability to print things to Serial Monitor.

pert:
You have a number of unrelated issues going on here. The key is to divide and conquer:
Upload errors are unrelated to your app or your Arduino sketch. As you say, connecting anything to the Arduino pins 0 and 1 can cause an upload to fail because on common Arduino boards such as Uno, Nano, Mega those pins are used for serial communication for the computer which is used to upload sketches to your Arduino.
Forget about the Bluetooth module and the App. Write a simple sketch that simply prints something and make sure you can see it on the Serial Monitor:

void setup() {

Serial.begin(9600);
  while(!Serial){}
  Serial.println(“hello”);
}

void loop() {}



Note this line:


Serial.begin(9600);



That configures serial communication at 9600 baud. You also need to set the baud rate menu at the bottom right corner of Serial Monitor to 9600. You can set other baud rates than 9600 but they always must match between the sketch and the Serial Monitor.

Note that pins 0 and 1 on standard Arduino boards are also used for serial communication with your computer. That means if you connect something to those pins it could interfere with your ability to print things to Serial Monitor.

Ok thanks for the speedy reply, I was able to get the serial monitor to print just like before I started this project. I used the same code and it said hello, I also tried using another tiny sketch to see if I could get AT commands working but nothing showed up. I typed AT+HELP and clicked send but nothing happened

Dean,

I am passing for a very similar situation as you described. Did you make some progress on your project?

Can you share the App inventor aia file and/or screenshot? I believe that following examples is a good way to learn and contribute.

Thanks !