1. Arduino 101
2. Android phone (Must have BLE hardware, but I think it's not a problem for most Android devices today).
3. Grove - Temperature&Humidity Sensor Pro. Special article in this series will be used Grove sensor kit for Arduino kit to produce, because MIT App Inventor also use this as the main teaching kit.
This article's concept is as same as the previous one: [App Inventor IoT ] Lesson 4: 4-axis robotarm. The difference between the two is the read of analog pin. One is Arduino A0 analog pin, and the other is the temperature and humidity sensor readings element. This article will continue to read the temperature and humidity sensors, and displayed on the screen corresponding to the App Inventor Label.Please refer to the following instructions :
App Inventor Designer:
This article only use the label to render temperature and humidity sensor's value, you can add different visual elements or trigger reactionon the phone. For example, through the TextToSpeech element to read out the value or send email automatically, etc. This article uses 3 Clock element, you can refer to this practice, if you have a better ideas, it's very welcome to share with us.
These three Clock elements' parameters are the better after several tests. You may need to adjust these parameters to your actual situation. Depending on the difference protocol, you can't use the BluetoothClient element to communicate with your Arduino 101.
App Inventor Blocks:
1. Connection and Disconnection
When the program is initialized, it requires BluetoothLE1 element scan. Please note that this example is directly connect to the specified Bluetooth device (Arduino 101). If you need to select from a plurality of devices, we suggest you can pair Bluetooth first, and tap in from ListPicker is a better way. Note BLE device didn't need to be paired, only need to direct connection to the specified address. When Button_Connect pressed, it will require BluetoothLE1 element connect to the specified address of bluetooth devices (98: 4F ...), and stop scanning after setting the enabled properties of element.
From the previous step, BluetoothLE 1.connected event will start after a successful connection, we show some confirmation message here.
3. Clock1 (Call once per second): Continuous reading the return value of Arduino 101.
This example uses 3 Clock elements, please see the following instructions:Clock1 according to the variable values of disconnect (true / false) to know whether there is connecting with the specified Arduino 101. If true, it will continue to determine whether there is a connection. If it is in the connection status, it wil be disconnected (BluetoothLE.DisconnectWithAddress), otherwise start scanning (BluetoothLE.StartScanning). If the variable value of disconnect is false, then began the most important combination of variable values, but you need to start Clock2 and Clock3's timer event. And update the variables of the temperature and humidity to the corresponding Label. Nothing to it, right?
4. Clock2(Call once every 0.9 seconds):
Clock2 will put it's timer event and Clock3's timer event closed every 0.9 seconds, and then followed the actual situation to start (that means the variable values of disconnect).
5. Clock3(Call once every 0.005 seconds): Control offset and combined datas
Clock3 will execute BluetoothLE.ReadIntValue instruction first, it's to read an integer from Arduino 101. Then set the variable data to read the results of BluetoothLE.IntGattValue instruction, and if the data is between 99 to 256, it is the humidity value. This value decreased by 100 will become the humidity value we want. On the contrary it is the temperature value. The reason we do, because after we read the results of the temperature and humidity we combined them into a value and then sent to App Inventor. This approach can reduce the loss of data, as in the following program fragment:
Please note that service_uuid and characteristic_uuid should filled in "19B10011-E8F2-537E-4F6C-D104768A1214", Arduino 101 use this parameter to represent the BLE services it provides.
Arduino 101 Code
You just need to copy the draft code and uploaded to the Arduino 101. Please note Arduino 101 has Bluetooth 4.0 that you don't have an external Bluetooth device such as HC05.In this code, you should specify service_uuid and characteristic_uuid, they are "19B10011-E8F2-537E-4F6C-D104768A1214" here.