Sensors
Light sensor
Light/dark
Checks if a light sensor is detecting light or dark. The block takes two parameters:
- light/dark: Whether the sensor should detect light or dark.
- Pin number: The pin the light sensor is connected to.
The block will output true
if the sensor is detecting the specified condition and false
otherwise.
Raw sensor value
Reads the raw value from a light sensor connected to an analogue pin.
- Pin number: The pin the light sensor is connected to.
Potentiometer on pin
Reads the value from a potentiometer connected to an analogue pin.
Ultrasonic sensor
An ultrasonic sensor measures distance by emitting high-frequency sound waves (typically 40 kHz) and detecting their reflection off objects. The sensor calculates distance based on the time taken for the sound wave to travel to the object and return, using the known speed of sound in air.
The sensor consists of two main components:
- A transmitter (trigger) that emits the ultrasonic pulse
- A receiver (echo) that detects the reflected wave
The distance is calculated using the formula:
The time is divided by 2 because the measured time includes both the outward and return journey of the sound wave.
Add ultrasonic sensor
Sets up an ultrasonic sensor on two pins: one for the trigger and one for the echo.
- trig: The pin connected to the trigger pin.
- echo: The pin connected to the echo pin.
When using an ultrasonic sensor, make sure to attach it before using other ultrasonic sensor blocks.
Ultrasonic sensor distance
Returns the distance measured by the ultrasonic sensor in the specified units.
- units: The units to output the distance in (centimeters or inches).
- sensor: The ultrasonic sensor to read from.
Encoder
An encoder is a sensor that measures rotational motion and position by converting mechanical movement into digital signals. It typically consists of a disk with equally spaced markings that interrupt a light beam as the shaft rotates, generating electrical pulses. The encoder can determine both the amount of rotation (by counting pulses) and the direction of rotation (by comparing the phase of signals from two sensors).
The most common type in robotics is the quadrature encoder, which uses two output channels (signal and direction) offset by 90 degrees. This offset allows the encoder to detect:
- Position: By counting the total number of pulses
- Speed: By measuring the frequency of pulses
- Direction: By comparing which channel leads or lags
Each pulse represents a fixed angular movement, with the resolution determined by the number of markings on the encoder disk. For example, an encoder with 360 markings can measure rotation in 1-degree increments.
In Code Kit, you can use encoders as user input devices or to measure the position of rotating parts, such as wheels on a robot. Properties like speed and direction can be calculated (manually) based on the encoder's output.
Add encoder
Sets up an encoder on two pins: one for the encoder's signal and one for the encoder's direction.
- signal: The pin connected to the encoder's signal.
- direction: The pin connected to the encoder's direction.
When using an encoder, make sure to attach it before using other encoder blocks.
Read encoder
Reads the current value of the encoder.
- encoder: The encoder to read from.
Write encoder value
Sets the value of the encoder. This block is useful for resetting the encoder's position.
- encoder: The encoder to write to.
- value: The value to set the encoder to.
Colour sensor (TCS34725)
The TCS34725 is a digital colour sensor that detects and measures light using an array of photodiodes with different color filters (red, green, blue, and clear). The sensor includes an LED that illuminates the target surface, allowing it to measure both the intensity and spectral composition of reflected light. This enables accurate color detection and light measurement across various lighting conditions.
The sensor can provide:
- RGB colour values
- Brightness levels
- Illuminance (lux)
- Colour temperature (K)
Sense colour
Reads the colour detected by the TCS34725 colour sensor.
Sense brightness
Reads the brightness of the colour detected by the TCS34725 colour sensor.
Sense lux
Reads the lux value of the colour detected by the TCS34725 colour sensor.
Lux is a unit of illuminance that measures the amount of light falling on a surface. It is used to quantify the brightness of light in a specific area.
Sense colour temperature
Reads the colour temperature of the colour detected by the TCS34725 colour sensor.
Colour temperature is a characteristic of visible light that describes its warmth or coolness. It is measured in Kelvin (K), with lower values indicating warmer (redder) light and higher values indicating cooler (bluer) light.
Laser distance sensor (VL53L0X)
The VL53L0X is a Time-of-Flight (ToF) sensor that measures distance using infrared laser light. It emits short pulses of invisible laser light and measures the time taken for the light to reflect off an object and return to the sensor. Using the known speed of light, the sensor calculates precise distances.
Unlike ultrasonic sensors, the VL53L0X:
- Provides more accurate measurements at close range
- Is less affected by surface properties
- Has a narrower detection beam
- Typically measures distances up to 2 meters
Get mm range
Reads the distance measured by the VL53L0X laser distance sensor in millimeters.