Display the temperature and light intensity measured by Micro:bit on the smartphone

Bluetooth 23-01-24
236 0

Tutorial plan

How does the Micro:bit card measure temperature and light intensity ?

How does the Micro:bit card send data to the smartphone via Bluetooth?

Program the Micro:bit card with Makecode to send temperature and light intensity to the smartphone

Develop a mobile smartphone application with App Inventor to receive data from the Micro:bit card via Bluetooth

 

How does the Micro:bit card measure temperature and light intensity ?

The BBC micro:bit is a small programmable computer designed for educational purposes, and it includes a few built-in sensors, including a temperature sensor and a light sensor. Here’s how each of these sensors works:

1- Temperature Sensor:

The micro:bit has a built-in temperature sensor that measures the ambient temperature.

The temperature sensor is a silicon-based sensor, and it relies on the fact that the voltage across a silicon diode changes with temperature.

By measuring this voltage change, the micro:bit can estimate the current temperature in degrees Celsius.

2- Light Sensor:

The micro:bit has a built-in light sensor that measures the ambient light intensity.

The light sensor is typically a photodiode or phototransistor, which generates a small electric current when exposed to light.

The micro:bit can measure this current to determine the intensity of the light falling on the sensor.

The light intensity value is often represented in arbitrary units, and it’s a relative measure rather than an absolute one.

Both the temperature and light sensors on the micro:bit can be accessed and utilized in programming through the micro:bit’s coding platform, which allows users to write code in languages such as Python or JavaScript. This makes it easy for students and beginners to create projects that involve monitoring and responding to changes in temperature and light intensity.

How does the Micro:bit card send data to the smartphone via Bluetooth?

The micro:bit uses Bluetooth Low Energy (BLE) for wireless communication with other devices, such as smartphones. Bluetooth Low Energy is a power-efficient version of the classic Bluetooth technology, and it is well-suited for applications where low power consumption is essential, making it ideal for small devices like the micro:bit.

Here’s a brief overview of how the micro:bit sends data to a smartphone via Bluetooth:

1- Bluetooth UART (Universal Asynchronous Receiver-Transmitter):

The micro:bit supports a UART service over Bluetooth. UART is a standard communication protocol used for serial communication between devices.

In the provided MakeCode example, the bluetooth.uartWriteString function is used to send a string over the Bluetooth UART connection.

2- MakeCode Programming:

The MakeCode programming environment for the micro:bit provides a simple and user-friendly way to work with Bluetooth communication.

3- Smartphone App:

On the smartphone side, you can use a Bluetooth terminal app to connect to the micro:bit and receive the data.

A Bluetooth terminal app typically allows you to establish a Bluetooth connection with a device and view the data sent over the UART service.

4- Data Format:

In the provided MakeCode example, the micro:bit sends a string containing the temperature and light intensity data when button A is pressed.

The data is formatted as a string using concatenation (+ operator) and includes labels such as “Temperature:” and “Light Intensity:” to make the information more readable.

To interact with the micro:bit using Bluetooth, you need to ensure that your smartphone has Bluetooth enabled, and you may need to pair/connect to the micro:bit from the Bluetooth settings on your phone. The specific steps may vary depending on the Bluetooth terminal app you are using on your smartphone.

Program the Micro:bit card with Makecode to send temperature and light intensity to the smartphone

To program the micro:bit using MakeCode to send temperature and light intensity data to a smartphone, you can use Bluetooth communication. Here’s a simple example using Microsoft MakeCode:

1- Go to the MakeCode website: https://makecode.microbit.org/

2- Create a new project.

2- Add the Bluetooth extension:

Look for “Extensions” and click on it.

In the search box, type “bluetooth” to find the bluetooth extension.

Now, let’s write the code:

Download program

 

This code continuously reads the temperature and light intensity from the built-in sensors and send a number containing the temperature and light intensity over Bluetooth.

Develop a mobile smartphone application with App Inventor to receive data from the Micro:bit card via Bluetooth

You can create a simple mobile application using MIT App Inventor to receive data from the micro:bit via Bluetooth. Here’s a step-by-step guide:

1. Set Up Your Micro:bit

Ensure that your micro:bit has the Bluetooth UART service enabled. You can use the previously mentioned MakeCode program to send data over Bluetooth. Make sure your micro:bit is powered on and ready.

2. Create a New App in MIT App Inventor

1- Open your web browser and go to MIT App Inventor (http://ai2.appinventor.mit.edu/).

2- Sign in with a Google account.

3- Click on “Start new project” and give your project a name.

3. Design the App UI

Drag and drop the following components from the Palette onto the Viewer:

– 4 buttons for connecting and disconnecting with Micro:bit card

– 3 images Sprite

– 2 labels for displaying the temperature and light level sended from Micro:bit card

Arrange them on the screen as needed.

3- Connect to Bluetooth

Design the user interface of your app. You might have two buttons to turn on and turn off the two lamps

Add the components to your app.

– The “BluetoothLE1” extension indeed refers to a specific extension for MIT App Inventor which allows you to manage Bluetooth Low Energy (BLE) communication in your mobile applications. This extension facilitates the interaction between your App Inventor application and BLE devices, such as sensors, trackers, wearables, etc.

– The “BluetoothClient1” extension in MIT App Inventor allows you to create mobile applications that can connect to Bluetooth devices, such as serial Bluetooth modules (eg HC-06) connected to microcontrollers, Bluetooth audio devices, etc. . This extension facilitates communication with these devices using serial Bluetooth connections.

– The “Microbit_UART1” extension allows you to use UART (Universal Asynchronous Receiver-Transmitter) communication with the Micro:bit card in the MakeCode programming environment.

– The “Notifier1” extension in MIT App Inventor is a component for displaying notifications or messages to the user of an application. It can be used to send pop-up messages, alerts or important information to the user while the application is running. It is a useful component to improve user experience by providing contextual information.

4- Create Blocks for Bluetooth Communication

– Starting with Android 12, Bluetooth permissions have been enhanced to improve security and user data protection. This is why we must declare the authorizations that your application needs in the AndroidManifest.xml file. For Bluetooth, you’ll need to include ACCESS_FINE_LOCATION, BLUETOOTH_SCAN, and possibly BLUETOOTH_CONNECT permissions, depending on the features you’re using.

– Use these programming blocks to connect the smartphone to the Micro:bit board via Bluetooth:

5- Use programming blocks to receive data from Micro:bit card via Bluetooth

Download projectDownload apk file

6. Connect the App to Your Smartphone

Connect your smartphone to the computer, install the MIT AI2 Companion app (available on Google Play for Android or App Store for iOS), and scan the QR code from the MIT App Inventor website to load your app onto the smartphone.

7. Test the App

1- Open the  application on your smartphone.

2- Press the “Connect” button to establish a Bluetooth connection with the micro:bit.

3- The labels should display the temperature and light level received from the micro:bit.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info