MIT app inventor with Arduino

by Jul 1, 2020Arduino Uno

MIT app inventor is a platform developed to help you expand your ideas into mobile applications that can be used throughout various devices. Arduino, as you most probably have heard of is mainly used to develop and implement many projects. When you put together the ease of the MIT app inventor and the adaptability and popularity of Arduino – the possibilities are endless! So, whether you already have an idea, or are yet to find inspiration go ahead and read further. In this article we’ll discuss what the MIT app inventor is, and what it can do. We’ll also build our first project integrating the app inventor with the Arduino board and an LED.

 What is MIT app inventor?

MIT App Inventor is a visual programming environment to build applications, in as less as 15-20 minutes. They have block-based tools that enable even children to create complex, high-impact app when they don’t have the traditional coding skills the application may require. You can develop applications for Android phones using a web browser with a phone or emulator. The App Inventor servers store your work and help you keep track of your projects.

Via https://appinventor.mit.edu/explore/content/what-app-inventor

The apps can be built using:

App Inventor Designer, to select its components.

App Inventor Blocks Editor, to assemble blocks of the program that determine how the components will behave. This is done by visually fitting pieces together.

Building your first project:

Akin to ‘Hello, world’ of computer programming, enabling blinking of an LED light qualifies as the first stepping stone to learning how to code new hardware. So, our first project is going to be just that!

First we have to setup the Arduino with the App Inventor app

Step 1:  Download and Install the IDE

If you haven’t already, install the Arduino Integrated Development Environment (IDE). If you already have it up and running, great! Open the AIM-for-Things-Arduino101.ino file, which is the Arduino file for App Inventor. If you don’t have that, download it here.

This is the file that should open up

Step 2: Install Libraries

Next we’re going to install some libraries to run Arduino with App Inventor. You might not require all of these for simpler projects, but will come in handy later. To do this, click on the Sketch dropdown menu, hover over Include Library, and select Manage Libraries.

In the window that opens, search for ‘DHT-sensor-library’ and click Install. Then, repeat the process for “Adafruit Unified Sensor”. To get the Grove LCD RGB Backlight working, you first need to download the library file. After downloading, click on Sketch, then Include Library.  Unlike last time, now click on Add .ZIP Library. Find the file and upload it.

Step 3: Select Board

If you hadn’t until now, plug your Arduino into your computer

Next, you can select the correct Arduino board:

Click on the Tools menu and go to the Board sub-menu to select your board. (if you cannot find it, go to Boards Manager and search for your board version.

Step 4: Select port

Select the port that the Arduino IDE will interact with the Arduino.

Under the Tools menu, select the “Port” sub-menu and selct the option that starts with

○ /dev/cu.usbmodem… (for MAC) or ○ COM… (For others)

Now to run AIM-for-Things-Arduino101, the Arduino program we first opened, we need to send it to the board. But before doing this, change the DISABLED against LED to ENABLED. Then, click on the arrow button in the top left corner of the program window.

Once you have sent pressed the arrow, and sent the code to the Arduino board, your App Inventor app can interact with the Arduino.

Now let’s start to use this for our first project!

Step 5: Basic screen layout

Open the app inventor window, and click on Start a new project and specify a name. The left side column, called Palette contains several options that we can use to build our project. The buttons we require for this project are Bluetooth(to select and connect to the device), on and off. Now, to create these buttons.

  1. The Bluetooth select button, will allow us to pick the device from the list of devices connected to our phone. So we choose the ListPicker option, and drag and drop it onto the screen. And on the properties tab, on the right – change the width – fill parent. You can also change the text on the button to Bluetooth, or whatever name you want to give the button. You can also drag and drop Label from the Palette to below the Bluetooth button. This will indicate whether the device is connected or not. For the label, change the width – fill parent and delete the text to leave the label empty.
  2. Before the next two buttons, open the Layout on the Palette and choose the Horizontal Layout, with width à fill parent. Now you can go back to the User Interface and drag and drop two buttons onto the horizontal layout with the text set to – ‘On’ and ‘Off’ respectively and set their widths to fill parent as well.

With these buttons you can feel free to play with the other buttons to customise and colour them or add images within the buttons as well.

Step 6: Connect to the Bluetooth

Scroll down in the Palette to find the Connectivity tab, open that and drag and drop BluetoothClient onto the screen

Step 7: Add the clock trigger

On the palette find the Sensors tab, open it and drag and drop a clock onto the screen as well.

Step 8: Programming the app using Blocks

To do this, click on Blocks on the right upper corner of the window. Using this interface, we will join the functions like puzzle pieces to get the desired output. Which in our case is, the LED control when the Arduino is connected to the app. First, we have to program the app for before picking the device. To do this click on the ListPicker1, under Screen1 on the left-hand side Blocks tab.

This will display various blocks. Drag and drop the ‘when ListPicker1 BeforePicking do’ to the screen. Again click on the ListPicker1 option and select ‘set ListPicker1 Elements to’ and place it within the first block. Then pick the ‘BluetoothClient1 AddressesandNames’ from the BluetoothClient option.

What this will do is, before you pick the device, the List Picker will display its elements as the connected Bluetooth devices.

Step 9: After picking the device

Next we will form the flow of action After Picking. For this again open the ListPicker1 tab and drag and drop the ‘when ListPicker1 AfterPicking do’ to the screen. Then, click control and choose the ‘if then’ box and place within the first one. Click on the BluetoothClient option and select ‘call BlueToothClient1 Connect address’ block to place against the ‘if’ of the previous block. Under ListPicker1 option and select ‘ListPicker1 Elements’ click on ‘Elements’ and replace it with selection from the drop down menu.

Right click within the Before picking to select duplicate and place the same blocks within the ‘then’ block.

Step 10: Add clock

From Clock1 in the Blocks pane, add when Clock1.Timer do to the viewer. Like before, click control and choose the ‘if then’ box and place within the first one. Then pick the ‘BluetoothClient1 AddressesandNames’, change AddressesandNamesto IsConnected and place it near if. Now, if connected we want the label to display connected. For this, click Label and drag and drop ‘set Label1 text To’ near then. From the Text option, pick the empty text option, drop it near the set Label1 text To and type Connected in the space provided.

To display ‘Not connected’ when Bluetooth device is not connected, click the small blue box near ‘if’ on the ‘if then’ box and drag and drop ‘else’

For the else, duplicate the then blocks and change ‘Connected’ to ‘Not Connected’.

Step 11: Buttons

From Button1 on the Palette, drag and drop the ‘when Button1 Click do’ block, and from Button2, drag and drop the ‘when Button2 Click do’ block. When Button1 is clicked, we want the app to send an ‘on’ and ‘off’ when Button2 is clicked. Click the BluetoothClient, and scroll down to find ‘call BluetoothClient  SendText text’, then from the text options, select the empty one, drag and drop and rename as on. Repeat the same for Button2 and rename the text as off.

And that concluds the program!

Step 12: Save App

From Build option on top, select the App (save. Apk to my computer)

Once you’ve saved it to your computer, download and install the app on your android phone.

Step 13: Hardware connection

This is the Bluetooth connected Arduino. Make sure to note the connection of TXD pin to the 10th, and RXD to the 11th. Even though by norm it is connected to the 1st and 2nd pins on the board, here we also want the computer monitor to be connected to see the on and off texts from the BluetoothClient. The LED is connected to the 13th pin.

We will now look at the code we need for this, in which we will use software serial to interface with Bluetooth.

Initial setup, with two different communications, one is with monitor and the other with Bluetooth.

#include <softwareserial.h>
SoftwareSerial BT(10, 11); //TX, RX respectively
String state;// string to store incoming message from bluetooth
void setup() {
 BT.begin(9600);// bluetooth serial communication will happen on pin 10 and 11
 Serial.begin(9600); // serial communication to check the data on serial monitor
  pinMode(13, OUTPUT); // LED connected to 13th pin
}

The main program, tells the Arduino to check any incoming message. If there is a message it builds the string from the incoming and checks whether its On or Off. The building is needed since it is serial communication – the message comes letter by letter. If on the 13th pin will be HIGH and LED will turn on.

void loop() {
  while (BT.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable 
  char c = BT.read(); //Conduct a serial read
  state += c; //build the string- either "on" or "off"
  }  
  if (state.length() > 0) {
    Serial.println(state); 

  if(state == "on") 
  {
    digitalWrite(13, HIGH);
     } 
  
  else if(state == "off") 
  {
    digitalWrite(13, LOW);
     }
  
state ="";}} //Reset the variable
</softwareserial.h>

Step 14: Run the program

Now you are all set to run the program, connect everything and from the MIT inventor go to Connect à AI companion.

From the app on your phone you should be able to control the LED on and off!

Creating a multiplication Skill in Alexa using python

Written By Jyotsna Rajaraman

Hi! I'm Jyotsna, an electronics and communication undergrad who likes reading, writing, talking and learning. So when it comes to teaching, all my favorite things come together! I hope my articles have helped and taught you something. 🙂

RELATED POSTS

How to use simulators to build Arduino Projects

How to use simulators to build Arduino Projects

Introduction In this tutorial, let's learn how to use simulators for building Arduino projects for beginners. In addition to it, We shall learn how to configure it and how to get started with simulation tools. Here, We shall take an example of blinking an led using...

Arduino and its various development boards

Arduino and its various development boards

1. What is Arduino? Arduino is an open-source software and software company, project, and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices....

Arduino Compatible Temperature Sensors

Arduino Compatible Temperature Sensors

In this article, we will look at Arduino's popular temperature sensors which are the foundation for Arduino's entry level projects. Temperature Sensor Temperature sensors are designed to measure the temperature of an object or substance using the properties and...

ARDUINO MKR 1000

In this article, we are going to learn about Arduino MKR 1000. .Arduino MKR1000 is a powerful board that combines the functionality of the Zero and the Wi-Fi Shield. It is the ideal solution for makers wanting to design IoT projects with minimal previous...

How to use Blynk with Arduino ?

How to use Blynk with Arduino ?

What if you want to exclude the typical involvement of a laptop in the Arduino and make it more dynamic! In this tutorial, you will learn how to get started to Blynk with Arduino and it's various features. So, let's begin with the introduction. Contents: What is...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....