Create your own App! Control an ESP32 (Arduino) via Bluetooth - Part 2

  Переглядів 42,220

MoThunderz

MoThunderz

День тому

IMPORTANT UPDATE (30.09.2022): MIT App Inventor updated their Bluetooth library without backward compatibility. Might you have downloaded this code from my Github page before 30.09.2022, please download the updated version. Changes only affect the general Bluetooth connection stuff discussed in Part 1.
Part 1 of this series focused on controlling an ESP32 via Bluetooth with your phone (using MIT app inventor). In part 2 I show you how to create bi-directional communication so that the ESP32 can send information back to the phone. Might you have missed part 1:
• Create your own App! C...
Please make sure your ESP32 has Bluetooth to make this work. I used the ESP32-WROOM-32D. For creation of the app I use the MIT app inventor in combination with the MIT AI2 Companion. Note that this code will only work on Android. The reason is that BluetoothSerial does not work on an Iphone. For an Iphone only BLE works. Code for this will follow shortly...
If you want to code along, this is the starting point:
github.com/mo-thunderz/Esp32B...
For the final code, please refer to:
github.com/mo-thunderz/Esp32B...
MIT App Inventor:
appinventor.mit.edu/
Might you have problems programming the ESP32, pls refer to:
• Programming ESP32: how...
Have fun with the code and let me know in the comments below what application you are working on :-)

КОМЕНТАРІ: 63
@stever3886
@stever3886 11 місяців тому
I watched part 1 and it was amazing. Thank you for the detailed instruction, I’m a new user of the Esp32. I would have never thought I could do this. This will take my projects to the next level. I subscribed.
@mothunderz
@mothunderz 10 місяців тому
Thank you very much for your feedback. Well appreciated!
@bobdurk5180
@bobdurk5180 2 роки тому
So far so good, your tutorials and explanations are really helping to reduce the learning curve. I now want to take a control sketch I have working and see if I can use the BT App to control my audio system. Just a baby step, but it should work as proof of concept.
@mothunderz
@mothunderz 2 роки тому
Great to hear, good luck with your project!
@DWM864
@DWM864 2 роки тому
man, your videos are awesome, thank you!!
@mothunderz
@mothunderz 2 роки тому
I really appreciate your feedback, thank you!
@DavidSunshine
@DavidSunshine 2 роки тому
Thank you you for making an easy to follow video! Really appreciate your hard work in sharing your knowledge with the world! Very helpful for us who are brand new to Arduino programming. I'm trying to create an APP that can control an ESP32 to turn on fans based on temperature sensors, so this is perfect for sending and receiving temperature settings and readings back and forth!
@mothunderz
@mothunderz 2 роки тому
Thank you for your kind feedback. Sounds like a fun project!
@DavidSunshine
@DavidSunshine 2 роки тому
@@mothunderz Ya it's pretty fun! Anything Arduino is fun I'd say. I've been playing around with sending 4 temperature readings over using your method shown, but the processor is really fast, 240Mhz I think, and the phone app only captures the last ID and Value, even though my timer is set up 1ms. I had to put a 60-70ms delay between bt sends to make it work, and capture all 4 temperatures, maybe this happens because the bt sending module has a limitation. My question to you, would be, what do you think is the best way to address this? I've just though of using Millis to check the time of last send and only send if it's been 70ms, this allows the code to keep processing and not lock it up for 70ms at a time. I know it's not a big deal to lock it up, but like you said, it's good to not use delay(#) anywhere if you want to keep the code optimised and not have lags. What do you think? I was also thinking of confirming data before sending the next piece, but then you need to introduce a retry delay, not ideal. Cheers! David.
@mobileiotapps967
@mobileiotapps967 Рік тому
Hey, thank you so much for the tutorial it really helps, I was just looking for other ways to create an ESP32 app by using MIT App inventor.
@mothunderz
@mothunderz Рік тому
Glad it helped! Thank you for your feedback :-)
@qzorn4440
@qzorn4440 2 роки тому
wonderful video. i have been watching several MIT-inventor videos in comparison to the RemoteXY, which shows the remotexy-Arduino code to download to the Arduino-IDE. 🤥This video part-2 makes it clearer where to Arduino IDE code is located. Most MIT videos go in detail on the fun programming stuff. now, i can starting using MIT and the Arduino-IDE. thanks you.
@mothunderz
@mothunderz 2 роки тому
Glad to hear it worked out for you! Thank you for the feedback 👍
@srikirthikandala1305
@srikirthikandala1305 2 роки тому
Thank you so much for the tutorials. They have greatly reduced the learning time and gave me a head start. I was wondering if you could make small video on plotting graphs in the app
@mothunderz
@mothunderz 2 роки тому
Thank you very much for your feedback. Will look into plotting graphs, though at the moment I first need to find time to make the next part on how to add more controls to the webserver. Will try to get that online next week and look into plotting afterwards.
@srikirthikandala1305
@srikirthikandala1305 2 роки тому
@@mothunderz thank you so much
@joebotics8761
@joebotics8761 2 роки тому
thanks for the great tutorials!. I just had the apps working on a Samsung S10+ and ESP32.. WINNING !!!
@mothunderz
@mothunderz 2 роки тому
Dear Joe, great to hear you were able to solve the problem you had and that it is working even before I got to answer you :-) Do check out the Wifi capabilities of the ESP32 as well, I just uploaded some videos on how to connect the ESP32 to Wifi and host a webserver on it. That way you can control the ESP32 without even needing Bluetooth or an app, you can just navigate to the IP of the ESP32 with a browser on any device. Good luck with your project!
@joebotics8761
@joebotics8761 2 роки тому
@@mothunderz Dear Mo.. thanks for your prompt reply... I will look into the other tutorials you posted ... I have not looked into the WIFI alternative yet... if that is a simpler alternative then I am so interested!.. I imagine you can obtain bidirectional communication also... perhaps even faster than Bluetooth ? Thanks again!
@mothunderz
@mothunderz 2 роки тому
Yes, WiFi communication is a lot faster than Bluetooth (also more power hungry, but ok). Bidirectional communication is easy to realize with Websockets. With "webSocket.broadcastTXT(jsonString);" you send information from the ESP32 to the clients and with "Socket.send(JSON.stringify(msg));" you send information from the clients back to the ESP32. See ukposts.info/have/v-deo/aWWJZI2tfpeHyGw.html for more info on that :-)
@banchasaoraso8591
@banchasaoraso8591 2 роки тому
Very goog. After I do with your project. It can operate. Thankyou.
@mothunderz
@mothunderz 2 роки тому
Glad to hear that!
@armancodeq3642
@armancodeq3642 Рік тому
U know some people r angles....bro ur the one.
@mothunderz
@mothunderz Рік тому
Thank you very much Arman! I wish you all the best with your project. Cheers, Sander
@rizvanrazi4698
@rizvanrazi4698 2 роки тому
awesome buddy
@mothunderz
@mothunderz 2 роки тому
Thank you! Cheers!
@ZedusUA
@ZedusUA 2 роки тому
thx, was interesting
@mothunderz
@mothunderz 2 роки тому
You're welcome! And thanks for the feedback
@filtermindmusic4208
@filtermindmusic4208 2 роки тому
best tutorials!
@mothunderz
@mothunderz 2 роки тому
Thank you for your feedback :-)
@MrPanrob
@MrPanrob Рік тому
finalmente dopo tanto cercare ho trovato lei che mi ha incoraggiato ad evolvermi in questo mio "gioco" nonostante il problema di comunicazione e grazie al traduttore sono riuscito a far funzionare esp32 con mit inventor. grazie per l'impegno e il suo modo di spiegare , saluti Roberto
@mothunderz
@mothunderz Рік тому
I am glad you were able to translate my video in Italian and that you were able to make it work! Thank you for your feedback :-)
@amraouiessaid8648
@amraouiessaid8648 Рік тому
thanks a lot
@mothunderz
@mothunderz Рік тому
You are most welcome!
@shihminglin229
@shihminglin229 2 роки тому
amazing
@mothunderz
@mothunderz 2 роки тому
Thank you! Cheers!
@protoTYPElab44
@protoTYPElab44 2 роки тому
Learning a lot from this 2 video tutorial, btw i am making an app for power monitoring system where the user can view the kwh, and some other features, i a sending data back to app using esp32
@mothunderz
@mothunderz 2 роки тому
Thanks for sharing. Sounds like a very useful application. Good luck!
@hidayat9547
@hidayat9547 Рік тому
Thanks for the video. Actually I always get "bluetooth permission" problem when trying MIT inventor test. So finally I used kodular and didn't have the same problem.
@mothunderz
@mothunderz Рік тому
Thank you very much for notifying me. I just checked and MIT App Inventor updated the BluetoothClient just now. It is not backward compliant and the module simply has to be deleted and added again to work. I will update my example code on GitHub
@ibendiben
@ibendiben 2 роки тому
Dank voor je tijd en uitleg. Spreek je Nederlands? En kom je wel eens in de buurt van Den Haag?
@mothunderz
@mothunderz 2 роки тому
Yep, ik spreek Nederlands. Ik woon echter sinds geruime tijd in Munchen. Den Haag vind ik een mooie stad, maar helaas een beetje ver weg voor me. Groet, Sander
@ibendiben
@ibendiben 2 роки тому
@@mothunderz haha. Das een end idd
@boultifnidhal2600
@boultifnidhal2600 2 роки тому
Hey, thank you so much for the tutorial. I'm just having a little problem. the screen that I connect to the ESP is not the same screen that I work with. So, how can I distribute the bluetouth connexion to the whole application
@mothunderz
@mothunderz 2 роки тому
Hi, sorry, but I dont know what you mean. I show here how you can make an android app and exchange information between the ESP32 and the app. Do you mean that the app will run on different devices (such as a tables and a mobile phone)? In that case you need to detect in the app what kind of device it is and adapt the layout for that (or have a manual switch). Good luck with your project!
@boultifnidhal2600
@boultifnidhal2600 2 роки тому
@@mothunderz Thank you so much for the reply Sander, You're amazing. So What I meant is; basically my app consist of two screens. Screen1 to establish the connection with the Bluetooth of the ESP. and screen2 is used for controlling the LEDs and stuff. The problem is; when I connect to the ESP in Screen1 and switch to Screen2 I lose the connection with the ESP32. So how can I pass the establish connection with ESP to different Screens in the same App. In other words; how can I connect to the ESP via Bluetooth once and for all. Once again thank you so much for your time and consideration.
@arduinosensor8728
@arduinosensor8728 2 роки тому
Hi, how do we enter two numbers in two separate textboxes and that would be sent to the Arduino? But only one or both textboxes can be used at any time to change the corresponding values of the variables in Arduino, with a single "Send" button in app for both textboxes. Thanks in advance...
@mothunderz
@mothunderz 2 роки тому
Please see "Part 3" of the video series. I explain it there: ukposts.info/have/v-deo/nYBkabCekaSCumg.html
@sridevipindi1547
@sridevipindi1547 6 місяців тому
hi could u guide me how to send adc values to mit app... // variables to store measure data and sensor states int BitsA0 = 0; float VoltsA0 = 0; void loop() { BitsA0 = analogRead(PIN_A0); // standard converion to go from 12 bit resolution reads to volts on an ESP VoltsA0 =BitsA0 * 3.3 / 4096; String adcValue = String(VoltsA0); Serial.println(adcValue); if (ESP_BT.available()) { ESP_BT.println(adcValue); if i write ESP_BT.write(adcvalue)....it is throwing an error // otherwise if i write ESP_BT.write(VoltsA0) when i press any button the numerical value gets displayed //on the mobile screen...and everytime the number get increased by 1.....but i have to press any button } my doubt is that automatically the adc value should be displayed...without pressing the button when we rotate the pot in the serial monitor the adc value updates automaticlly....similarly as long as the bluetooth is connected , when we rotate the pot the value should be updated on the moblie screen too...without pressing any button....could u guide me pls }
@mothunderz
@mothunderz 5 місяців тому
So if I understand it correctly you do have the program working with write ESP_BT.write(VoltsA0), but it just does not update automatically, right? You should check in your ESP that upon initialization you do send out the current value to MIT App Inventor. Then you should make sure that in MIT App Inventor the value is updated in the Clock1.Timer() function.
@abishek8432
@abishek8432 Рік тому
Hey , apart from trial and error how do get precise delays , say for 10 seconds?
@mothunderz
@mothunderz Рік тому
there are two locations where you can set delays. If you want to time a delay in MIT app inventor you can do that with the clock module. In the Designer window you can set the TimerInterval to 10 seconds. In the Arduino you can time a delay with the delay(ms) function. This is in milliseconds, so delay(10000) would give you a 10s delay. However, this is not a smart way to go about because your ESP/Arduino will not do anything those 10 seconds but waiting. A better way to realize this is to use the millis() function. Just do the following -> Define a global variable first for the interval with which you want to run the code (in milliseconds): int interval = 10000; // Then define a global variable to record the last time the code was run: unsigned long previousMillis = 0; // Then in "void loop() {" do: unsigned long now = millis(); // record current time if ((unsigned long)(now - previousMillis) > interval) { // here you add the code you want to run every 10 seconds // dont forget to update the code was run: previousMillis = now; }
@sisekelocele303
@sisekelocele303 Рік тому
Help...how do you display ultrasonic sensor readings to ur mit app
@mothunderz
@mothunderz Рік тому
On your Arduino/ESP you periodically read the sensor value. Lets say the sensor value varies between 0.0 and 100.0. The Bluetooth channel only allows you to send integers, so you need to convert this number to an integer. You can do this by multiplying the sensor value with 10. If you want to send over 34.5, then you send over 345 with a new ID number you have not used yet, so for instance 14. In MIT app inventor, the function that periodically checks for incoming Bluetooth messages is the section that starts with "when Clock1.Timer". In this section received messages are just written to a text field. Instead of writing it to the text field you can check the ID to make sure that ID == 14 so that you know it is a sensor value. Then you combine the two received data bytes with 128*val_byte1 + val_byte2 (is already there in the blue section). Before displaying this number you now have to divide it with 10 and you are done. Good luck! NOTE: I just noticed that there was an update in the Bluetooth library of MIT app inventor. If you build everything up from scratch you have no problem, but if you use my github pages you will need to replace the BluetoothClient module. I will fix this in the coming days.
@sisekelocele303
@sisekelocele303 Рік тому
@@mothunderz thank you so much
@ananyavgupta2740
@ananyavgupta2740 10 місяців тому
how to send the recieved data from the esp to speech
@mothunderz
@mothunderz 10 місяців тому
What exactly do you mean with "speech"? Thank you
@ranjithshetty7078
@ranjithshetty7078 2 роки тому
Sir can yoy make physical switch feedback status in mit app. Please ease🙏
@mothunderz
@mothunderz 2 роки тому
If you have a physical switch connected to your ESP32, you can read the status of that switch periodically and write any changes to the state of the switch to the Bluetooth interface. So for instance if your switch is detected between ground and pin 16 you can write in the setup: pinMode(16, INPUT_PULLUP); and then in the main code you can read the state with: int switchVal = digitalRead(16); That should do the trick. Good luck with your project!
@ranjithshetty7078
@ranjithshetty7078 2 роки тому
Thank you sir
@navindujayawardhane285
@navindujayawardhane285 2 роки тому
hello please can you give new video this project how to make android app in android studio
@mothunderz
@mothunderz 2 роки тому
I have not worked with Android studio directly. It is limited to Android only, so I am now looking into Angular and React Native. A steep learning curve, but interesting programming languages. I am not yet at the level where I want to be, so will take some time for me to do a vid about that.
@navindujayawardhane285
@navindujayawardhane285 2 роки тому
@@mothunderz thanks alot
Create your own App! Control an ESP32 (Arduino) via Bluetooth - Part 1
18:18
SMART GADGET FOR COOL PARENTS ☔️
00:30
123 GO! HOUSE
Переглядів 20 млн
I PUT MY ARMOR ON (Creeper) (PG Version)
00:19
Sam Green
Переглядів 3,1 млн
The Cheapest Microcontroller? Getting started with the 10 cent Puya PY32.
21:36
Zach of All Trades
Переглядів 21 тис.
How Las Vegas' Sphere Actually Works
17:41
MegaBuilds
Переглядів 340 тис.
MIT Maker Portfolio (Admitted EA Class of 2028)
2:00
Theme
Переглядів 56 тис.
ESP32 Guide 2024 | Choosing and Using an ESP32 Board
41:06
DroneBot Workshop
Переглядів 196 тис.
Control Anything With IOT Easy Internet of Things with ESP32 and Arduino
17:56