Scratch Sensor 2.0
Scratch Sensor 2.0 is an Android smartphone app that enables the Scratch user to read the Android smartphone sensors data in ScratchX. ScratchX has Experimental Extensions which allows Scratch to connect to external hardware or web services. This note is intended for users familiar with Scratch.
If you have updated from Scratch Sensor 1.0, note that Scratch Sensor 2.0 does not work with Scratch 1.4.
Scratch Sensor 2.0 does not work with Scratch 3. ScratchX and Scratch 3 extensions are incompatible.
What are the requirements of Scratch Sensor 2.0?
- works only at ScratchX
- the Android smartphone is now a webserver. So you have to enter the IP address of the smartphone in the Scratch program.
- both the smartphone and the computer running ScratchX must be on the same wifi network
- supports multiple android smartphones
- the update rate is determined by the Android OS
Getting Started
- Install Scratch Sensor 2.0 from the Google Play Store onto your Android phone.
- Press Start. When the server is running, a notification appears in the notification area of your Android phone. Note the IP address. In our example it is 192.168.1.6
- Click start.sbx to load the Getting Started Project in ScratchX. .
- Set the addr variable in the project to the IP address you noted in step 2.
- Run the ScratchX project.
- When you tilt your phone, the tilt variable value is the same as shown on your phone.
- The time the data is accessed from the phone server is also displayed.
- The status of the phone web server is also available.
- You have sucessfully accessed the tilt sensor data from your Android phone. The tilt sensor is a composite sensor derived from the accelerometer sensor.
- Stop the ScratchX project.
- Click Stop on the Scratch Sensor app to stop the server. The notification will disappear.
Sample ScratchX Projects
- Getting Started start.sbx
- Read sensor data from 2 smartphones 2-scratch-sensors.sbx
- Read Position sensor data (Bear video demo) sensor-position.sbx
- Scratch Sensor Mazeball mazeball.sbx
- Bubble Level Meter level-meter.sbx
ScratchX Extension
ScratchX URL
https://emantpl.github.io/scratch-sensor-2.0/scratch_sensor.js
Scratch Sensor App
To turn on/off the server
- Click Start to start the server
- Notification will appear. Tapping on the notification will bring the app to the foreground.
- IP address of the phone will be displayed.
- Click Stop to stop the server. The notification will disappear.
Available Sensors
The app will display the following sensors if they are available in your phone.
- Accelerometer - x,y,z
- Steps - step count
- Tilt - angle of tilt in degrees
- Position - feet, head (phone standing), front, back (phone lying)
- Light - light intensity in lux
- Compass - 0 North 180 South, in degrees
Important Note
Although the app need not be in the foreground, the screen should be left on. The doze mode to extend battery life introduced in Android versions from Marshmallow onwards may turn off the sensors and server.
Support or Contact
Support is via comments below. You may also email us.
Generate sensor data for Human Activity Recognition (HAR)
Human Activity Recognition (HAR) based on wearable sensor data aims to identify a person’s actions, such as standing, sitting, jumping, and going up stairs, by using data from body-worn sensors. Now you can use the Chrome browser on your Android phone to save the sensor data to Google sheets at sensor-cloud.com.