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.)
Experiments
4.Experimental Setup
Our goal is to measure the degree to which computational thinking skills can be developed once we have mastered each programming language. In order to achieve our goal, we attempted to crawl mature (and diverse) Scratch and App Inventor projects rather than crawling all public projects, which include many duplicated or temporary projects [
2829
].
We crawled 524 high-quality Scratch projects on the Scratch website. More specifically, we crawled (1) 24 “starter projects” as shown on the Ideas menu, which consists of tutorial projects categorized as animations, games, interactive art, music and dance, stories and video sensing; and (2) 500 “popular” and “trending” projects on the Explore menu, which consist of the animations, art, games, music and story projects.
We also crawled 379 mature projects on the App Inventor website, consisting of (1) official tutorials, (2) all of the popular projects “liked” by greater than or equal to ten users, and (3) all of the App of the Month (AOM) projects from January of 2015 to August of 2019. Note that only 209 projects received greater than or equal to ten “likes,” and that 67 AOM projects are developed by adults while the other 89 AOM projects are invented by primary or secondary school students. We excluded projects that could only be downloaded from the Google Play Store because we cannot access to their source codes. We also excluded projects with broken hyperlinks.
shows the statistics of our selected projects. The average number of lines of code for each category is also presented in the table. Because all of the selected projects provide their source codes, in
Section 4.2
and
Section 4.3
these codes are parsed using Python and automatically scored according to the proposed rubric.
4.Experimental Results on Computational Thinking Concepts: ScratchApp Inventor
shows the overall comparison results for Scratch and App Inventor for computational thinking concepts. In each cell of the second and third columns, the numbers outside of the parentheses are the averages of the effectiveness scores calculated by the proposed rubric, while the values inside the parentheses are the standard deviations of the scores. We also specify their two-tailed
p
-values in the fourth column in order to determine whether the differences in the two effectiveness scores are statistically significant. Note that the maximum available value of each effectiveness score was three.
First, the experimental results show that there are no statistically significant differences between the scores of Scratch and App Inventor in the areas of Abstraction and Problem Decomposition and Logical Thinking. Unfortunately, the scores for these computational thinking concepts are relatively low compared to those of the other concepts. This result is similar to previous findings [
28
] which showed many Scratch projects do not use My Blocks or conditionals.
With three of the computational thinking concepts (Parallelism, Synchronization and Flow Control), Scratch projects outperform App Inventor projects, especially with regard to Parallelism, where the average score for Scratch is much higher than that for App Inventor. This result is in good agreement with work by Wangenheim et al. [
26
], who noted that it is difficult to implement parallelism in App Inventor. On the other hand, this result also shows that Scratch is highly appropriate for learning parallelism. Scratch also outperforms App Inventor in terms of Synchronization. This result is somewhat surprising because App Inventor has 40 different types of callback functions. Scratch also scored higher in the area of Flow Control. In practice, while Repeat blocks are frequently used to control sprites in Scratch, it is often unnecessary to use loops when changing the state of a component in App Inventor.
App Inventor projects scored higher in the areas of User Interactivity and Data Representation. The high User Interactivity score may stem from the fact that we often need to use the event blocks of a component when we need to exploit the functionalities of the component. Additionally, the high score for Data Representation may be due to the fact that there are many command blocks that require a list as input.
In summary, the effectiveness scores for Scratch and App Inventor projects showed significant differences. More specifically, Scratch projects outperformed App Inventor projects in the areas of Parallelism, Synchronization and Flow Control. On the other hand, App Inventor projects outperformed Scratch in the areas of User Interactivity and Data Representation.
4.Detailed Analysis of the Results
For a more detailed analysis, we initially investigated how the scores of computational thinking concepts vary depending on the type of projects.
Figure 3
shows the results of this analysis: (1) For Scratch, game projects received the highest overall score, and starter projects had the lowest overall score. These results indicate that the effectiveness scores of programs differed depending on their genre. (2) For App Inventor, App of the Month projects invented by adults received the highest overall score, while popular projects with greater than or equal to 10 “likes” received the lowest overall score. Although the projects developed by adults scored higher than those developed by young students, their differences were not significant. Additionally, the scores of the young students’ works are much higher than those of the official tutorials. It is important to note many App Inventor tutorials are actually college students’ projects, created as these students took App Inventor classes [
3
]. This indicates that teaching App Inventor from an early age will effectively allow students to learn computational thinking concepts.
It is interesting to note that projects with high overall scores show significant score improvements in the “weak areas” of each programming language. For example, while the Data Representation score for the Scratch starter projects is 1.08, that for the popular game projects is 2.34. Similarly, while the Parallelism score of the App Inventor tutorials is 0.50, that for the App of the Month (adult) projects is 1.67. These results indicate that even if we learn only one programming language, we can develop comprehensive computational thinking skills if we can make good use of that language.
shows how the average score of each computational thinking concept changes with an increase in the number of lines. Given that the average number of lines for App Inventor projects is less than 200, we plotted the projects with more than 200 lines as “200+.” These results show that the average scores tend to increase as the number of lines of code increases. This indicates that if we teach students to create large programs, their comprehensive computational thinking skills can be improved. However, there were exceptions where the average score did not increase significantly even if the number of lines of code was increased. For example, the Flow Control score for App Inventor was relatively low, even for large programs. As another example, the User Interactivity score for Scratch did not increase significantly as the number of lines of code was increased. This indicates that each language has its own area of excellence with regard to the learning of computational thinking skills.
In summary, even if students learn only one programming language, they can develop comprehensive computational thinking skills by making good use of that language. However, each programming language is superior to the other in certain computational thinking areas. Thus, it could be more helpful for students to learn both Scratch and App Inventor to gain a broader sense of computational thinking concepts.
4.Threats of Validity
Although we believe that our findings can be helpful for many computer science educators and K-12 teachers, this paper has the following limitations.
-
We experimented with high-quality Scratch and App Inventor projects; therefore, different results may arise for moderate or low quality projects. In other words, this paper assumes that students are sufficiently skilled in the use of each programming language.
-
We could not find a large number of high-quality projects on the App Inventor and Scratch websites because (1) App Inventor projects are not actively uploaded or shared in the projects gallery, and (2) on the Scratch website, there are many empty or duplicate Scratch projects [
23
], making it difficult to crawl high-quality projects. Although we could show statistically significant differences between Scratch and App Inventor regarding the five computational thinking concepts using a total of 903 projects, it would be possible to produce more meaningful results if more projects could be collected.
-
When creating the unified rubric, only the common characteristics of Scratch and App Inventor were taken into account. In other words, the rubric does not take into account the unique characteristics of Scratch and App Inventor. For example, file access blocks are excluded from the proposed rubric because these are not supported in Scratch. Further research is needed to analyze how these unique blocks can help improve students’ computational thinking skills.
Related Work
Papadakis et al. [
2223
] found that Scratch and App Inventor have individual advantages: (1) while we can create web-based programs using Scratch, we can create mobile applications using App Inventor. (2) App Inventor also differs from Scratch in that it can exploit various types of sensors (such as accelerometer sensors and location sensors) without connecting external devices; it can also provide more command/event blocks than Scratch (such as file access blocks or callback functions [
24
]). (3) In Scratch, we can easily draw images and record sounds, and there are numerous features for young students. For example, we can easily implement parallel execution codes, and while the program code is running, we can visually observe the parts of the code that are executed. (4) On both the Scratch and App Inventor websites, there is a “gallery” where we can share (or “remix”) our projects with other users. However, the Scratch gallery is much more active than the App Inventor gallery. For example, there are some Scratch projects that have received more than ten thousand “hearts.”
Turback et al. [
24
] noted that depending on which programming language we use, different types of codes can be implemented to create programs that even have the same functionalities. These different types of codes make it challenging to compare Scratch and App Inventor.
Figure 1
shows our example codes for Scratch and App Inventor, which move a sprite every second. While we explicitly use the “wait 1 seconds” block in Scratch, we use the “Timer” event in order to do the same thing in App Inventor.
Moreno-León et al. [
18
] presented a rubric for Scratch, which they called “Dr. Scratch”. They redefined the “computational thinking concepts” originally proposed by Brennan and Resnick [
20
]. The redefined computational thinking concepts are classified into the following seven groups: (1) Abstraction and Problem Decomposition, (2) Parallelism, (3) Logical Thinking, (4) Synchronization, (5) Flow Control, (6) User Interactivity, and (7) Data Representation. The advantage of this rubric is that it can be directly (and automatically) applied to Scratch projects.
Sherman et al. [
25
] presented a rubric for App Inventor called the “App Inventor Project Rubric”. This rubric can assess students’ “mobile computational thinking” skills, and it has the following 14 assessment categories: (1) Screen Interface, (2) Naming, (3) Events, (4) Procedural Abstraction, (5) Globals with Variables or Text Labels, (6) Component Abstraction, (7) Loops, (8) Conditionals, (9) Lists, (10) Data Persistence, (11) Data Sharing, (12) Public Web Services, (13) Accelerometer and Orientation Sensors, and (14) Location Awareness.
Wangenheim et al. [
26
] presented rubrics for “Snap!” [
27
] and App Inventor based on earlier work ([
1825
] respectively). They also presented a program called “CodeMaster” which automatically calculates the score of each project. However, their rubrics are not integrated into a single rubric, making it difficult to compare projects written in different languages: for example, while the App Inventor rubric includes criteria pertaining to local databases (TinyDB), Snap! does not provide this functionality by default. As another example, while the Snap! rubric includes criteria for Parallel Execution, the App Inventor rubric does not include such criteria.
To the best of our knowledge, there is no unified rubric that can be used to assess both Scratch and App Inventor projects in terms of computational thinking. In
Section 3
, we present a unified rubric based on the common features of Scratch and App Inventor in order to compare these two languages. Note that although Scratch and App Inventor are both programming languages and environments [
28
], we compare them mostly from the perspective of a programming language, as there are many common features from a language perspective as opposed to an environment perspective.
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.
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.
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.)
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.
Hello friends,
In this topic I am going to show some examples of Arduino UNO with the Bluetooth HC-06 module.
I will start with simple examples and later I will put some more complicated codes.
Hello friends,
In this topic I am going to show some examples of Arduino UNO with the Bluetooth HC-06 module.
I will start with simple examples and later I will put some more complicated codes.
1.- App sends simple char. Arduino on-off LED12 and LED13.
p9A0i_bluetooth_caracter.aia (2.4 KB)
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #define Pin12 12 #define Pin13 13 char caracter; void setup() { Serial.begin(9600); pinMode(Pin12, OUTPUT); pinMode(Pin13, OUTPUT); } void loop() { if(Serial.available()) { caracter = Serial.read(); if(caracter == 'a'){ digitalWrite(Pin12, HIGH);} if(caracter == 'b'){ digitalWrite(Pin12, LOW);} if(caracter == 'c'){ digitalWrite(Pin13, HIGH);} if(caracter == 'd'){ digitalWrite(Pin13, LOW);} } }
Instead of using LEDs you can put Relays.
2A.- App sends text. Arduino on-off LED12 and LED13. Serial Monitor. With asterisk.
p9A0i_bluetooth_texto.aia (2.6 KB)
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #define Pin12 12 #define Pin13 13 char caracter; String palabra; void setup() { Serial.begin(9600); pinMode(Pin12, OUTPUT); pinMode(Pin13, OUTPUT); } void loop() { if(Serial.available()) { caracter = Serial.read(); palabra = palabra + caracter; if(caracter == '*') { palabra = palabra.substring(0, palabra.length() - 1); // Delete last char * Serial.println(palabra); if (palabra == "on12"){digitalWrite(Pin12, HIGH);} if (palabra == "off12"){digitalWrite(Pin12, LOW);} if (palabra == "on13"){digitalWrite(Pin13, HIGH);} if (palabra == "off13"){digitalWrite(Pin13, LOW);} palabra = ""; delay(100); } } }
oooooooooooooooo0000000000000000ooooooooooooooooooo
2B.- App sends text. Arduino on-off LED12 and LED13. Serial Monitor. Without asterisk.
p9A0i_bluetooth_texto_2.aia (2.6 KB)
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #define Pin12 12 #define Pin13 13 char caracter; String palabra; void setup() { Serial.begin(9600); pinMode(Pin12, OUTPUT); pinMode(Pin13, OUTPUT); } void loop() { if(Serial.available()) { caracter = Serial.read(); palabra = palabra + caracter; Serial.println(palabra); if (palabra.indexOf("on12")>= 0){digitalWrite(Pin12, HIGH); palabra = "";} if (palabra.indexOf("off12")>= 0){digitalWrite(Pin12, LOW); palabra = "";} if (palabra.indexOf("on13")>= 0){digitalWrite(Pin13, HIGH); palabra = "";} if (palabra.indexOf("off13")>= 0){digitalWrite(Pin13, LOW); palabra = "";} delay(100); } }
3.- App sends several information at the same time.
In this example we will use the same App as in the previous example.
Suppose we want to send two information at the same time, for example we want to turn on LED12 and turn off LED13.
We write in the TextBox: on12, off13 [the asterisk will be added automatically at the end of this text]
The Arduino code will check if the text sent contains the string: on12, off12, on13, off13
To check if a substring is in a text we use indexOf: if(palabra.indexOf(“on12”)>= 0)
We can also put the text in another order: off13, on12
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #define Pin12 12 #define Pin13 13 char caracter; String palabra; void setup() { Serial.begin(9600); pinMode(Pin12, OUTPUT); pinMode(Pin13, OUTPUT); } void loop() { if(Serial.available()) { caracter = Serial.read(); palabra = palabra + caracter; if(caracter == '*') { palabra = palabra.substring(0, palabra.length() - 1); // Delete last char * Serial.println(palabra); if(palabra.indexOf("on12")>= 0){digitalWrite(Pin12, HIGH);} if(palabra.indexOf("off12")>= 0){digitalWrite(Pin12, LOW);} if(palabra.indexOf("on13")>= 0){digitalWrite(Pin13, HIGH);} if(palabra.indexOf("off13")>= 0){digitalWrite(Pin13, LOW);} palabra = ""; delay(100); } } }
4.- App sends three values separated by comma. Arduino receives them and separates them.
In this example we will use the same App as in the previous example.
We assume that the App wants to send these numbers separated by commas to the Arduino: 126,3,58
An asterisk will be added indicating end of message. [126,3,58*]
In this case it is necessary to indicate the end of the message (example with asterisk) since we can send any number.
Arduino will receive that text and separate it by the comma.
Check Serial Monitor.
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm char caracter; String palabra; String red; String green; String blue; int ind1; int ind2; int ind3; void setup() { Serial.begin(9600); } void loop() { if(Serial.available()) { caracter = Serial.read(); palabra = palabra + caracter; if(caracter == '*') { palabra = palabra.substring(0, palabra.length() - 1); // Delete last char * Serial.println(palabra); ind1 = palabra.indexOf(','); red = palabra.substring(0, ind1); ind2 = palabra.indexOf(',', ind1+1 ); green = palabra.substring(ind1+1, ind2); ind3 = palabra.indexOf(',', ind2+1 ); blue = palabra.substring(ind2+1); Serial.print("red = "); Serial.println(red); Serial.print("green = "); Serial.println(green); Serial.print("blue = "); Serial.println(blue); Serial.println(); palabra = ""; delay(10); } } }
ooooooooooooooo000000o000000oooooooooooooooAnother way to split the data in with this getValue function:
Serial.println(palabra); red = getValue(palabra,',',0); green = getValue(palabra,',',1); blue = getValue(palabra,',',2); (...) ///////////////// Function Split by char //////////////// String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = {0, -1}; int maxIndex = data.length()-1; for(int i=0; i<=maxIndex && found<=index; i++){ if(data.charAt(i)==separator || i==maxIndex){ found++; strIndex[0] = strIndex[1]+1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found>index ? data.substring(strIndex[0], strIndex[1]) : ""; }
5.- App requests temperature and humidity to the Arduino. The Arduino sends values.
p9A0i_bluetooth_temperatura.aia (3.3 KB)
When Click in tempe_humidity Button, App sends the character “D”.Arduino concatenates the temperature and humidity Strings separated by a comma:37,80
App ReceiveText 37,80 converts it to a list and separates the values.
Note: the DelimiterByte must have the value 10. [10 is ASCII New Line, LF. Arduino \n]
In this Arduino code I do not use the sensor or the I2C LCD to simplify its content.Here you can see the code with the sensor and the I2C LCD
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm char caracter; int temperature = 0; int humidity = 0; String tempera_humidity; void setup() { Serial.begin(9600); } void loop() { temperature = random(20,40); humidity = random(50,95); delay(500); if(Serial.available()) { caracter = Serial.read(); if(caracter == 'T'){Serial.println(temperature);} if(caracter == 'H'){Serial.println(humidity);} if(caracter == 'D'){ tempera_humidity = (String) temperature + "," + (String) humidity; Serial.println(tempera_humidity); } } }
6.- App checks status 2 PushButtons.
p9A0i_bluetooth_pulsadores.aia (3.4 KB)
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm char caracter; #define push7 7 // PushButton 7. #define push8 8 // PushButton 8. String status_push7; String status_push8; String status; void setup() { Serial.begin(9600); pinMode(push7, INPUT); pinMode(push8, INPUT); } void loop() { delay(50); if(Serial.available()) { caracter = Serial.read(); if (digitalRead(push7) == HIGH) {status_push7 = "Push7 ON";} else {status_push7 = "Push7 OFF";} if (digitalRead(push8) == HIGH) {status_push8 = "Push8 ON";} else {status_push8 = "Push8 OFF";} status = status_push7 + "," + status_push8; if(caracter == '7'){Serial.println(status_push7);} if(caracter == '8'){Serial.println(status_push8);} if(caracter == 'D'){Serial.println(status);} } }
7.- App gets the value of two potentiometers.
p9A0i_bluetooth_potenciometro.aia (3.3 KB)
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm int value_pot0; int value_pot1; String value; void setup() { Serial.begin(9600); } void loop() { value_pot0 = analogRead(A0); value_pot1 = analogRead(A1); value = (String) value_pot0 + "," + (String) value_pot1; Serial.println(value); delay(200); // It should be slower than the Clock Interval. }
8.- App receives data from Arduino. Clock.Interval. Arduino delay. Buffer.
p9A0i_bluetooth_aleatorio.aia (2.9 KB)
a)Clock.Interval = 300Arduino delay = 200
App cannot process the information because the Clock “is slower” than the Arduino.The buffer is being filled, values that arrive and have not yet been processed.
When the Buffer reaches a certain value, for example 120, you remove power to the Arduino. What happens with buffer?
b) Change Clock.IntervalClock.Interval = 100Arduino delay = 200
Therefore, Clock.Interval < delay Arduino
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm int aleatorio; void setup() { Serial.begin(9600); } void loop() { aleatorio = random(0,100); Serial.println(aleatorio); delay(200); // Clock.Interval < delay Arduino }
9.- A potentiometer in Arduino sends values to the App. Dynamic graph. Shift left.
p9A0i_bluetooth_dinamico.aia (8.1 KB)
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm int value_pot0; void setup() { Serial.begin(9600); } void loop() { value_pot0 = analogRead(A0); Serial.println(value_pot0); delay(100); // It should be slower than the Clock Interval. }
10.- Three LEDS on-off according to a sequence saved in a file.
p9A0i_bluetooth_secuencia3LED.aia (5.0 KB)
In file rutina2.csv this content:
Levels of: LED11 – LED12 – LED13 – Time in seconds of this combination.
App sends 1-1-0-2*
Arduino set LEDs on, on, off
and wait 2 seconds.
then Arduino sends to App “send_me_next”
When App receives “send_me_next”
App “send_next” combination: 1-0-0-2*
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm char caracter; String palabra; int LED11 = 11; int LED12 = 12; int LED13 = 13; int valor11; int valor12; int valor13; int Tiempo = 1000000; unsigned long currentMillis; unsigned long previousMillis = currentMillis; int k1; int k2; int k3; int k4; void setup() { Serial.begin(9600); pinMode(LED11, OUTPUT); pinMode(LED12, OUTPUT); pinMode(LED13, OUTPUT); } void loop() { if(Serial.available()) { caracter = Serial.read(); palabra = palabra + caracter; Serial.println(palabra); if(caracter == '*') { palabra = palabra.substring(0, palabra.length() - 1); // Delete last char * k1 = palabra.indexOf('-'); valor11 = palabra.substring(0, k1).toInt(); k2 = palabra.indexOf('-', k1+1); valor12 = palabra.substring(k1+1, k2).toInt(); k3 = palabra.indexOf('-', k2+1); valor13 = palabra.substring(k2+1, k3).toInt(); k4 = palabra.indexOf('-', k3+1); Tiempo = 1000 * palabra.substring(k3+1, k4).toInt(); palabra = ""; digitalWrite(LED11, valor11); digitalWrite(LED12, valor12); digitalWrite(LED13, valor13); } previousMillis = currentMillis; } // =>Fin del available tiempo(); } // =>Fin del loop void tiempo() { currentMillis = millis(); if (currentMillis >= (previousMillis + Tiempo)) { previousMillis = currentMillis; Serial.println("send_me_next"); // Envíame el siguiente. } }
11.- Virtual Screen with two VerticalArrangement.
p9A0i_bluetooth_virtual.aia (4.1 KB)
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #define LED13 13 byte StatusLED13; void setup() { Serial.begin(9600); pinMode(LED13, OUTPUT); } void loop() { if(Serial.available()) { int dato = Serial.read(); if(dato == 153){digitalWrite(LED13, HIGH);} if(dato == 168){digitalWrite(LED13, LOW);} if(dato == 221){ StatusLED13 = digitalRead(LED13); Serial.print(StatusLED13); // Sends 48 or 49 } } }
12.- App moves two Servos by Sliders.
p9A0i_bluetooth_servos.aia (3.2 KB)
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #include
Servo servo3; Servo servo5; const int pwmPin3 = 3; // Servo3 pin3 PWM const int pwmPin5 = 5; // Servo5 pin5 PWM char caracter; String palabra; String angulo_1; String angulo_2; int k1; void setup() { Serial.begin(9600); pinMode (pwmPin3, OUTPUT); pinMode (pwmPin5, OUTPUT); servo3.attach(pwmPin3); servo5.attach(pwmPin5); } void loop() { if(Serial.available()) { caracter = Serial.read(); palabra = palabra + caracter; if (caracter == '*') { Serial.println(palabra); palabra = palabra.substring(0, palabra.length() - 1); // Delete last char * k1 = palabra.indexOf(','); angulo_1 = palabra.substring(0, k1); angulo_2 = palabra.substring(k1+1, -1); servo3.write(angulo_1.toInt()); servo5.write(angulo_2.toInt()); palabra = ""; } } } // => Fin Loop
Note: if you use more than 2 servos you will need to power them with an external power source. Video: Each servo needs about 400 mA.
13.- App moves a Stepper motor.
p9A0i_bluetooth_pasopaso.aia (3.1 KB)
In a servo you order:set 34ºset 12ºset 96º, it is not necessary to know the previous position.
In a stepper motor, you order:set 20 step clockwiseset 80 step anticlockwise, it is necessary to know the previous position to place it in a new position.
I will use: Stepper motor 28BYJ-48 ULN2003
It is convenient to power this motor through an external source, in this experimental example I will feed it with the 5 V of Arduino.
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #include
#define STEPS 64 // Secuencia 1-3-2-4 Stepper motor(STEPS, 8, 10, 9, 11); char caracter; void setup() { Serial.begin(9600); motor.setSpeed(200); } void loop() { if( Serial.available() ) { caracter = Serial.read(); Serial.print(caracter); if(caracter == '1'){motor.step(60);} if(caracter == '2'){motor.step(-60);} if(caracter == '3'){motor.step(510);} if(caracter == '4'){motor.step(-510);} if(caracter == '5'){motor.step(1020);} if(caracter == '6'){motor.step(-1020);} if(caracter == '7'){motor.step(2040);} if(caracter == '8'){motor.step(-2040);} if(caracter == 'A'){motor.step(100);} if(caracter == 'B'){motor.step(-100);} } }
14. Where do we connect the Bluetooth module in Arduino UNO?
p9A0i_bluetooth_Serial.aia (2.9 KB)
Terminals 0 (RX) and 1 (TX) are used by Arduino as the default Serial RX/TX. Use it to upload sketch, Serial Monitor, Bluetooth. So when we are going to upload a sketch for Bluetooth we must disconnect the RX cable from the Arduino.
We can use other terminals to connect the Bluetooth module, for example 10 and 11, in this case we need the “SoftwareSerial” library. Now when we upload a sketch it is not necessary to remove the RX cable.
– CODE FOR MODULE IN default RX/TX pin 0 and 1 of Arduino.
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #define Pin13 13 char caracter; void setup() { Serial.begin(9600); pinMode(Pin13, OUTPUT); } void loop() { if(Serial.available()) { caracter = Serial.read(); if(caracter == 'a'){ digitalWrite(Pin13, HIGH);} if(caracter == 'b'){ digitalWrite(Pin13, LOW);} Serial.println(caracter); } }
– CODE FOR MODULE IN pin10 and pin11 with SoftwareSerial library.
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #include
SoftwareSerial I2CBT(10,11); // El TX del módulo BT va al pin10 del Arduino // El RX del módulo BT va al pin11 del Arduino #define Pin13 13 char caracter; void setup() { I2CBT.begin(9600); // To read and write Bluetooth Serial.begin(9600); // To print in Serial Monitor pinMode(Pin13, OUTPUT); } void loop() { if(I2CBT.available()) { caracter = I2CBT.read(); if(caracter == 'a'){ digitalWrite(Pin13, HIGH);} if(caracter == 'b'){ digitalWrite(Pin13, LOW);} Serial.println(caracter); // Serial Monitor I2CBT.println(caracter); // return Bluetooth // I2CBT.write(caracter); // return Bluetooth } }
15.- Send text file from Server to Client and from Client to Server. Message Mobile to Mobile by Bluetooth.
p9A0i_BT_Server_File.aia (3.3 KB)
p9A0i_BT_Client_File.aia (3.4 KB)
– Blocks Server.
– Blocks Client.
16.- Send Image file from Server to Client and from Client to Server.
This example is only experimental, there are problems with file size, clock interval, conversion … Try.
p9A0i_BT_Server_Image.aia (41.9 KB)
p9A0i_BT_Client_Image.aia (55.6 KB)
– Blocks Server.
– Blocks Client.
17.- Write number with KeyPad in Arduino and sends to App by Bluetooth. LCD I2C.
p9A0i_bluetooth_teclado.aia (1.8 MB)
// Juan A. Villalpando // http://kio4.com/appinventor/9BA_bluetooth_teclado_LCD.htm #include
#include
// Pantalla LCD #includeLiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); String clave = ""; String clave_old = ""; const byte ROWS = 4; const byte COLS = 4; char keys[ROWS][COLS] = { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; byte rowPins[ROWS] = {0, 1, 2, 3}; byte colPins[COLS] = {4, 5, 6, 7}; int i2caddress = 0x20; // Module I2C Keyboard. Keypad_I2C kpd = Keypad_I2C( makeKeymap(keys), rowPins, colPins, ROWS, COLS, i2caddress); void setup() { Serial.begin(9600); kpd.begin(); lcd.begin(16,2);// Columnas y filas de LCD. } void loop() { char key = kpd.getKey(); clave = clave + (String) key; if (key == '#') { clave = clave.substring(0, clave.length() - 1); // Delete last char # lcd.clear(); lcd.setCursor(0,0); lcd.print(clave); lcd.setCursor(0,1); lcd.print(clave_old); clave_old = clave; Serial.println(clave); clave = ""; } delay(100); }
18.- Poor man’s circuit.
// Juan A. Villalpando // http://kio4.com/appinventor/9BA_bluetooth_teclado_LCD.htm char key = 0; String clave = ""; void setup() { Serial.begin(9600); } void loop() { if (Serial.available() > 0) { key = Serial.read(); clave = clave + key; if (key == '#') { Serial.print(clave); // Example sends: 123# clave = ""; } } }
19.- Arduino Interrupts sends data to App.
p9A01_bluetooth_interrupt.aia (2.3 KB)
Arduino UNO has two pins for interruptions (pin2 and pin3). ESP32 has 32 interrupt pins).
Arduino interrupts: https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
When pin2 RISING causes an interrupt and calls function on_13
When pin3 RISING causes an interrupt and calls function off_13
// Juan A. Villalpando // http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm #define LED13 13 void setup() { Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(2), on_13, RISING); attachInterrupt(digitalPinToInterrupt(3), off_13, RISING); pinMode(LED13, OUTPUT); } void loop() { // } // Interruptions ISR. void on_13() // When pin2 RISING... { digitalWrite(LED13, HIGH); Serial.print(1); } void off_13() // When pin3 RISING... { digitalWrite(LED13, LOW); Serial.print(0); }
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.
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?
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 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.
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
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.
|
|
Below is a video that goes through all the steps to assembling and running the traffic lights using the Arduino Look the Demonstration video HERE
Introduction
In this project I am going to demonstrate how to control 3 Led using your smart phone with the help of Bluetooth connectivity.
This project will involve using a little a bit of code and a very simple circuit that’s great for beginners.
The video further down this page will go through all the steps to completing this very cool DIY LED Controlled project.
This project aims to control the blinking of a LED using wireless technology. This will serve as a base to build more amazing projects on home automation and many more automation projects.
Working on Basics
The LED have been powered by Arduino UNO (Board). It contains a code which uploaded to the board. And once it simulated you can connect with Bluetooth Module (HC-05) with you compatible device
Once code have been uploaded and Connected the Bluetooth and start pressing button through app known as Bluetooth Electronics and start pressing button you will be able to see that the desire led which is code for button pressed will be turned on.
Refer to this video there is full instruction how to create button in app and how to use app.
Usage
There is multiple use of this project:-
- You can come to know how to use Bluetooth with Arduino
- It is a very helpful project who are getting starting in home automation.
- If you are a beginner and want to control Arduino with Smartphone so you can do with the help of this.
- You can change code and components according to you and can code it easily and control it through smartphone easily.
Connection of HC-05
- Hook the GND pin (Negative Pin) of HC-05 to Pin GND of Arduino.
- Connect Red VCC Pin (Positive Pin) of HC-05 to VCC of Arduino.
- Connect TXpin (DataTransferPin) of HC-05 to RX pin of Arduino.
- Connect RXPin ofHC-05 to TXPin of Arduino.
Connection of LED
- Hook the GND Pin(NegativePin) of all led to Pin GND of Arduino.
- Connect VCC Pin (Positive Pin) of Red LED to Pin 3 of Arduino.
- Connect VCC Pin (Positive Pin) of Blue LED to Pin 4 of Arduino.
- Connect VCC Pin (Positive Pin) of Green LED to Pin 5 of Arduino.
- Copy or download the code attached with the project.
- Download the app known as Bluetooth Electronics available on Play Store. CLICK HERE to download.
- Build up Button to control LED using the app. To Watch video how to Build up button CLICK HERE.
- Once complete setup you will able to control (on/off) LED using your Device
Introduction
Scratch [
12
] and App Inventor [
34
] are two of the most widely used block-based programming languages and environments for colleges, universities and K-12 students. As of August of 2019, there are 44,981,198 registered users on the Scratch website and 8,200,000 registered users on the App Inventor website. Both Scratch and App Inventor are educational programming languages that allow novice programmers or even young students to program easily by dragging and dropping their code blocks [
56
]. Although Scratch was originally developed for teaching young students (ages 8–16) [
2
], it has also been taught at the college level [
7
]. Similarly, although App Inventor is mainly used in introductory computer science courses for non-majors [
3
], there are many examples of successful App Inventor courses at the secondary school level [
8
]. Scratch and App Inventor are both programming languages and environments [
28
].
Students can improve their
computational thinking91011121314
] skills by making applications using these programming languages [
1
]. The term “computational thinking” was mentioned for the first time by Seymour Papert [
15
] and has since become widely known through Jeannette Wing’s CACM paper [
9
]. Computational thinking can be defined as the “thought processes involved in formulating problems and their solutions so that the solutions are represented in a form that can be effectively carried out by an information-processing agent” [
11
]. As Jeannette Wing argued, “Computational thinking is a fundamental skill for everyone, not just for computer scientists” [
16
].
There have been proposed several rubrics for assessing students’ computational thinking skills based on their developed Scratch or App Inventor projects. A typical example is Dr. Scratch [
171819
]. The authors of Dr. Scratch redefine
computational thinking concepts20
] in order to assess students’ individual levels of computational thinking. The computational thinking concepts include
Abstraction and Problem DecompositionParallelismLogical ThinkingSynchronizationFlow ControlUser Interactivity
, and
Data Representation
. The authors also presented a rubric which calculates the “computational thinking scores” based on the computational thinking concepts. It is assumed that the higher scores indicate (1) a better understanding of computational thinking concepts and (2) better computational thinking skills acquired.
Our hypothesis is that the degree of improvement in students’ computational thinking skills will vary somewhat depending on which programming language they learn. This is in line with the opinion of Edsger W. Dijkstra, who stated “we are all shaped by the tools we train ourselves to use.” Thus, our research questions are as follows:
-
Which programming language, Scratch or App Inventor, is better for learning each computational thinking concept?
-
Do our students need to learn both Scratch and App Inventor in order to enhance their overall computational thinking skills?
In this paper, we propose a novel rubric based on Dr. Scratch for assessing both Scratch and App Inventor projects in terms of the learning of computational thinking concepts. We examine teachers’ and students’ popular projects and calculate their “effectiveness scores” in learning computational thinking concepts based on our rubric. To the best of our knowledge, although there have been papers [
212223
] comparing Scratch and App Inventor, no papers have compared these languages in terms of computational thinking. Furthermore, although there are rubrics for Scratch projects and App Inventor projects individually, there is no common rubric for assessing both Scratch and App Inventor projects.
The main contributions of our paper are as follows:
-
We propose a novel rubric that can be used for assessing both Scratch and App Inventor projects (
Section 3
).
-
We collect open and popular Scratch and App Inventor projects (
Section 4.1
) and calculate their effectiveness scores with regard to learning computational thinking concepts based on our rubric, thus answering our first research question (
Section 4.2
).
-
We analyze the result of our experiments, thus answering our second research question (
Section 4.3
).
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
Trong Hướng dẫn Arduino này, chúng ta sẽ tìm hiểu cách tạo các ứng dụng Android để kiểm soát Arduino bằng ứng dụng trực tuyến MIT App Inventor. Bạn có thể xem video sau hoặc đọc hướng dẫn dưới đây.
Tổng quan
Đối với hướng dẫn này, chúng tôi có hai ví dụ. Ví dụ đầu tiên là điều khiển một đèn LED đơn giản và cái thứ hai là điều khiển động cơ bước sử dụng điện thoại thông minh.
Code Arduino
Dưới đây là tổng quan nhanh về code. Thông qua cổng nối tiếp, nhận được dữ liệu đến từ điện thoại và lưu trữ nó trong biến ‘trạng thái’. Nếu nhận được ký tự ‘0’ được gửi từ điện thoại khi nhấn nút ‘LED: TẮT’, chúng tôi sẽ tắt đèn LED và gửi lại cho điện thoại String Đèn LED: TẮT. Mặt khác, nếu chúng tôi nhận được ký tự ‘1’, chúng tôi sẽ bật đèn LED và gửi lại String Đèn LED: ON.
#define ledPin 7 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; } }
Vì vậy, bây giờ chúng ta cần xây dựng ứng dụng Android tùy chỉnh của mình, nó sẽ gửi các ký tự ‘0’ và ‘1’ khi nhấn một nút cụ thể, cũng như, nhận các Chuỗi đến từ Arduino.
Nhà phát minh ứng dụng MIT
Từ trang web MIT App Inventor, cần đăng nhập vào ứng dụng xây dựng trực tuyến bằng cách nhấp vào nút Tạo ứng dụng! Để đăng nhập, cần phải có tài khoản Gmail. Khi đã đăng nhập, bạn có thể tạo dự án đầu tiên của mình. Đây là cửa sổ thiết kế và bây giờ chúng ta có thể bắt đầu xây dựng ứng dụng của mình.
Cửa sổ thiết kế ứng dụng MIT
Nhưng trước khi làm điều đó, chúng ta cần kết nối điện thoại của mình với dự án này để có thể xem ứng dụng đang hình thành trực tiếp trên điện thoại của chúng ta trong thời gian thực như thế nào. Để thực hiện điều đó trước tiên, phải tải xuống ứng dụng MIT AI2 Companion từ Play Store và cài đặt nó trên điện thoại. Sau đó, từ menu Connect từ trình chỉnh sửa trực tuyến, chọn AI Companion và mã vạch sẽ xuất hiện, sau đó chỉ cần quét hoặc chèn mã vào ứng dụng điện thoại và kết nối giữa trình chỉnh sửa trực tuyến và ứng dụng điện thoại sẽ được thiết lập.
Phát triển ứng dụng Mit và kết nối điện thoại
Bây giờ, ví dụ, nếu chúng ta chèn một nút trong màn hình của trình chỉnh sửa trực tuyến, nút này cũng sẽ xuất hiện trên điện thoại. Tương tự như vậy, nếu bạn không muốn sử dụng điện thoại của mình trong khi xây dựng ứng dụng, bạn có thể cài đặt Trình giả lập Android trên máy tính và sử dụng theo cách tương tự. Bạn có thể tìm thêm chi tiết cách thiết lập Trình mô phỏng trên trang web của họ.
Xây dựng ứng dụng – Ví dụ 1
Bây giờ bạn đã sẵn sàng để xây dựng ví dụ đầu tiên. Chúng ta sẽ bắt đầu với bố cục của chương trình. Đầu tiên, chúng ta sẽ thêm một số tính năng ngang từ bảng bố trí và đặt các thuộc tính của chúng như chiều cao, chiều rộng và căn chỉnh để phù hợp với giao diện mong muốn của chương trình. Sau đó, từ Bảng màu UserInterface, chúng ta sẽ thêm ListPicker và đính kèm hình ảnh vào đó. ListPicker sẽ được sử dụng để chọn thiết bị Bluetooth mà điện thoại của chúng tôi sẽ kết nối.
Xây dựng ứng dụng Android – Ví dụ 01
Tiếp theo, thêm một tính năng ngang khác, trong đó đặt tên cho nó. Nhãn này sẽ cho biết điện thoại có được kết nối hay không với mô-đun Bluetooth và đó là lý do tại sao chúng ta sẽ đặt tên ban đầu của nhãn này thành Không được kết nối. Nhãn tiếp theo sẽ được sử dụng để hiển thị trạng thái của đèn LED, cho dù đã tắt hay bật. Trạng thái ban đầu sẽ là LED: OFF. Tiếp theo, thêm hai nút, ‘Bật’ và ‘Tắt’ để điều khiển đèn LED. Tại thời điểm này, tốt hơn là đổi tên các thành phần để chúng ta có thể dễ dàng nhận ra và sử dụng chúng hơn trong trình chỉnh sửa Blocks sau này. Những gì còn lại bây giờ là thêm BluetoothClient, một thành phần không nhìn thấy cũng như đồng hồ sẽ được sử dụng để chỉ báo thời gian thực về trạng thái kết nối.
Trình chỉnh sửa khối
Bây giờ trong trình chỉnh sửa Blocks, chúng ta đã sẵn sàng hoàn thiện cho chương trình của mình. Từ phía bên trái, chúng ta có tất cả các khối và chức năng liên quan đến các thành phần được thêm vào trước đó.
Khối ứng dụng Android – Ví dụ 01
Chúng ta sẽ bắt đầu với Danh sách BluetoothList ListPicker. Từ đó trước tiên, chúng ta sẽ thêm khối ‘BeforePicking’ và đính kèm với khối ‘thiết lập các thành phần Bluetooth’. Sau đó, từ các khối BluetoothClient, thêm khối ‘ BluetoothClient AddressesAndNames’. Khối này sẽ thiết lập một danh sách các thiết bị Bluetooth đã được kết nối với điện thoại để khi nhấp vào nút ListPicker, nút kết nối, danh sách tất cả các thiết bị được ghép nối sẽ hiển thị.
Tiếp theo, chúng ta phải đặt những gì sẽ xảy ra sau khi chúng ta sẽ chọn hoặc chọn mô-đun Bluetooth cụ thể của mình. Từ khối BluetoothClient, thêm khối ‘call BluetoothClient .Connect address’. và thêm khối BluetoothList Selection’ vào đó, có nghĩa là điện thoại sẽ kết nối với địa chỉ Bluetooth đã chọn trước đó.
Tiếp theo từ các khối Đồng hồ, chúng tôi sẽ thêm khối “.Timer “. Trong khối này, chúng ta sẽ đưa ra dấu hiệu thời gian thực cho dù điện thoại có được kết nối hay không với mô-đun Bluetooth bằng cách sử dụng khối “set Text” có tên là “Connected”.
Khối đồng hồ
Tiếp theo chúng ta cần cung cấp cho cuộc sống cho hai nút. Vì vậy, khi nhấp vào nút TurnOn_Button, chúng tôi sẽ sử dụng chức năng máy khách Bluetooth, Send Send1ByteNumber, để gửi một số đến mô-đun Bluetooth Arduino. Trong trường hợp của chúng tôi, đó là số 49 tương ứng với ký tự ‘1’ theo bảng ASCII và nó sẽ bật đèn LED. Ngay sau đó, chúng tôi sẽ sử dụng chức năng BluetoothClient của Bluetooth GetText để nhận Chuỗi đến được gửi lại từ Arduino tới điện thoại. Chuỗi này được đặt thành Nhãn LED LED_Status.
Khối nút
Quy trình tương tự cũng diễn ra đối với “TurnOff_Button”, trong đó số gửi sẽ được thay đổi thành 48 tương ứng với ký tự ‘0’. Những gì còn lại bây giờ là tải xuống và cài đặt chương trình trên điện thoại. Chúng ta có thể tải từ menu của “Build” bằng cách lưu nó vào máy tính và sau đó chuyển vào điện thoại hoặc quét mã QR để tải xuống chương trình trực tuyến.
Đây là tệp tải xuống của dự án MIT App Inventor ở trên:
Ví dụ điều khiển động cơ bước
Bây giờ hãy xem ví dụ thứ hai, điều khiển động cơ bước. Ở đầu màn hình, chúng ta có các thành phần tương tự cho kết nối Bluetooth như ví dụ trước. Tiếp theo chúng ta có một thành phần Canvas được sử dụng để vẽ và chèn hình ảnh. Tôi đã chèn hai hình ảnh trước đây tôi đã vẽ. Cái đầu tiên là hình ảnh của một thước đo sẽ được cố định tại chỗ và cái thứ hai là hình ảnh của một con trỏ sẽ quay. Tiếp theo, chúng ta có nút Kiểm tra để chuyển đổi giữa Chế độ thủ công và Tự động hoặc chế độ chạy liên tục và một nút để thay đổi hướng xoay. Chúng ta còn có một thanh trượt để thay đổi tốc độ quay của động cơ bước.
Dưới đây là các khối và code Arduino đằng sau ví dụ này. Trong trình chỉnh sửa Blocks một lần nữa, chúng ta có các khối tương tự cho kết nối Bluetooth như ví dụ trước.
Ví dụ điều khiển động cơ bước Khối 01
Bây giờ để xoay con trỏ, chúng tôi sử dụng chức năng “.PointInDirection”, trong đó xoay con trỏ từ vị trí 0 ° theo trục X và Y nơi Canvas đã được chạm vào. Đồng thời, đặt tiêu đề ImageSprite thành tên con trỏ. Sau đó, gọi thủ tục tùy chỉnh được thực hiện hoặc chức năng delay 10m giây.
Cuối cùng, gửi giá trị tiêu đề dưới dạng Văn bản tới Arduino bằng chức năng Bluetooth SendText của Bluetooth. Giá trị này sẽ được chấp nhận bởi Arduino và nó sẽ xoay động cơ bước tương ứng.
Tiếp theo là khối CheckBox. Nếu CheckBox được kiểm tra, chúng tôi sẽ gửi văn bản (Auto Auto) đến Arduino để kích hoạt động cơ bước để xoay liên tục. Mặc dù đang ở chế độ này nếu nhấn nút Reverse, chúng ta sẽ gửi văn bản Nghịch đảo Reverse tới Arduino để thay đổi hướng quay của động cơ. Ngoài ra, trong khi ở chế độ này, chúng ta có thể thay đổi tốc độ quay. Nếu chúng ta thay đổi vị trí của thanh trượt, giá trị hiện tại của vị trí thanh trượt sẽ được gửi đến Arduino, nó sẽ thay đổi tốc độ quay của động cơ bước. Nếu chúng ta bỏ chọn CheckBox, chúng tôi sẽ quay lại chế độ thủ công.
Đây là tệp tải xuống của dự án MIT App Inventor ở trên, cũng như hai hình ảnh được sử dụng trong dự án:
Dịch từ: https://howtomechatronics.com/tutorials/arduino/how-to-build-custom-android-app-for-your-arduino-project-using-mit-app-inventor/
Đây là code Arduino của ví dụ thứ hai:
// 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; } } }
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)
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
Conclusions
In this paper, we compared the effectiveness of Scratch and App Inventor with regard to the learning of computational thinking concepts. In order to compare these languages, we initially proposed a novel rubric for assessing both Scratch and App Inventor projects in terms of computational thinking concept learning. Based on the rubric, we calculated the effectiveness scores of high-quality Scratch and App Inventor projects. Note while some projects were created by teachers or adults, most were made by young students, by themselves. The experimental results show that the effectiveness scores for Scratch and App Inventor projects are significantly different. More specifically, Scratch projects scored higher on average on Parallelism, Synchronization, and Flow Control, while App Inventor projects scored higher on average on User Interactivity and Data Representation. However, we also found that the overall scores for programs tend to increase as the number of lines of code increases and that the scores are highly dependent on the types (genres) of projects. Based on these results, we can conclude that if students learn both Scratch and App Inventor, they can improve their computational thinking skills in general, and that mastering a single programming language can also improve their overall computational thinking skills if they practice creating various types of large programs.
Our future work will take three directions. First, we would like to survey or interview groups of experts (such as teachers and computer scientists) with regard to the learning of computational thinking concepts through Scratch and App Inventor. It would be very useful to uncover the difference between the results obtained by selected projects (artefacts) and the results obtained through expert groups. Second, we want to prepare educational materials for these languages in order to develop students’ comprehensive computational thinking skills based on the rubric proposed in this study. In particular, we would like to focus on what types of projects could be taught to students in order to foster computational thinking more effectively. Finally, we want to implement a more general rubric that consists not only of block-based programming languages but also of text-based programming languages such as Python and JavaScript, as these text-based programming languages are also widely used for educational purposes.
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.
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.
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:
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
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.
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):
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.
Unified Rubric for Assessing Both Scratch and App Inventor Projects
One of the barriers to making a unified rubric that can be used for assessing both Scratch and App Inventor is that each programming language has its own code blocks. For example, App Inventor has local file access blocks (TinyDB) while Scratch does not have these types of blocks. Moreover, while Scratch can create clones of sprites, App Inventor does not have a cloning block. Therefore, we create a novel unified rubric based on the common features of Scratch and App Inventor. We reused the category names of the computational thinking concepts used in Dr. Scratch and modify the detailed criteria by taking into account the common characteristics of Scratch and App Inventor.
summarizes the proposed rubric, which assigns a maximum of three points for each computational thinking concept. The detailed criteria of our rubric for assessing each concept are described below.
Abstraction and Problem Decomposition. We calculate the Abstraction and Problem Decomposition scores based on the sprites, components, and procedures, because these elements are strongly related to how the program is organized. The “sprite” of Scratch is similar to the “component” of App Inventor. Without a sprite or a component, we do not execute most of the code blocks. Thus, we consider sprites to be the same as the components. We also consider “My Blocks” in Scratch to be identical to “procedures” in App Inventor, as we can define new command blocks with parameters using them. We did not give additional points to procedures that return a value, because unlike procedures, we cannot return values in My Blocks.
We give one point to projects that have more than one script and more than one sprite (component). If My Blocks or procedures are defined in a project, then the project received two points. We give three points to a project in which parameters are defined.
Parallelism is also one of the core concepts in computational thinking. Thus, if a project has multiple scripts (sequences of code blocks) that run at the same time, that project receives a Parallelism score. In Scratch, we can easily execute multiple command blocks in a parallel manner using the same event blocks in the same sprite. Unlike Scratch, App Inventor does not allow the same event blocks on the same screen. Instead, there are a few other ways to achieve interleaving [
24
] in App Inventor, such as the use of Clocks, Image Sprites or Balls: (1) we can easily simulate parallel processing in App Inventor using Clocks because the Timer event of a Clock occurs periodically. (2) Additionally, Image Sprites or Balls on the Canvas move consistently in parallel by default.
First, if two scripts begin at the time a program starts, we give one point to that program. Because a Clock is activated by default when its program starts, an App Inventor project receives one point if a Clock is used in it. By the same token, we assign one point if a Scratch project has two green flags in one sprite. Then, we assign two points to projects for which there could be multiple scripts that run at the same time in the middle of the program execution step. For example, when we touch an image sprite in an App Inventor project, both the “when ImageSprite touched” and the “when Canvas touched” events are invoked simultaneously. In this case, we assign two points to the project. Finally, we give three points to projects for which it is possible that one script will affect the behavior of another script due to their parallel execution.
Logical Thinking. The term “Logical Thinking” is closely related to conditionals and logic operators. Thus, we assign one point for projects that have “if” statements and two points for those that have “if–else” statements. If any of the logic operations (and/or/not) are used in a project, we assign three points to that project. Note we only consider explicit conditionals. For example, the GetValue command block of the TinyDB component has the “valueIfTagNotThere” parameter. We use this parameter value if the data that we want to find does not exist. Although this block implicitly exploits the concepts of the “if–else” statement, we do not assign two points for these cases because we are not certain as to whether the code writer intended to use the “else” statement.
Synchronization involves changing the flow of the execution by different scripts, time, or the like. We assign one point to projects that have code blocks for intentionally delaying the execution. We assign two points to the projects that may involve a scene change. Finally, we assign three points to projects that have at least one callback function. While App Inventor has 40 types of callback functions (as of August 2019), Scratch does not support the callback functions. The “Broadcast and wait” block in Scratch is similar to the callback functions in App Inventor. Thus, we assign three points if that block is used at least once. For example,
Figure 2
shows a comparison of the callback functions used in Scratch and App Inventor; a sprite says “Cheese!” after another sprite says “No Problem!” (on the left side of the
Figure 2
), and the background image changes after we take a picture (on the right side of the
Figure 2
).
Flow Control. This type of computational thinking concept is closely related to loops. We assign one point to projects that have a sequence of blocks because loops can be simulated by just repeating the statements. We give two points to projects that have simple loops, such as “Repeat,” “Forever” or “For each number from, to, by.” We ignore certain exceptional cases for the sake of simplicity; for example, some Scratch projects have numerous duplicate codes instead of loops, as a “Repeat” block slows down the execution time if Turbo Mode is not used. As another example, some App Inventor projects implement loops using the Clock component and variables. Finally, we assign three points to projects that have more advanced loop blocks.
User Interactivity. Obviously, User Interactivity is strongly related to events. While Scratch has seven types of event blocks, App Inventor has 204 types of event blocks. Thus, we decided to assign three points to projects that have more than four distinct user events. If there are three or four distinct user events, the project receives two points. A project receives one point if it has only one or two distinct user events.
Data Representation. Data are usually represented in terms of properties, variables or lists. We assign one point to projects that contain at least one block that modifies their properties. If projects define and use variables, then assign them two points. Note some App Inventor programs use the properties of components (mainly Text Labels) to represent variables. We decided to not assign two points to those projects if the variables are not explicitly defined for the sake of simplicity. Finally, if there is a user-defined list in a project, then we assign three points to that project.
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.
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.
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.
Keywords searched by users: mit app inventor and arduino
Categories: Phát hiện thấy 34 Mit App Inventor And Arduino
See more here: kientrucannam.vn
See more: https://kientrucannam.vn/vn/