Users Manual

SCRATCH CODING KIT
Experiencing
the alligator robot coding
Brightness sensor, volume sensor, and servomotor
Now, we are going to make a code that will control the angle of the servomotor using the brightness and volume
sensors. When the brightness sensor is covered, the mouth should close and when it’s not covered, it has to set a
max angle for the alligator to open its mouth using the volume sensor. Make a script like below!
If you see the script above, the servo motor’s angle will be 150 degree when the value of analog1 sensor is larger
than 80. Analog port 1 is connected with the brightness sensor. Therefore, when the brightness sensor is covered,
it will operate the servo motor at a 150 angle degree.
If the analog1 sensor value is smaller than 80, it says the servomotor will be in at the ‘analog0 sensor value/1.8
rounded’ angle. When the brightness sensor is not covered, you should be able to use the volume sensor to con-
trol the mouth’s angle. But, since we can’t turn the volume sensor more than the angle where the robot can open
its mouth, we have to divide the volume sensor’s analog value with the right number to control the servo motor’s
angle.
The script above divided the volume sensor’s analog value (analog0 sensor value) with 1.8 and rounded it. The
‘rounded’ operator can be found under the calculation tab and makes the calculated value into an integer. 255 is
the largest number of the volume sensor’s analog value, and if we divide it by 1.8, the angle of the closing mouth
will not gog over the servo motor’s angle. The important part is that you don’t always divide it by 1.8. It depends
on the angle you set for the alligator’s closing mouth. It can be 1.7, 1.8, or 2.0. When dividing the volume sensor’s
analog value, make sure you check the angle in which the alligator closes its mouth.
255 ÷ 1.8 = 141.666… rounded
Smaller than the angle in which the
alligator closes its mouth
Set an angle in which the
alligator closes its mouth.
It might differ between
users.