Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Barometer for Altitude
📖 Scenario: You are programming a drone that uses a barometer sensor to measure altitude. The barometer gives pressure readings, and you want to convert these readings into altitude values to help the drone fly safely.
🎯 Goal: Build a simple program that stores pressure readings, sets a baseline pressure, calculates altitude from each reading using a formula, and then prints the altitude values.
📋 What You'll Learn
Create a list called pressure_readings with exact pressure values
Create a variable called baseline_pressure with a specific value
Use a list comprehension to calculate altitude values from pressure readings
Print the list of altitude values
💡 Why This Matters
🌍 Real World
Drones use barometer sensors to measure altitude for safe flying and navigation.
💼 Career
Understanding sensor data processing and simple formulas is important for drone programming and robotics jobs.
Progress0 / 4 steps
1
Create pressure readings list
Create a list called pressure_readings with these exact values: 1013.25, 1000.00, 990.00, 980.00, 970.00
Drone Programming
Hint
Use square brackets [] to create a list and separate values with commas.
2
Set baseline pressure
Create a variable called baseline_pressure and set it to 1013.25 (standard sea level pressure in hPa).
Drone Programming
Hint
Just assign the number 1013.25 to the variable baseline_pressure.
3
Calculate altitude from pressure
Use a list comprehension to create a list called altitudes. Calculate altitude for each pressure reading using the formula: altitude = 44330 * (1 - (pressure / baseline_pressure) ** 0.1903). Use pressure as the variable inside the comprehension.
Drone Programming
Hint
Use the formula exactly and write a list comprehension with for pressure in pressure_readings.
4
Print altitude values
Write a print statement to display the altitudes list.
Drone Programming
Hint
Just print the variable altitudes to see the list of altitude values.
Practice
(1/5)
1. What does a barometer measure to help a drone find its altitude?
easy
A. Battery level
B. Temperature
C. Wind speed
D. Air pressure
Solution
Step 1: Understand barometer function
A barometer measures air pressure, which changes with altitude.
Step 2: Connect air pressure to altitude
Lower air pressure means higher altitude, so drones use this to estimate height.
Final Answer:
Air pressure -> Option D
Quick Check:
Barometer = Air pressure [OK]
Hint: Barometer always measures air pressure, not temperature or speed [OK]
Common Mistakes:
Confusing barometer with thermometer
Thinking it measures wind speed
Assuming it measures GPS signals
2. Which of the following is the correct way to read a barometer sensor value in drone code?
easy
A. altitude = barometer.readAltitude()
B. pressure = barometer.getTemperature()
C. pressure = barometer.readPressure()
D. altitude = barometer.getSpeed()
Solution
Step 1: Identify correct method for pressure reading
The method readPressure() is used to get air pressure from the barometer.
Step 2: Check other options for correctness
getTemperature() reads temperature, readAltitude() may not exist, and getSpeed() is unrelated.
Final Answer:
pressure = barometer.readPressure() -> Option C
Quick Check:
Read pressure with readPressure() [OK]
Hint: Pressure reading uses readPressure(), not temperature or speed [OK]
B. Pressure should be divided by 100000, not 101325
C. Missing parentheses around pressure division
D. Altitude formula should multiply by pressure, not subtract
Solution
Step 1: Check the exponent value in formula
The correct exponent in the barometric formula is approximately 0.1903, not 1.903.
Step 2: Understand impact of wrong exponent
Using 1.903 will give incorrect altitude values, making the calculation invalid.
Final Answer:
Exponent should be 0.1903, not 1.903 -> Option A
Quick Check:
Exponent = 0.1903 for altitude formula [OK]
Hint: Check exponent carefully; 0.1903 is standard for altitude [OK]
Common Mistakes:
Typing 1.903 instead of 0.1903
Changing pressure divisor incorrectly
Misplacing parentheses
5. You want to estimate altitude using a barometer when GPS is unavailable. Which approach correctly converts pressure to altitude in your drone program?