Python6 tutorials

Sensors & Modules with Python

Read and process sensor data in Python — distance, line, light, and analog inputs.

Distance Sensor in Python

IntermediatePython

Read the HC-SR04 ultrasonic sensor with `pybot.distance()`, display the live reading on the OLED, and apply a threshold to trigger a LED and buzzer alert.

DistanceHC-SR04SensorOLEDIntermediate

Line Sensor in Python

IntermediatePython

Read the left and right TCRT5000 line sensors using `pybot.line_left()` and `pybot.line_right()`. Combine boolean readings to detect where a dark line is relative to the robot.

Line SensorTCRT5000BooleanSensorIntermediate

Light Sensor in Python

IntermediatePython

Read the PT19 phototransistor with `pybot.light()` and map the 0–100 value to LED brightness. Watch the LEDs respond in real time as the room lighting changes.

Light SensorPT19ADCMappingLEDIntermediate

Analog Reads with ADC

IntermediatePython

Go beyond the named sensor functions and read raw ADC values from any GPIO pin. Use MicroPython's `machine.ADC` to read the trimpot on GP27 and scale the result to a 0–100 range — the same way `pybot.light()` works under the hood.

ADCAnalogTrimpotSensorIntermediate

Sensor Thresholds and Alerts

AdvancedPython

Combine multiple sensors in one program. Read distance and light level, apply compound conditions, and trigger different buzzer alerts depending on which threshold is crossed. The full data → decision → action pattern.

DistanceLight SensorMulti-sensorThresholdsBuzzerAdvanced

Temperature & Humidity in Python

IntermediatePython

Read the SHT40 sensor with `pybot.temperature()` and `pybot.humidity()` and display both values live on the OLED. Then add a heat alert that lights the RED LED whenever the temperature crosses a threshold.

SHT40TemperatureHumiditySensorOLEDIntermediate