Two mobiles. Connection Server - Client by Bluetooth. LDR trigger a relay

Hello friends,

normally we connect our mobile (or tablet) to Arduino, ESP8266, ESP32, Tiny85, ... by Bluetooth to control a device.

We are going to see how we can control a device using two Bluetooth mobiles, four LDRs and four relays.

ooooooooooooooooooooooo0000ooooooooooooooooooooooo

  • We will use a mobile and build an app to work as a Bluetooth Server. This app will have 4 buttons (up, down, left and right), it will send a number from 1 to 8 according to those buttons are TouchDown or TouchUp.

  • Another mobile will be the Bluetooth Client, it will have an application with four circles, these circles will be filled with white or black depending on the button pressed on the Server.

1 Like

- Server Bluetooth.

  • Server Bluetooth accepts connections and sends a number from 1 to 8 depending on the Button pressed.

p9C2_Servidor_BT_LDRi.aia (27.9 KB)

1 Like

- Client Bluetooth.

  • Client Bluetooth connects with Server and receives a number from 1 to 8 and fills in a ball with black or white depending on the number received.

p9C2_Cliente_BT_LDRi.aia (5.6 KB)

  • The two mobiles must be paired, this is done in Settings.
  • For them to work, it is convenient that the applications are installed (Build .apk).
1 Like

- LDR.

Here four LDR (Light Dependent Resistor).
ldr2

  • we pack those four LDRs in a cardboard, leaving a hole as the following image indicates:
    ldr3

  • We put these four LDRs on the mobile screen, on the circles of the Client application, as the image indicates:

ldr5

  • If we measure the resistance of an LDR with an ohmmeter we will observe that its value will change between 2 KΩ (when the circle is white) and 50 KΩ (when the circle is black) [Those values ​​are just examples]
1 Like

- Relay.
ldr6

  • We can connect each LDR to a relay that will be triggered according to the resistive value of the LDR.

- Proposals.

1.- Change the circles on the Server and the buttons on the Client.

2.- Perform this same technique using CloudDB or FireBase.

3.- Use a Slider component and send luminance levels (gray tones) to the LDR, measure its value with the ohmmeter.

1 Like

JoseRafael uses this method to move a small cart.

On his YouTube channel Corcinox Inventos shows us, in Spanish, all his interesting process.

1 Like

Reply to Juan Antonio

Hi Juan Antonio,

Thank you so much for the example you provided in this post. I downloaded and tested the .aia files and found the example very helpful.

However, I am encountering a runtime error (see screenshot below).

I have ensured that all necessary settings are configured:

  • Changed "Nearby Devices" from "Not Allowed" to "Allowed"
  • Paired the two mobiles

My setup is as follows:

  • Tablet with Android 13 (Server)
  • Phone with Android 12 (Client)

On the phone, everything seems to work fine, but it cannot find the tablet due to the runtime error on the server.

Screenshot:

Do you have any suggestions on how to resolve this issue?

Thank you!

Best regards,
Josie

Nowadays you have to ask for permission
Taifun


(Canned Response ABG - Bluetooth non-BLE SCAN Permission Blocks)

The easiest solution, for immediate relief
(from @Barry_Meaker) ...

I had the same issue. The problem is your app does not have permission to see nearby devices. The solution is to give your app permission on your phone (no code changes in your app).

on your phone,

  • goto settings
  • search for your app
  • in App Info for your app select Permissions
  • change Nearby Devices from Not Allowed to Allowed
  • Done

By the way, the very first time you run the app, Android will ask if you want to grant the app this permission. If you say no, or ignore the pop-up, the permission will be set as Denied. Android will not ask again.

A more complex approach, for professional app development:

See Bluetooth liste of devices deosn't work anymore - #7 by Anke
Special note for Xiaomi devices:
I have an error with bluetooth on android 12, Xiaomi Poco X3 NFC - #20 by Patryk_F

Yes I did that. But I still get the runtime error, do you maybe have another idea?

Josie

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Hello,

I actually used Juan_Antonio project, so I did not change really anything. Did I supposed to change things?

I also added his Extension, but did not used it:
http://kio4.com/appinventor/242_extension_bluetooth.htm

Server:

Client:

unfortunately you did not follow the suggestion to ask for permission...
without that it will not work anymore
here is the link again Bluetooth liste of devices deosn't work anymore - #7 by Anke

Taifun

1 Like