Sensors

Topic

Sensors

Topic Progress:

Sensors are part of the invisible components of your application. This means they will not display when running the application. 

By adding them, you enable your application to use your phone’s sensors, such as the accelerometer, gyroscope, and the magnetometer.

Sadly, this lesson is using a Gyroscope, so if you don’t have a phone, tablet, or other device which screen is able to rotate, then you probably won’t be able to complete this lesson. Talk to your tutor about skipping this lesson if this affects you!

Feel free to add some layout blocks  to help format the following elements

Go ahead and drag a Gyroscope component from the sensors section into your application. 

Now add 3 labels to your application, which you can find in the user interface tabs, which we will be using to display the gyroscope readings. 

Remember to name these properly! It will help us work out what to target with our blocks later!

As we will be using these later to display the sensor readings, some good names could be “Sensor X Label”, “Sensor Y Label” and “Sensor Z Label”.

If you want, you can add some extra labels between each of these sensor labels to help understand what the sensor labels are displaying.

You should now have something resembling the image below in your design window.

We’re now going to start coding the application.

Navigate to the blocks tab and find the gyroscope code blocks near the bottom of the blocks menu and drag over “when gyroscope changes”

Now find and drag your sensor labels “set Text” from the label blocks and attach a relevant gyroscope variable block. In this lesson we will be using the “in gyroscope call alpha, beta, gamma” blocks.

The completed block can be seen below

This block is sufficient for displaying the gyroscopes readings. Start up the Thunkable Live on your preferred device and test your new project.

If you’re having trouble rotating your device to see the sensors without the app rotating, you can set the screen to be portrait only.

This lessons Thunkable code can be found at https://x.thunkable.com/projectPage/5e9e8abb63024a1ce31d6d9b

Feel free to play around with more of these sensors and the associated command blocks that come with them.

You can find in-depth information on each sensor at https://docs.thunkable.com/sensors

@

Not recently active