Controlling LED's from my phone via BluetoothLE

You have a huge Block - Integers Received

Hi Muhammad

Well, there are a huge number of errors in the App Project. I can see that the original file was created by someone else (it's using a very early version of the BLE extension) and you have modified it to fit your requirements but in so doing it is well and truly broken :upside_down_face:

What I would like to know - is this your personal project or is it an assignment from college or university? If it's personal, I can just fix it for you, though I can't test it, I don't have the microcontroller. If it's an assignment I should only give guidance for you to fix it.

Dear @Muhammad_Zulkifli, (and @ChrisWard),
while looking to your post and Arduino .ino file, I noticed that there isn't the declaration of the costants LEDR, LEDG, LEDB, therefore I've searched in the .h file whether they were there. During this search I found this link that states that there is an incompatibility between BLE and the embedded LED's drivers. Please take a look to it:

Maybe it's not your case, but before getting crazy with the SW, be sure that the HW is the good one :roll_eyes:.
Best wishes.

1 Like

Hi Muhammed

Well, pretty much impossible to guide you through the changes without making them.

App Inventor Project:
Instead of a BLE send event for every button, share just the one BLE send with all the LED buttons - all you do is make a list of the buttons and use an "any component" block to find which one has been tapped.

The Arduino Sketch is expecting numbers, so I have given it an integer Characteristic and the App a BLE send integer block.

The App needs to show the User the Status of each LED, so I have added a Label for each pair of buttons (on/off pair). The label background is coloured green for on, light grey for off.

For Android versions below v12, I have added a Location sensor to trigger the phone's Location setting. Location is a Google security requirement. You already had the BT Classic Client, which adds relevant permissions to the App's manifest file. This would normally be done by the MIT BLE Extension, but it requires an update for the latest Android versions.

For Android v12+, it is necessary to ask the User for permissions. Therefore, we need a tiny Extension to determine the Android version - I have added my colleague Anke's extension "GetApiLevel" for that task.

I have also updated the MIT BLE Extension to the latest version 20201223.

You have a disconnect button and it should work but note that there isn't actually a Bluetooth function for disconnection - so this is defined in the MIT Extension but not guaranteed to work with every board/BT module.

LED_Control_HM10_AA.aia (196.6 KB)

Arduino Sketch:
I noticed that the constants LEDR, LEDG, LEDB were not declared but it looks to me like they are defined by the Sketch developer, Mr Cobak? I have removed them and trusted that your circuit using pinModes 5 to 9 is correct. The Sketch now compiles without error (usually there are issues with the Arduino Nano 33 range). However, while writing this, Ugo's post arrived on the Topic and it looks like there could still be some issues to solve before we get your project to work :roll_eyes: I do not have a Nano board so all of the code changes I have made are untested.

LED_COBAK3.ino (4.3 KB)

So, without changing anything, upload the Sketch to the Arduino and compile the App Inventor Project as an APK. Let's see what happens!

1 Like

If the new files are an abject failure we will need to see the connections to the board more clearly :thinking:

Yes sir, that original file created by someone and then I edited it to compatible for my project
I took it from the Arduino forum which I think fits my current project. the link is below

To be honest, this is my final assignment so I can graduate from college

Sometimes trying to work with existing files is more difficult than starting from scratch :upside_down_face: You have however put in a lot of effort and you are learning along the way.

Let's see how you get on with the modified files I have uploaded. Your Project requires concentration, attention to detail and that has been missing because you have not had time to dedicate to it.

Once you get it working properly, that's not the end, spend some time to 'beautify' the GUI.

I've used it and the bluetooth can connect smoothly to my android via the lightblue application

How to make it sir? I have to learn it for my classmate

I've update it for long time ago, so there is no features updateable in my Android. So what should I do to trigger the phone's location setting?

I get it sir, so I edited it in such a way as to suit my project

No sir :smile:, 'cobak' is my languange that means 'try' I'm from Indonesia sir :wink:

I'm sorry sir, I don't have any app to making board because my PC has restarted due to a virus :frowning:

I have experienced that, sir, there are many assignments and there are also many demands from my lecturers

Just run the App in Companion to see how that works. Best not to use Companion when testing Bluetooth though, use an APK).

It's possible to use Activity Starter, but for now switch Location on and Bluetooth on before running the App.

Study my changes in LED_COBAK3.ino

:joy: So, I followed the link to the Arduino Document and it seems that code is flawed with respect to the LED constants. Since your Project is not using those constants, I deleted them in LED_COBAK3.ino

image
I've checked it out sir, and I found that number 10 is unidentified. So I changed the 10 to 0
I check it from my lightblue application first to check that bluetooth can connect or not

image
I have tried also in MIT App. That shows an error like that sir
What kind of error is that? And how do i fix it

or should I add the Characteristic UUID in 'initialize global'?

No, leave it where it is