Integrating External Sensors with SPIKE Prime: Expand Your Robot's Capabilities
Supporting Free Content
When you purchase through our links, we earn a small commission at no extra cost to you. As an Amazon Associate and eBay Partner, this helps us keep bringing you expert LEGO® reviews and guides. Thank you for your support!
Integrating External Sensors with SPIKE Prime: Expand Your Robot's Capabilities
Want to take your LEGO SPIKE Prime robots to the next level? Integrating external sensors opens up a world of possibilities, allowing your creations to interact with their environment in sophisticated ways. This comprehensive guide provides tested code examples, wiring diagrams, and troubleshooting tips to help you seamlessly connect and utilize third-party sensors with your SPIKE Prime hub. From ultrasonic distance measurement to temperature sensing and beyond, we'll explore how to expand your robot's capabilities and conquer any challenge.
Why Integrate External Sensors with SPIKE Prime?
The LEGO Education SPIKE Prime system is a fantastic platform for learning about robotics and programming. However, the built-in sensors and those available in the expansion packs, like the SPIKE Prime Expansion Set (v2) (45681), while useful, can sometimes be limiting. Integrating external sensors provides several key advantages:
- Expanded Functionality: Access a wider range of sensor types (e.g., gas sensors, pressure sensors, high-precision temperature sensors) that aren't available from LEGO directly.
- Improved Performance: Obtain higher accuracy, faster response times, or greater sensing ranges compared to standard LEGO sensors.
- Cost-Effectiveness: In some cases, third-party sensors can offer comparable performance at a lower cost.
- Customization: Tailor your robot's sensing capabilities to specific tasks and challenges, such as those encountered in FIRST LEGO League (FLL) or World Robot Olympiad (WRO) competitions.
- Educational Opportunities: Learn about different sensor technologies, communication protocols (e.g., I2C, SPI, OneWire), and signal processing techniques.
By integrating external sensors, you can transform your SPIKE Prime robots into truly versatile and capable machines. Find the perfect set to get you started with robotics: LEGO SPIKE Prime.
Understanding Compatibility and Safety
Before diving into specific sensors, it's crucial to understand the compatibility and safety considerations when interfacing external hardware with the SPIKE Prime hub. The SPIKE Prime hub operates at 3.3V logic levels. Never directly connect 5V sensors or components to the SPIKE Prime hub, as this can damage the hub.
Here are some key points to keep in mind:
- Voltage Levels: Ensure that the sensor's operating voltage is compatible with the SPIKE Prime hub's 3.3V logic. If the sensor operates at 5V, you'll need to use a voltage divider or a level shifter to safely interface it with the hub.
- Current Draw: Check the sensor's current requirements and ensure that the SPIKE Prime hub can supply enough current. Exceeding the hub's current limits can cause it to malfunction or become damaged.
- Communication Protocols: Understand the communication protocol used by the sensor (e.g., I2C, SPI, analog, digital) and ensure that you can implement the corresponding communication protocol in your Python code.
- Wiring: Use appropriate wiring and connectors to ensure a secure and reliable connection between the sensor and the SPIKE Prime hub.
Voltage Dividers and Level Shifters
When interfacing 5V sensors with the 3.3V SPIKE Prime hub, you'll typically need to use a voltage divider or a level shifter to reduce the voltage levels. A voltage divider is a simple circuit consisting of two resistors that divide the voltage proportionally. A level shifter is a more sophisticated circuit that converts voltage levels without attenuating the signal.
Here's how to create a voltage divider:
- Choose two resistors, R1 and R2, such that the desired output voltage (Vout) is 3.3V when the input voltage (Vin) is 5V. The formula for calculating the output voltage is: Vout = Vin * (R2 / (R1 + R2)).
- Select resistor values that satisfy the equation. For example, you could use R1 = 10kΩ and R2 = 20kΩ.
- Connect the resistors in series between the 5V supply and ground.
- Connect the sensor's output to the junction between R1 and R2.
- Connect the junction between R1 and R2 to a SPIKE Prime input pin.
Example Voltage Divider Circuit:
5V ---[R1 = 10kΩ]--- Junction ---[R2 = 20kΩ]--- Ground
Sensor Output --> Junction --> SPIKE Prime Input Pin
Level shifters, such as the TXS0108E, are bidirectional and work well for I2C and SPI communication. These are recommended for reliability. You can find voltage dividers and level shifters at Electronics Components.
Interfacing with Analog Sensors: Photoresistors
Photoresistors, also known as light-dependent resistors (LDRs), are simple analog sensors whose resistance varies depending on the amount of light shining on them. They are useful for detecting changes in ambient light levels, creating light-following robots, or building simple light-activated switches.
Wiring Diagram
To interface a photoresistor with the SPIKE Prime hub, you'll need to create a voltage divider circuit. Connect the photoresistor in series with a fixed resistor (e.g., 10kΩ) between the 3.3V supply and ground. Connect the junction between the photoresistor and the fixed resistor to an analog input pin on the SPIKE Prime hub.
Wiring:
- Photoresistor Pin 1: Connected to 3.3V
- Photoresistor Pin 2: Connected to one end of the 10kΩ resistor
- Other end of the 10kΩ resistor: Connected to Ground
- Junction between Photoresistor Pin 2 and 10kΩ resistor: Connected to a SPIKE Prime analog input pin (e.g., Port A, Pin 1)
Code Example
Here's a Python code example that reads the analog voltage from the photoresistor and prints the value to the console:
from spike import PrimeHub, LightMatrix
import hub
import time
hub = PrimeHub()
# Define the analog input pin
PHOTO_RESISTOR_PIN = 'P0' # Example, change if needed. Must be P0-P3
# Function to read the analog voltage
def read_light_level():
return hub.port.P0.get() # Returns an integer between 0 and 1023
# Main loop
while True:
light_level = read_light_level()
print("Light Level:", light_level)
time.sleep(0.1)
This code uses the hub.port.P0.get() function to read the analog voltage from the specified pin. The value returned is an integer between 0 and 1023, representing the voltage level.
Calibration and Conversion to Lux
The raw analog value from the photoresistor is not directly proportional to the light intensity in lux. To convert the analog value to lux, you'll need to calibrate the sensor and create a conversion formula. Here's a general approach:
- Measure the analog value at different light levels: Use a calibrated lux meter to measure the light intensity at several different locations. At each location, record the analog value from the photoresistor.
- Plot the data: Plot the analog values against the corresponding lux values.
- Fit a curve to the data: Find a mathematical function that best fits the data. A simple power law function (lux = a * analog_value^b) is often a good starting point.
- Determine the coefficients: Use a curve-fitting algorithm or a spreadsheet program to determine the values of the coefficients (a and b) that minimize the error between the fitted curve and the measured data.
- Implement the conversion formula in your code: Use the determined coefficients to convert the analog values to lux in your Python code.
Example Conversion:
Let's assume you've calibrated your photoresistor and determined the following conversion formula:
lux = 10 * (light_level ** -1.5)
You can then modify the code to include this conversion:
from spike import PrimeHub, LightMatrix
import hub
import time
hub = PrimeHub()
# Define the analog input pin
PHOTO_RESISTOR_PIN = 'P0' # Example, change if needed. Must be P0-P3
# Calibration constants (replace with your own values)
A = 10.0
B = -1.5
# Function to read the analog voltage
def read_light_level():
return hub.port.P0.get() # Returns an integer between 0 and 1023
# Function to convert analog value to lux
def analog_to_lux(analog_value):
# Avoid division by zero
if analog_value == 0:
return 0.0
return A * (analog_value ** B)
# Main loop
while True:
light_level = read_light_level()
lux_value = analog_to_lux(light_level)
print("Light Level:", light_level, "Lux:", lux_value)
time.sleep(0.1)
Troubleshooting:
- If the analog value is always 0 or 1023, check the wiring and ensure that the photoresistor and fixed resistor are properly connected.
- If the analog value is noisy or unstable, try adding a small capacitor (e.g., 0.1µF) in parallel with the fixed resistor to filter out noise.
You can use the photoresistor output to control motors, such as those found in the SPIKE Prime Expansion Set (45680), to create light-seeking robots. Find photoresistors for your project at Photoresistors.
Ultrasonic Distance Sensor (HC-SR04)
The HC-SR04 ultrasonic distance sensor is a popular and inexpensive sensor for measuring distances to objects. It works by emitting a short burst of ultrasound and measuring the time it takes for the sound to bounce back from the object. This time is then used to calculate the distance to the object.
Important Note: The HC-SR04 typically operates at 5V. You MUST use a voltage divider on the Echo pin to protect the SPIKE Prime.
Wiring Diagram
The HC-SR04 has four pins: VCC, Trig, Echo, and GND. Connect the pins as follows:
- VCC: Connect to a 5V power supply (not from the SPIKE Prime hub).
- GND: Connect to ground.
- Trig: Connect to a digital output pin on the SPIKE Prime hub (e.g., Port A, Pin 1).
- Echo: Connect to a voltage divider (as described above) and then to a digital input pin on the SPIKE Prime hub (e.g., Port A, Pin 2). Use a 1kΩ and 2kΩ resistor to divide the 5V signal to approximately 3.3V.
Wiring:
- HC-SR04 VCC: Connect to 5V power supply
- HC-SR04 GND: Connect to Ground
- HC-SR04 Trig: Connect to SPIKE Prime digital output pin (e.g., Port A, Pin 1)
- HC-SR04 Echo: Connect to 1kΩ resistor. Other end of 1kΩ resistor connects to SPIKE Prime digital input pin (e.g., Port A, Pin 2). Connect 2kΩ resistor from the SPIKE Prime digital input pin to Ground.
Code Example
Here's a Python code example that uses the HC-SR04 to measure the distance to an object:
from spike import PrimeHub, LightMatrix
import hub
import time
hub = PrimeHub()
# Define the trigger and echo pins
TRIG_PIN = 'P0' # Example, change if needed
ECHO_PIN = 'P1' # Example, change if needed
# Speed of sound in air (cm/s)
SPEED_OF_SOUND = 34300
# Function to measure the distance in centimeters
def measure_distance():
# Send a 10us pulse to the trigger pin
hub.port.P0.mode(hub.port.MODE_OUTPUT)
hub.port.P0.digital(1)
time.sleep(0.00001)
hub.port.P0.digital(0)
# Measure the duration of the echo pulse
hub.port.P1.mode(hub.port.MODE_INPUT)
start_time = time.ticks_us()
while hub.port.P1.digital() == 0 and time.ticks_diff(time.ticks_us(), start_time) < 100000: # Timeout of 100ms
pass
pulse_start = time.ticks_us()
while hub.port.P1.digital() == 1 and time.ticks_diff(time.ticks_us(), pulse_start) < 100000: # Timeout of 100ms
pass
pulse_end = time.ticks_us()
pulse_duration = time.ticks_diff(pulse_end, pulse_start)
# Calculate the distance
distance = (pulse_duration * SPEED_OF_SOUND) / 20000 # Divide by 2 for round trip, convert us to s, cm/s to cm
return distance
# Main loop
while True:
distance = measure_distance()
print("Distance:", distance, "cm")
time.sleep(0.1)
This code first sends a short pulse to the trigger pin to initiate the ultrasonic burst. It then measures the duration of the echo pulse using the time.ticks_us() function. Finally, it calculates the distance using the formula: distance = (pulse_duration * speed_of_sound) / 2, where speed_of_sound is the speed of sound in air (approximately 343 m/s).
Error Handling:
The code includes timeout mechanisms to handle cases where the echo pulse is not received. This can happen if the object is too far away, the sensor is not properly aligned, or there is an obstacle blocking the sound wave.
# Measure the duration of the echo pulse
hub.port.P1.mode(hub.port.MODE_INPUT)
start_time = time.ticks_us()
while hub.port.P1.digital() == 0 and time.ticks_diff(time.ticks_us(), start_time) < 100000: # Timeout of 100ms
pass
pulse_start = time.ticks_us()
while hub.port.P1.digital() == 1 and time.ticks_diff(time.ticks_us(), pulse_start) < 100000: # Timeout of 100ms
pass
pulse_end = time.ticks_us()
pulse_duration = time.ticks_diff(pulse_end, pulse_start)
If either of the while loops times out, it means that the echo pulse was not received. In this case, the pulse_duration will be zero, and the calculated distance will also be zero. You can add error handling to your code to detect these cases and take appropriate action.
Calibration:
The accuracy of the HC-SR04 sensor can be affected by temperature, humidity, and other environmental factors. To improve the accuracy of the sensor, you can calibrate it by measuring the distance to a known object at different distances and adjusting the speed_of_sound constant in the code.
Troubleshooting
- No Readings: Ensure 5V is supplied correctly. Check wiring, especially the voltage divider on the Echo pin.
- Inaccurate Readings: Calibrate the sensor. Ensure the sensor is mounted securely and is not vibrating.
- Intermittent Readings: Check for loose connections. Add a small capacitor (e.g., 0.1µF) across the VCC and GND pins of the HC-SR04 to filter out noise.
The HC-SR04 can be used to create obstacle-avoiding robots, proximity sensors, and other distance-based applications. Consider using the SPIKE Prime (45678) to experiment with robotics. Find HC-SR04 sensors for your project at Ultrasonic Distance Sensors.
MPU6050 IMU (Accelerometer and Gyroscope)
The MPU6050 is a popular inertial measurement unit (IMU) that combines a 3-axis accelerometer and a 3-axis gyroscope in a single chip. It communicates using the I2C protocol, making it relatively easy to interface with the SPIKE Prime hub.
Wiring Diagram
The MPU6050 has several pins, but you only need to connect four pins to the SPIKE Prime hub:
- VCC: Connect to 3.3V (MPU6050 can operate at 3.3V, so no voltage divider needed).
- GND: Connect to ground.
- SCL: Connect to the I2C clock pin on the SPIKE Prime hub (Port A, Pin 1).
- SDA: Connect to the I2C data pin on the SPIKE Prime hub (Port A, Pin 2).
Wiring:
- MPU6050 VCC: Connect to SPIKE Prime 3.3V
- MPU6050 GND: Connect to Ground
- MPU6050 SCL: Connect to SPIKE Prime I2C SCL (e.g., Port A, Pin 1)
- MPU6050 SDA: Connect to SPIKE Prime I2C SDA (e.g., Port A, Pin 2)
Code Example
Here's a Python code example that reads the accelerometer and gyroscope data from the MPU6050:
from spike import PrimeHub, LightMatrix
import hub
import time
import math
hub = PrimeHub()
# MPU6050 I2C address
MPU6050_ADDR = 0x68
# MPU6050 registers
PWR_MGMT_1 = 0x6B
ACCEL_XOUT_H = 0x3B
GYRO_XOUT_H = 0x43
# Function to read a 16-bit value from the MPU6050
def read_i2c_word(register):
high = hub.port.P0.i2c_read(MPU6050_ADDR, register, 1)[0]
low = hub.port.P0.i2c_read(MPU6050_ADDR, register+1, 1)[0]
value = (high << 8) | low
if value >= 32768:
return -((65536 - value))
else:
return value
# Function to initialize the MPU6050
def init_mpu6050():
# Wake up the MPU6050
hub.port.P0.i2c_write(MPU6050_ADDR, PWR_MGMT_1, b'\x00')
time.sleep(0.1)
# Initialize the MPU6050
init_mpu6050()
# Main loop
while True:
# Read accelerometer data
accel_x = read_i2c_word(ACCEL_XOUT_H)
accel_y = read_i2c_word(ACCEL_XOUT_H + 2)
accel_z = read_i2c_word(ACCEL_XOUT_H + 4)
# Read gyroscope data
gyro_x = read_i2c_word(GYRO_XOUT_H)
gyro_y = read_i2c_word(GYRO_XOUT_H + 2)
gyro_z = read_i2c_word(GYRO_XOUT_H + 4)
# Print the data
print("Accel X:", accel_x, "Accel Y:", accel_y, "Accel Z:", accel_z,
"Gyro X:", gyro_x, "Gyro Y:", gyro_y, "Gyro Z:", gyro_z)
time.sleep(0.1)
This code first initializes the MPU6050 by writing to the PWR_MGMT_1 register. It then reads the accelerometer and gyroscope data from the corresponding registers using the hub.port.P0.i2c_read() function. The data is returned as 16-bit signed integers.
Calibration:
The accelerometer and gyroscope data may have some offset errors. To calibrate the sensor, you can measure the average values of the accelerometer and gyroscope data when the sensor is stationary and subtract these offset values from the subsequent readings.
Calculating Tilt Angle using a Complementary Filter:
The accelerometer measures acceleration, including the acceleration due to gravity. By analyzing the accelerometer data, you can estimate the tilt angle of the sensor. However, the accelerometer data can be noisy, especially when the sensor is subjected to vibrations or sudden movements. The gyroscope measures angular velocity, which can be integrated over time to estimate the tilt angle. However, the gyroscope data can drift over time, leading to inaccurate angle estimates. A complementary filter combines the accelerometer and gyroscope data to obtain a more accurate and stable estimate of the tilt angle.
Here's how to implement a complementary filter:
- Calculate the tilt angle from the accelerometer data:
- angle_accel_x = atan2(accel_y, accel_z) * 180 / PI
- angle_accel_y = atan2(-accel_x, sqrt(accel_y * accel_y + accel_z * accel_z)) * 180 / PI
- Calculate the tilt angle from the gyroscope data:
- angle_gyro_x = angle_gyro_x + gyro_x * dt
- angle_gyro_y = angle_gyro_y + gyro_y * dt
- Combine the accelerometer and gyroscope data using a complementary filter:
- angle_x = alpha * angle_gyro_x + (1 - alpha) * angle_accel_x
- angle_y = alpha * angle_gyro_y + (1 - alpha) * angle_accel_y
Here's the Python code to implement the complementary filter:
from spike import PrimeHub, LightMatrix
import hub
import time
import math
hub = PrimeHub()
# MPU6050 I2C address
MPU6050_ADDR = 0x68
# MPU6050 registers
PWR_MGMT_1 = 0x6B
ACCEL_XOUT_H = 0x3B
GYRO_XOUT_H = 0x43
# Filter coefficient
DT = 0.01
# Initial angle estimates
angle_x = 0.0
angle_y = 0.0
# Function to read a 16-bit value from the MPU6050
def read_i2c_word(register):
high = hub.port.P0.i2c_read(MPU6050_ADDR, register, 1)[0]
low = hub.port.P0.i2c_read(MPU6050_ADDR, register+1, 1)[0]
value = (high << 8) | low
if value >= 32768:
return -((65536 - value))
else:
return value
# Function to initialize the MPU6050
def init_mpu6050():
# Wake up the MPU6050
hub.port.P0.i2c_write(MPU6050_ADDR, PWR_MGMT_1, b'\x00')
time.sleep(0.1)
# Initialize the MPU6050
init_mpu6050()
# Main loop
while True:
# Read accelerometer data
accel_x = read_i2c_word(ACCEL_XOUT_H)
accel_y = read_i2c_word(ACCEL_XOUT_H + 2)
accel_z = read_i2c_word(ACCEL_XOUT_H + 4)
# Read gyroscope data
gyro_x = read_i2c_word(GYRO_XOUT_H)
gyro_y = read_i2c_word(GYRO_XOUT_H + 2)
gyro_z = read_i2c_word(GYRO_XOUT_H + 4)
# Calculate tilt angle from accelerometer data
angle_accel_x = math.atan2(accel_y, accel_z) * 180 / math.pi
angle_accel_y = math.atan2(-accel_x, math.sqrt(accel_y * accel_y + accel_z * accel_z)) * 180 / math.pi
# Calculate tilt angle from gyroscope data
angle_gyro_x += gyro_x * DT
angle_gyro_y += gyro_y * DT
# Combine accelerometer and gyroscope data using a complementary filter
angle_x = ALPHA * angle_gyro_x + (1 - ALPHA) * angle_accel_x
angle_y = ALPHA * angle_gyro_y + (1 - ALPHA) * angle_accel_y
# Print the data
print("Angle X:", angle_x, "Angle Y:", angle_y)
time.sleep(DT)
Troubleshooting:
- No Readings: Check the I2C wiring. Verify that the MPU6050 is powered correctly (3.3V).
- Inaccurate Readings: Calibrate the sensor to remove offset errors. Ensure the sensor is not subjected to excessive vibrations.
- Drifting Angle Estimates: Adjust the filter coefficient (ALPHA) in the complementary filter.
The MPU6050 can be used to create self-balancing robots, motion-controlled devices, and other applications that require orientation sensing. The Robot Inventor (51515) can be modified using the MPU6050 to enhance its balancing capabilities. Find MPU6050 sensors for your project at IMU Sensors.
DS18B20 Temperature Sensor (OneWire)
The DS18B20 is a digital temperature sensor that communicates using the OneWire protocol. This protocol allows multiple devices to be connected to the same data line, making it convenient for building sensor networks.
Wiring Diagram
The DS18B20 has three pins:
- VCC: Connect to 3.3V.
- GND: Connect to ground.
- DQ: Connect to a digital input/output pin on the SPIKE Prime hub (e.g., Port A, Pin 1). A 4.7kΩ pull-up resistor is required between the DQ pin and VCC.
Wiring:
- DS18B20 VCC: Connect to SPIKE Prime 3.3V
- DS18B20 GND: Connect to Ground
- DS18B20 DQ: Connect to SPIKE Prime digital I/O pin (e.g., Port A, Pin 1). Connect 4.7kΩ resistor between DQ pin and 3.3V.
Code Example
Here's a Python code example that reads the temperature from the DS18B20:
from spike import PrimeHub, LightMatrix
import hub
import time
hub = PrimeHub()
# Define the data pin
DATA_PIN = 'P0' # Example, change if needed
# OneWire commands
OW_RESET = 0xF0
OW_READ_ROM = 0x33
OW_MATCH_ROM = 0x55
OW_CONVERT_T = 0x44
OW_READ_SCRATCHPAD = 0xBE
# DS18B20 ROM code (replace with your sensor's ROM code)
DS18B20_ROM = b'\x28\x3B\x92\x42\x05\x00\x00\x84' # Example - replace with your sensor's ROM
# Function to perform a OneWire reset
def ow_reset():
hub.port.P0.mode(hub.port.MODE_OUTPUT)
hub.port.P0.digital(0)
time.sleep(0.0005) # 500us
hub.port.P0.mode(hub.port.MODE_INPUT)
time.sleep(0.00006) # 60us
presence = hub.port.P0.digital()
time.sleep(0.00048) # 480us
return presence == 0
# Function to write a bit to the OneWire bus
def ow_write_bit(bit):
hub.port.P0.mode(hub.port.MODE_OUTPUT)
hub.port.P0.digital(0)
time.sleep(0.000005) # 5us
if bit:
hub.port.P0.mode(hub.port.MODE_INPUT)
time.sleep(0.00006) # 60us
hub.port.P0.mode(hub.port.MODE_INPUT)
# Function to read a bit from the OneWire bus
def ow_read_bit():
hub.port.P0.mode(hub.port.MODE_OUTPUT)
hub.port.P0.digital(0)
time.sleep(0.000002) # 2us
hub.port.P0.mode(hub.port.MODE_INPUT)
time.sleep(0.00001) # 10us
bit = hub.port.P0.digital()
time.sleep(0.00005) # 50us
return bit
# Function to write a byte to the OneWire bus
def ow_write_byte(byte):
for i in range(8):
ow_write_bit(byte & 1)
byte >>= 1
# Function to read a byte from the OneWire bus
def ow_read_byte():
byte = 0
for i in range(8):
bit = ow_read_bit()
byte |= bit << i
return byte
# Function to read the temperature from the DS18B20
def read_temperature():
# Reset the OneWire bus
if not ow_reset():
print("OneWire reset failed")
return None
# Select the DS18B20
ow_write_byte(OW_MATCH_ROM)
for byte in DS18B20_ROM:
ow_write_byte(byte)
# Start temperature conversion
ow_write_byte(OW_CONVERT_T)
time.sleep(0.75) # Wait for conversion to complete
# Reset the OneWire bus
if not ow_reset():
print("OneWire reset failed")
return None
# Select the DS18B20
ow_write_byte(OW_MATCH_ROM)
for byte in DS18B20_ROM:
ow_write_byte(byte)
# Read the scratchpad
ow_write_byte(OW_READ_SCRATCHPAD)
scratchpad = []
for i in range(9):
scratchpad.append(ow_read_byte())
# Extract the temperature from the scratchpad
temp_lsb = scratchpad[0]
temp_msb = scratchpad[1]
temperature = (temp_msb << 8) | temp_lsb
temperature = temperature * 0.0625
return temperature
# Main loop
while True:
temperature = read_temperature()
if temperature is not None:
print("Temperature:", temperature, "°C")
time.sleep(1)
This code implements the OneWire protocol to communicate with the DS18B20 sensor. It first performs a reset to synchronize with the sensor. It then sends the "Convert T" command to initiate a temperature conversion. After waiting for the conversion to complete, it reads the scratchpad from the sensor and extracts the temperature value.
Important: You need to replace the DS18B20ROM variable with the actual ROM code of your DS18B20 sensor. You can use the OWREAD_ROM command to read the ROM code from the sensor
Use Our Tools to Go Further
Get more insights about the sets mentioned in this article with our free LEGO tools