Skip to content
Home » App Inventor With Arduino | Step 3: Arduino Code

App Inventor With Arduino | Step 3: Arduino Code

HC-05 Bluetooth Module with Arduino-MIT App Inventor

Building the App – Example 1

Now we are ready to build the first example. We will start with the layout of the program. First we will add some HorizontalArrangements from the layout Palette and set their properties like the height, the width and the alignment to match our program desired look. Then from the UserInterface Palette we will add a ListPicker and attach an image to it. The ListPicker will be used for selecting the Bluetooth device to which our smartphone will connect.

Next we will add another HorizontalArrangements in which we will place a Label. This label will indicate whether the smartphone is connected or not to the Bluetooth module and that’s why we will set the initial text of this label to “Not Connected”. The next label will be used for displaying the status of the LED, whether is turned off or on. The initial state will be “LED: OFF”. Next we will add the two buttons, ‘Turn On’ and ‘Turn Off’ for controlling the LED. At this point it is good to rename the components so that we can easier recognize and use them in the Blocks editor later. What’s left now is to add the BluetoothClient which is a Non-visible component as well as a clock which will be used for the real time indication of the connection status.

Stepper Motor Control Example

Now let’s take a look at the second example, controlling a stepper motor. At the top of the screen we have the same components for the Bluetooth connection as the previous example. Next we have a Canvas component which is used for drawing and inserting images. I inserted two transparent images which I previously drew. The first one is an image of a gauge which will be fixed in place and the second one is an image of a pointer which will be rotating. Next we have a Check button for switching between Manual and Auto or continuously running mode and a button for changing the rotation direction. At the button we have a slider for changing the rotation speed of the stepper motor.

Here are the blocks and the Arduino code behind this example. So, in the Blocks editor again we have the same blocks for the Bluetooth connection as the previous example.

Now for rotating the pointer image we use the ImageSprite function “.PointInDirection” which rotates the image from 0° position to the X and Y coordinates where the Canvas has been touched. At the same time we set the rotated ImageSprite heading to the text label above. After that we call custom made procedure, or function which is actually a 10m seconds delay.

Lastly we send the heading value as a Text to the Arduino using the “SendText” Bluetooth function. This value will be accepted by the Arduino and it will rotate the stepper motor accordingly.

Next is the the CheckBox block. So if the CheckBox is checked we will send the text “Auto” to the Arduino which will activate stepper motor to rotate continuously. While we are in this mode if we press the “Reverse” button, we will send the text “Reverse” to the Arduino which will change the rotation direction of the motor. Also, while we are in this mode, we can change the speed of rotation. If we change the position of the slider, the current value of the slider position will be send to the Arduino which will change the rotation speed of the stepper. If we uncheck the CheckBox we will get back into the manual mode. Here’s the demonstration of the example.

Here’s a download file of the above MIT App Inventor project, as well as the two images used in the project:

Here’s the Arduino code of the second example:


/* Stepper Motor Control via HC-05 Bluetooth Module * * by Dejan Nedelkovski, www.HowToMechatronics.com * */ // Defining variables const int stepPin = 7; const int dirPin = 6; String state = ""; int currentHeading=0; int currentAngle=0; int lastAngle=0; int angle=0; int rotate=0; int runContinuously=0; String mode = "Manual"; boolean dirRotation = HIGH; int rotSpeed = 1500; void setup() { // Sets the two pins as Outputs pinMode(stepPin,OUTPUT); pinMode(dirPin,OUTPUT); Serial.begin(38400); // Default communication rate of the Bluetooth module } void loop() { delayMicroseconds(1); if(Serial.available() > 0){ // Checks whether data is comming from the serial port state = Serial.readString(); // Reads the data from the serial port } // When Auto Button is pressed if (mode == "Auto") { if (state == "Reverse") { delay(10); if (dirRotation == HIGH) { dirRotation = LOW; } else { dirRotation = HIGH; } digitalWrite(dirPin,dirRotation); delay(10); state = ""; } rotSpeed = state.toInt(); if (rotSpeed >= 300 && rotSpeed <= 3000) { digitalWrite(stepPin,HIGH); delayMicroseconds(rotSpeed); digitalWrite(stepPin,LOW); delayMicroseconds(rotSpeed); } else { digitalWrite(stepPin,HIGH); delayMicroseconds(1500); digitalWrite(stepPin,LOW); delayMicroseconds(1500); } if (state == "Manual"){ mode = state; } } // When Program is in Manual mode else if (mode == "Manual"){ currentHeading = state.toInt(); //Serial.println(angle); //Serial.println(state); if (currentHeading < 0 ){ currentHeading = 360+currentHeading; } currentAngle = map(currentHeading,0,359,0,200); digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction // Makes 200 pulses for making one full cycle rotation if (currentAngle != lastAngle){ if(currentAngle > lastAngle){ rotate = currentAngle - lastAngle; for(int x = 0; x < rotate; x++) { digitalWrite(stepPin,HIGH); delayMicroseconds(500); digitalWrite(stepPin,LOW); delayMicroseconds(500); } } if(currentAngle < lastAngle){ rotate = lastAngle - currentAngle; digitalWrite(dirPin,LOW); //Changes the rotations direction for(int x = 0; x < rotate; x++) { digitalWrite(stepPin,HIGH); delayMicroseconds(500); digitalWrite(stepPin,LOW); delayMicroseconds(500); } } } lastAngle = currentAngle; if (state == "Auto"){ mode = state; } } }

Code language: Arduino (arduino)

HC-05 Bluetooth Module with Arduino-MIT App Inventor
HC-05 Bluetooth Module with Arduino-MIT App Inventor

Step 6: Send Data to Arduino

Assuming that the connection is successful the light on the HC-06 bluetooth module will become solid. That is good, your device can now talk to the arduino. So to send something to the arduino, just select the type of data you want to send. Is it numbers, letters, bits, bytes, etc. Then select the .SendXXXX operation from the bluetooth menu in AppInventor and stick your data in. In this case for the LittleArm we use .SendText because we have text characters, in this case commas, in the data. If it was numerical we would use SendNumbers and so on.

You may notice that the function that the send command is inside of, is linked to one of the slider bars in the app. This means that the the Send is linked to an “event.” i.e. when the slider is moved it automatically calls this function. Not to bad, right?

Step 7: Recieve Data From Arduino

Now, you are not always sending data to the Arduino. Sometimes you want to get something back. In fact, if you want to have reliable connections, you should require something back. A parity character, if you will. Something that signals that all of the data was received and the arduino is ready to get more. In this case we use the letter ‘d.’ D is for Done. Now you could change your arduino code to send the value of a sensor or anything else. But it is good practice and much more reliable to send every data set with an signal character to show that all the data was sent and received.

To read this data being sent (‘d’) just again go through the bluetooth options until you find the type of data that you want to wait for. The character ‘d’ in this case is simply text in the form of a single byte, so we allow the scanning of only one Byte. If it is a “d” then we know that the arduino read the signal we sent and that we can send another.

How To Build Custom Android App for your Arduino Project using MIT App Inventor
How To Build Custom Android App for your Arduino Project using MIT App Inventor

Introduction: Using MIT App Inventor to Control Arduino – the Basics

We all have a smartphone. Now, with that statement of the obvious, let me ask you this. Why is your Arduino hardly ever connected to your smartphone. Bluetooth costs about $8 to implement on an arduino. The main issue is that some people get hung-up on the issue of programming bluetooth, so they just keep the usb cord. So here is the absolutely most basic things you need to use bluetooth with android and arduino.

This tutorial will go through the bare minimum you need to create an connection between a custom android app you make with MIT App Inventor and the Arduino.

All code and references provided are based on the code from the LittleArm Arduino robot arm.

Step 5: App Inventor: Create a ListPicker

Create a listpicker so that you can use to find and select the bluetooth devices that are paired with the smartphone.

When the listpicker is open, then a selection should trigger some event. In this case, a Bluetooth connection to the device listed. (Ignore the last three green blocks those are specific “trees” in the forest that you don’t have to have.)

Bluetooth LED Control App with MIT App Inventor - STEP By STEP
Bluetooth LED Control App with MIT App Inventor – STEP By STEP

Step 4: Connect Arduino to Android Device

at first you need a terminal emulator on your andriod device to send or receive data to arduino .

You can download this app from Google play .

https://play.google.com/store/apps/details?id=arduino.bluetooth.terminal&feature=search_result#?t=W251bGwsMSwxLDEsImFyZHVpbm8uYmx1ZXRvb3RoLnRlcm1pbmFsIl0.

after that , you can use the same arduino Sketch and control LED Blinking on or Off from android device .

just type and t send #1 to make LED Blink on , or 0 to blink off .

this video below show how to control arduino I/O from android tablet .

Step 1: The Bluetooth Module

The most common bluetooth module today is the HC-06 or HC-05. It costs about 7-10 dollars online. Look at the image below to see how to hook it to the Arduino.

That is pretty easy right? Just four jumper wires and you now have wireless serial connectivity to your arduino. Now, if you have a program where you have been sending commands to the arduino with the Serial Monitor you can now do that wirelessly with a bluetooth device. (Note: You can upload programs to the arduino via bluetooth, but that is significantly more complicated than what we want to achieve here.)

Arduino Servo Motor Control via Bluetooth | App Inventor
Arduino Servo Motor Control via Bluetooth | App Inventor

Introduction: Arduino AND Bluetooth HC-05 Connecting Easily

Hello Every body , This is my first artical on Instructable.com , I’m so happy for that , and I will start by How to connect arduino with bluetooth , I suffered a lot of problems when I try to connect it as the website and instructable artical did , So i decided To share my experience with YouThe bluetooth module I will use today is HC-05 which is so familiar and cheap ,Most tutorial on The website Connect the bluetooth with default Rx and Tx on the arduino Board , I faced a lot of problem and bluetooth didn’t work will .But arduino support something Called Software Serial , which allow You to change any arduino board pin to serial pinhttp://arduino.cc/en/Reference/SoftwareSerialso After reading this article you will be able to:1) Connect arduino Board with PC By Bluetooth , to send and receive data .2)Connect arduino Board with Any android device .so you can send your information , Like Sensors reading , from arduino to PC Or android device , and you can build your Home automation system by bluetooth , and controlling your robot wirelessly

Step 5: Receiving Data From Arduino

The last arduino Sketch that i wrote , used to send commands from PC Or android device to android , Now in this program i will use arduino to Calculate the time since the start of the program in second , and send it Via bluetooth to any pairing device .the code below// This program shown how to control arduino from PC Via Bluetooth// Connect …// arduino>>bluetooth// D11 >>> Rx// D10 >>> Tx//Written By Mohannad Rawashdeh//for http://www.genotronex.com/// you will need arduino 1.0.1 or higher to run this sketch#include

// import the serial librarySoftwareSerial Genotronex(10, 11); // RX, TXint ledpin=13; // led on D13 will show blink on / offlong previousMillis = 0; // will store last time LED was updated// the follow variables is a long because the time, measured in miliseconds,// will quickly become a bigger number than can be stored in an int.long interval = 1000; // interval at which to blink (milliseconds)int ledState = LOW; // ledState used to set the LEDlong Counter=0; // counter will increase every 1 secondvoid setup() {// put your setup code here, to run once:Genotronex.begin(9600);Genotronex.println(“Bluetooth On please wait….”);pinMode(ledpin,OUTPUT);}void loop() {// put your main code here, to run repeatedly:unsigned long currentMillis = millis();if(currentMillis – previousMillis > interval) {// save the last time you blinked the LEDpreviousMillis = currentMillis;Counter+=1;Genotronex.println(Counter);// if the LED is off turn it on and vice-versa:if (ledState == LOW)ledState = HIGH;elseledState = LOW;// set the LED with the ledState of the variable:digitalWrite(ledpin, ledState);}}at the end , You can visit the orginal artical in arabic language on my websitehttp://www.genotronex.com/Hope my first artical here is useful to you , thank you for your time ,

Bluetooth controlled Robot using Arduino Uno and MIT APP Inventor
Bluetooth controlled Robot using Arduino Uno and MIT APP Inventor

Step 2: Connect Arduino With PC

We now want to send or receive Data between arduino and computer , first we need to make a Communication link to Definition arduino Board to the computer .We will need a software called Tera Term to show the data received or what we want to send through it .You can download Tera Term or any terminal emulator software , you can download Tera term from this link :http://hp.vector.co.jp/authors/VA002416/ttermv14.zipTo make a link between your Arduino and bluetooth , do the following :1) Go to the bluetooth icon , right click and select Add a Device2) Search for new device , Our bluetooth module will appear as HC-05 , and add it3) The pairing code will be 1234 .4)after make a pairing , we can now program the arduino and upload a sketch to send or receive data from Computer.

Projects with MIT App Inventor

This was just a quick introduction to the MIT App Inventor. Now, its time to start building apps!

Here’s a list of our popular Arduino and MIT App Inventor projects:

  • Android App – RGB LED with Arduino and Bluetooth
  • Arduino – Control 2 DC Motors Via Bluetooth
  • Control your Arduino with Voice Commands
How to make a Android Application control Robot Camera | MIT App inventor based Android Application
How to make a Android Application control Robot Camera | MIT App inventor based Android Application

MIT App Inventor

From the MIT App Inventor website we need to log in into the online building application by clicking the “Create apps!” button. In order to log in we need to have a Gmail account. Once we are logged in now we can create our first project. Here’s how the design window looks and now we can start building our application.

But before do that, we can connect our smartphone to this project so that we can see how the app is taking shape directly on our smartphone in real time. In order to do that first we have to download the MIT AI2 Companion app from the Play Store and install it on our smartphone. Then from the Connect menu from the online editor we will select AI Companion and a barcode will appear which we just need to scan it or insert the code into the smartphone app and the connection between the online editor and the smartphone app will be established.

So now for example, if we insert a button in the screen of the online editor, the button will appear in real time on the smartphone as well. Similar to this, if you don’t want to use your smartphone while building the app, you can install the Android Emulator on your computer and use in the same way. You can find more details how to set up the Emulator on their website.

Why MIT App Inventor is a good choice?

  • MIT App Inventor 2 is intuitive and simple to use.
  • You don’t have to be an expert in programming or design to build awesome apps that can do useful stuff.
  • Creating the design is as easy as selecting and placing widgets in the smartphone screen.
  • The code is done with drag and drop puzzle blocks.

Anyone can learn how to build their own apps with MIT App Inventor 2 with a few hours of practice.

how to make Wireless Temperature and Humidity Monitoring System using Bluetooth | mit app inventor
how to make Wireless Temperature and Humidity Monitoring System using Bluetooth | mit app inventor

I provide 15 tutorial links about App Inventor communicating with Arduino Uno. The tutorials start with a Bluetooth connection and they are developed ending with a monitor for 2 potentiometers, leds, buttons and small supervisory using procedure blocks, canvas, etc

Tutorial 1/15: connecting with bluetooth

Tutorial 2/15: Led ON / OFF

Tutorial 3/15: Led ON / OFF – Changing Button Color

Tutorial 4/15: Led ON/OFF – Using a single button on App Inventor

Tutorial 5/15: Slider changes LED intensity

Tutorial 6/15: Joining Slider / Button in App Inventor and Leds Arduino

Tutorial 7/15: Checking Status of an Arduino Pushbutton (button) in App Inventor

Tutorial 8/15: Monitoring 02 Potentiometers

Tutorial 9/15: now monitoring the status of 02 Potentiometers and 01 Pushbutton

Tutorial 10/15: Complete Project – Bt, Pot, Button, Slider, Leds

Tutorial 11/15: 8Leds 8 Buttons – Mode1

Tutorial 12/15: 8Leds 8 Buttons – Mode1: Using Procedure Block

Tutorial 13/15: Small Supervisory using Canvas – Part 1

Tutorial 14/15 : small supervisory using Canvas – Part 2

Tutorial 15/15: two ways to install the HC-05 module on Arduino and communicate to AppInventor

In this Arduino Tutorial we will learn how to build custom Android applications for controlling Arduino using the MIT App Inventor online application. You can watch the following video or read the written tutorial below.

Arduino Code

Here’s a quick overview of that code. So, via the serial port we receive the incoming data from the smartphone and store it in the ‘state’ variable. If we receive the character ‘0’ which is sent from the smartphone when the ‘LED: OFF’ button is pressed, we will turn the LED off and send back to the smartphone the String “LED: OFF”. On the other hand, if we receive the character ‘1’ we will turn the LED on and send back the String “LED: ON”.


/* Arduino and HC-05 Bluetooth Module Tutorial * * by Dejan Nedelkovski, www.HowToMechatronics.com * */ int state = 0; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); Serial.begin(38400); // Default communication rate of the Bluetooth module } void loop() { if(Serial.available() > 0){ // Checks whether data is comming from the serial port state = Serial.read(); // Reads the data from the serial port } if (state == '0') { digitalWrite(ledPin, LOW); // Turn LED OFF Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON" state = 0; } else if (state == '1') { digitalWrite(ledPin, HIGH); Serial.println("LED: ON");; state = 0; } }

Code language: Arduino (arduino)

So now we need to build our custom Android application which will send those characters ‘0’ and ‘1’ when a particular button is pressed, as well as, receive the incoming Strings from the Arduino.

Step 8: Enjoy Your App

And that is all there is to it. You now have an app, that will connect with a bluetooth device and then send some kind of data to the Arduino and receive some kind of data via serial communications. Now you can control almost any arduino project with your android smartphone. Enjoy.

You can see a demo of the app that all of this code was taken from in this video.

Hi everyone.

I’m quite new to MIT App Inventor and BLE connection in general.

I have begun creating an app that is to be used to connect to my Arduino Nano 33 IOT and then receive data from said Arduino to be then graphed. The data will be a weight between 0 and 50kg. However I have little understanding as to how BLE works and am unsure how to use the Bluetooth on the Arduino. I have looked all over the internet (granted maybe not in the correct places) but I have spent a few days on this and am struggling still. Here is the app, blocks and my code so far. But I have little to no understanding as to where to find the service or characteristics UUID.

Any help is appreciated, even if it’s a link to something else, be a previously made similar project, another thread or web page.

I’m happy to answer any questions. Thanks!

#include

BLEService weightService(“?”); // BLE weight Service

// BLE weight Switch Characteristic – custom 128-bit UUID, read and writable by centralBLEByteCharacteristic switchCharacteristic(“?”, BLERead);

// Arduino With Load Celllong time = 0; // Set time to 0int interval = 100; // Take a reading every 100 ms

void setup() {Serial.begin(9600);

while (!Serial);

// begin initializationif (!BLE.begin()) {Serial.println(“starting BLE failed!”);


while (1);

// set advertised local name and service UUID:BLE.setLocalName(“Arduino”);BLE.setAdvertisedService(weightService);

// add the characteristic to the serviceweightService.addCharacteristic(switchCharacteristic);

// add serviceBLE.addService(weightService);

// set the initial value for the characeristic:switchCharacteristic.writeValue(0);

// start advertisingBLE.advertise();

Serial.println(“BLE Active”);

void loop() {float curReading = analogRead(0); // Take reading of analog pin 0 of Arduino

// using serial.print, we can send the data in a ‘text’ formatSerial.print(curReading);delay(100);}

In this post I’m going to introduce you to the MIT App Inventor 2 software and I’m going to show you what you need to quickly getting started building Android apps that interact and control your Arduino.

Here’s the contents that are going to be covered in this post:

  • Introducing MIT App Inventor 2
  • Why MIT App Inventor 2 is a good choice?
  • Accessing MIT App Inventor 2
  • How to control Arduino with MIT App Inventor (Bluetooth)
  • MIT App Inventor Overview
  • Projects with MIT App Inventor
  • Android Apps for Arduino with MIT App Inventor 2
How to make Arduino based Home Appliance Control Using Android Application | Home Automation Project
How to make Arduino based Home Appliance Control Using Android Application | Home Automation Project

Step 2: Arduino Code

Some people think that that when you replace the cord with bluetooth that you have to change your code. THEY ARE WRONG. Relax, if your code works with the USB cord than you do not have to change a thing. As I said, bluetooth is basically the same thing as USB in code syntax. The Arduino’s Serial.read is just fine with the same code.

Here is the code that is used with the LittleArm Arduino robot Arm.

//////Other Intiations here

void setup(){ Serial.begin(9600); baseServo.attach(5); // attaches the servo on pin 5 to the servo object shoulderServo.attach(4); elbowServo.attach(3); gripperServo.attach(2); Serial.setTimeout(50); //ensures the the arduino does not read serial for too long Serial.println(“started”); baseServo.write(90); //intial positions of servos shoulderServo.write(100); elbowServo.write(110); ready = 0; }//primary arduino loopvoid loop() { if (Serial.available()){ ready = 1; desiredAngle.base = Serial.parseInt(); desiredAngle.shoulder = Serial.parseInt(); desiredAngle.elbow = Serial.parseInt(); desiredGrip = Serial.parseInt(); desiredDelay = Serial.parseInt();

if(Serial.read() == ‘\n’){ // if the last byte is ‘d’ then stop reading and execute command ‘d’ stands for ‘done’ Serial.flush(); //clear all other commands piled in the buffer Serial.print(‘d’); //send completion of the command } }

This snippet of code is the read and return code. Notice that it reads information from the Serial port just as if there were a usb cable connected. There is no need to initiate ports for the Bluetooth, they are naturally activated.

MIT App Inventor Overview

Go to http://appinventor.mit.edu/explore/ and press Create Apps button.

Next, click on Start new project as shown in figure below.

You’ll be asked to give your project a name. As we’re just exploring the MIT App Inventor 2 features, you can name it test.

Click OK. Your project is automatically saved.

If you go to Projects > My Projects you can see all your saved projects.

Click on the project name to open the app builder.

Designer

You’ll be presented with the Designer tab as shown in the following figure.

At 1) you select whether you are on the Designer or in the Blocks Editor tab. With MIT App Inventor you have 2 main sections: Designer and Blocks. The designer gives you the ability to add buttons, add text, add screens and edit the overall app look.

The Blocks section allows you to create custom functionality for your app, so when you press the buttons it actually does something with that event.

2) The Palette contains the components to build the app design like buttons, sliders, images, labels, etc…

3) It’s the Viewer. This is where you drag the components to build the app look.

4) Components. You can see all the components added to your app and how they are organized hierarchically.

5) Properties. This is where you select your components’ properties like color, size and orientation.

Blocks Editor

Open the Blocks editor tab.

In the Blocks editor tab, you have several sections:

1) contains the built-in blocks for creating the app’s logic. This is what makes the app define the buttons functionalities, send commands to Arduino, connect to the Bluetooth module, etc. You have several blocks grouped by categories:

  • Control: if/else statements, while loops, etc…
  • Logic: True, False, equal, not equal, etc…
  • Math: math operators.
  • Text: blocks that deal with text.
  • Lists: blocks for handling lists.
  • Colors: blocks to handle colors, like choosing a color, make color and split colors.
  • Variables: initialize variables, setting variables values, get variables values, etc…
  • Procedures: procedures are like functions. A procedure is a sequence of code blocks with a given name. Later, you can call that sequence of blocks instead of creating the same long sequence.

Inside each group, you have blocks that you can drag to the Viewer 2). In the Viewer, you drag the blocks and join them in a specific way to make something happen.

We recommend that you navigate inside the blocks section and explore what’s inside. The blocks look like puzzle pieces that fit into each other or not. If you can’t do something with certain blocks, they won’t fit.

In the backpack 3) you save code blocks to use later. You move blocks to the dustbin 4) to delete them.

Arduino Robot Car Control using HC-05 Bluetooth | mit app inventor for android apk
Arduino Robot Car Control using HC-05 Bluetooth | mit app inventor for android apk

How to Control Arduino with MIT APP Inventor (Bluetooth)

To establish a connection between the Arduino and your Android app, you need a Bluetooth communication protocol. For that, you need a Bluetooth module.

The most common Bluetooth modules used with the Arduino are the HC‑05 bluetooth, HC-04 and HC-06.

For more information about the bluetooth module, you can check this blog post: Reviews – HC-05 Bluetooth Module

The Bluetooth module works with serial data. This means that the Arduino sends information and the Bluetooth module receives it via serial (and vice-versa).

The following figure explains how the information flows from the Android app to the Arduino.

Your smartphone sends information to the Bluetooth module via Bluetooth. Then, the Bluetooth module sends the information via serial communication to the Arduino. This flow also works the other way around: the Arduino sends information to the Bluetooth module that sends it to the smartphone via Bluetooth.

Introducing MIT App Inventor 2

MIT App Inventor 2 is a simple and intuitive free service for creating Android applications. If you want to start with MIT App Inventor, you don’t need to download or install any program in your computer as the software is cloud-based, so you build the apps directly in your browser (Chrome, Mozilla, Safari, Internet Explorer, etc).

For instance, you only need an internet connection for building the apps.

How to Make a Simple App--[NodeMCU-ESP8266] -PART1
How to Make a Simple App–[NodeMCU-ESP8266] -PART1

Step 3: Arduino Code

this program below allow us to control LED connected to D13 To blink on/off , by press # 1 from PC Keyboard the LED blink on , and if we press 0 LED blink off !

To send the Control commands from Computer to arduino , Go to the tera term , Run it , and choose Serial , and select the bluetooth Serial from the list as Shown on the picture .

The code below :

// This program shown how to control arduino from PC Via Bluetooth

// Connect …

// arduino>>bluetooth

// D11 >>> Rx

// D10 >>> Tx

//Written By Mohannad Rawashdeh

//for http://www.genotronex.com/

// you will need arduino 1.0.1 or higher to run this sketch

#include

// import the serial library

SoftwareSerial Genotronex(10, 11); // RX, TX

int ledpin=13; // led on D13 will show blink on / off

int BluetoothData; // the data given from Computer

void setup() {

// put your setup code here, to run once:

Genotronex.begin(9600);

Genotronex.println(“Bluetooth On please press 1 or 0 blink LED ..”);

pinMode(ledpin,OUTPUT);

void loop() {

// put your main code here, to run repeatedly:

if (Genotronex.available()){

BluetoothData=Genotronex.read();

if(BluetoothData==’1′){ // if number 1 pressed ….

digitalWrite(ledpin,1);

Genotronex.println(“LED On D13 ON ! “);

if (BluetoothData==’0′){// if number 0 pressed ….

digitalWrite(ledpin,0);

Genotronex.println(“LED On D13 Off ! “);

delay(100);// prepare for next data …

After uploading This sketch go to tera term and press 0 or 1 and see the results

This Video show the results of this code .

Blocks Editor

Now in the Blocks editor we are ready to give life to our program. From the left side we got all the blocks and function related to the previously added components.

We will start with the BluetoothList ListPicker. From there first we will add the ‘BeforePicking’ block and attach to it the ‘set Bluetooth Elements’ block. Then from the BluetoothClient blocks we will add the ‘BluetoothClient AddressesAndNames’ block. What this set of blocks will do is set a list of Bluetooth devices which are already paired with our phone so when we will click on the ListPicker “Connect Button” the list of all paired devices will show up.

Next we have to set what will happen after we will pick or select our particular Bluetooth module. From the BluetoothClient block we will add the ‘call BluetoothClient .Connect address’ block and add the block ‘BluetoothList Selection’ to it, which means that our phone will connect to the Bluetooth address that we have previously selected.

Next from the Clock blocks we will add the “.Timer” block. Within this block we will make the real time indication whether the phone is connected or not to the Bluetooth module using the “set Text” block of the label named “Connected”.

Next we need to give life to the two buttons. So when the “TurnOn_Button” will be clicked we will use the Bluetooth client function “Send1ByteNumber” to send a number to the Arduino Bluetooth module. In our case that’s the number 49 which corresponds to the character ‘1’ according to the ASCII table and that will turn on the LED. Right after that we will use the “ReceiveText” BluetoothClient function to receive the incoming String which is send back from the Arduino to the phone. This String is set to the “LED_Status” Label.

The same procedure goes for the “TurnOff_Button” where the sending number should be changed to 48 which corresponds to character ‘0’. What’s left now is to download and install the program on our smartphone. We can do that from the “Build” menu by either saving it to our computer and then transfer to our phone or scan a QR code for online download of the program. Here’s the demonstration of the example.

Here’s a download file of the above MIT App Inventor project:

App inventor 2 manejando el modulo Bluetooth con Arduino
App inventor 2 manejando el modulo Bluetooth con Arduino

Overview

For this tutorial we have two examples. The first example is controlling a simple LED and the second one is controlling a Stepper Motor using smartphone. In my previous tutorial we already learned how to make the Bluetooth communication between the Arduino Board and the Smartphone using the HC-05 Bluetooth module and explained the Arduino code needed for the first example.

Step 3: App Inventor

The basics of app inventor are easy. If you know how to code you can struggle through the basic set-up and operation. So just fiddle around until you have a button or slider bar that you want to use then you can add in this bluetooth code. In the context of the tutorial the app is that of the LittleArm Arduino Robot Arm, which has multiple sliders. But we will focus on just one.

Multi Servo Motor Control via Bluetooth Using Android App | Arduino and App Inventor
Multi Servo Motor Control via Bluetooth Using Android App | Arduino and App Inventor

Accessing MIT App Inventor 2

To access MIT App Inventor 2 go to http://appinventor.mit.edu/explore/ and press the orange Create Apps button.

To access the app builder, you need a Google account. Follow the on-screen steps to login into MIT App Inventor 2. After that, you’ll be presented with the following dashboard (we’ll cover how to use the dashboard in the MIT App Inventor 2 Overview section):

Android Apps for Arduino with MIT App Inventor 2

If you like Android Apps and Arduino take a look at our course: Android Apps for Arduino with MIT App Inventor

This is a step-by-step course to get you building cool Android applications for Arduino, even with no prior experience! A collection of 8 + 1 Projects.

Download Android Apps for Arduino with MIT App Inventor 2

I hope you’ve found this post useful.

Thanks for reading,

Sara

I am trying to use the app inventor with an iPhone and and Arduino. I used code I learned in a workshop for Android phones and it doesn’t work with the iPhone.

A recent post gave this as an answer to the same question, but I don’t understand how to use the answer: “Use ElementsFromString property in the designer rather than the ListData property.”

Are there any tutorials you can suggest to help me use it with the iPhone and Arduino?

Welcome Elene.

The Android users use Bluetooth to communicate with an Arduino . I don’t think an ios version of App Inventor can do that yet. Android users use extensions to accomplish that goal. The ios version of App Inventor currently cannot use extensions.

Some users use the Web component to talk to their arduinos. See Search results for ‘arduino Web ‘ – MIT App Inventor Community.

Is this using App Inventor Blocks?

Ultimately it will depend on the Arduino you are using. At the moment, App Inventor for iOS does not have the BluetoothClient, BluetoothLE (currently an extension), or Serial components implemented, which are common ways to connect to Arduinos. If you have an Arduino Yun (or another Wifi shield), you should be able to use the Web component to communicate with it.

Of the three unavailable connection methods, BluetoothLE is the mostly likely to be implemented in the short term as we are producing new curricula around BluetoothLE and the micro:bit, and we want to ensure that this will be a good experience for both Android and iOS users.

1 Like

Yes. They used the app inventor with the HM-10 Bluetooth module, the Arduino Uno, and an android phone.

Does this mean that the App inventor will work with the HM-10 Bluetooth module, Arduino uno and iPhones in the future?

I would need to see an example project to better assess that.

How to make IOT based Home Appliance Control using Firebase Server | MIT App Inventor Part:1
How to make IOT based Home Appliance Control using Firebase Server | MIT App Inventor Part:1

Keywords searched by users: app inventor with arduino

Smartphone Controlled Lamp | Arduino + Mit App Inventor - Hackster.Io
Smartphone Controlled Lamp | Arduino + Mit App Inventor – Hackster.Io
How To Build Custom Android App For Your Arduino Project Using Mit App  Inventor - How To Mechatronics
How To Build Custom Android App For Your Arduino Project Using Mit App Inventor – How To Mechatronics
Receiveing Values From Arduino To App - Mit App Inventor Help - Mit App  Inventor Community
Receiveing Values From Arduino To App – Mit App Inventor Help – Mit App Inventor Community
Connect To Arduino - Mit App Inventor Help - Mit App Inventor Community
Connect To Arduino – Mit App Inventor Help – Mit App Inventor Community
App Inventor 2 : Android Receive Data From Arduino Via Bluetooth - Youtube
App Inventor 2 : Android Receive Data From Arduino Via Bluetooth – Youtube
Arduino And App Bluetooth - Mit App Inventor Help - Mit App Inventor  Community
Arduino And App Bluetooth – Mit App Inventor Help – Mit App Inventor Community
Alerting About Fire From Arduino To Phone App - Mit App Inventor Help - Mit  App Inventor Community
Alerting About Fire From Arduino To Phone App – Mit App Inventor Help – Mit App Inventor Community
Sending Data To And From Mit App To Arduino Via Bluetooth (Hc05) - Mit App  Inventor Help - Mit App Inventor Community
Sending Data To And From Mit App To Arduino Via Bluetooth (Hc05) – Mit App Inventor Help – Mit App Inventor Community
How To Use App Inventor With Arduino - Youtube
How To Use App Inventor With Arduino – Youtube
Accept Characters From Arduino In The App - Mit App Inventor Help - Mit App  Inventor Community
Accept Characters From Arduino In The App – Mit App Inventor Help – Mit App Inventor Community
Getting Started Mit App Inventor 2 | Random Nerd Tutorials
Getting Started Mit App Inventor 2 | Random Nerd Tutorials
Bluetooth Hc-06. Arduino. Send. Receive. Send Text File. Multitouch. Image  - Tutorials And Guides - Mit App Inventor Community
Bluetooth Hc-06. Arduino. Send. Receive. Send Text File. Multitouch. Image – Tutorials And Guides – Mit App Inventor Community
Help Arduino Phone Connection - Mit App Inventor Help - Mit App Inventor  Community
Help Arduino Phone Connection – Mit App Inventor Help – Mit App Inventor Community
App Inventor - Arduino - Internet Of Things - Mit App Inventor Community
App Inventor – Arduino – Internet Of Things – Mit App Inventor Community
App Inventor - Arduino - Internet Of Things - Mit App Inventor Community
App Inventor – Arduino – Internet Of Things – Mit App Inventor Community
Mit App Inventor Arduino Android App To Control Led With Hc05 Bluetooth  Module Part 1 : 3 Steps - Instructables
Mit App Inventor Arduino Android App To Control Led With Hc05 Bluetooth Module Part 1 : 3 Steps – Instructables
Sending Text From Arduino To App Inventor Via Bluetooth In Order To Play A  Corresponding Voice Message Via Player - Mit App Inventor Help - Mit App  Inventor Community
Sending Text From Arduino To App Inventor Via Bluetooth In Order To Play A Corresponding Voice Message Via Player – Mit App Inventor Help – Mit App Inventor Community

See more here: kientrucannam.vn

Leave a Reply

Your email address will not be published. Required fields are marked *