Lab 8 Part 1: Sensor Accuracy Evaluation

Compare accuracy of Ultrasonic vs. Laser Ping sensors with data analysis

Learning Goals

  • Develop Blockly Scripts: Create and utilize functions in Blockly for task automation and control.
  • Data Saving Techniques: Learn how to record and save sensor data on an SD card.
  • Sensor Accuracy Comparison: Examine and compare the accuracy of Ultrasonic vs. Laser Ping sensors for distance measurement.
  • Data Analysis in Excel: Practice plotting actual versus measured data and calculating the coefficient of determination (R²) value to evaluate the goodness of fit of the data.

Software and Hardware

  • BlocklyProp Solo
  • Activity Board and Parallax USB programming cable
  • Laser Ping Sensor
  • Ultrasonic Sensor
  • GND -- VIN -- SIG cable
  • SD Card
  • SD Card Reader
  • Ruler or Measuring Tape
  • Excel

SD Card Data Storage

Your ActivityBot board has a built-in card reader that is compatible with our preformatted microSD card. SD cards can give your Propeller microcontroller invention some extra gigabytes of memory to work with.

Built-in card reader for microSD Card

Sensor Connections

Laser Ping Sensor

The Laser PING Rangefinder provides an easy method of distance measurement. This near-infrared, time-of-flight (TOF) sensor is ideal for measuring distances between moving or stationary objects.

  • Identify the Cable: Locate the cable with three pins labeled GND, VIN, and SIG.
  • Connect to Sensor: Attach one end to the Laser Ping Sensor (GND to Ground, VIN to Voltage In, SIG to Signal)
  • Connect to Board: Connect the other end to the Ping socket (pin 15) on the Activity Board.
Laser Ping Sensor Connection

Ultrasonic Sensor

Ultrasonic sensors provide precise, non-contact distance measurements within a 3 cm to 3 m range.

  • Identify the Cable: Locate the cable with three pins labeled GND, VIN, and SIG.
  • Connect to Sensor: Attach one end to the Ultrasonic Sensor
  • Connect to Board: Connect to the General socket (pin 7) on the Activity Board. Adjust jumper caps to 5V and P7.
Ultrasonic Sensor Connection

Programming Assignment

Your script may have a main block and a few functions:

Main Block:

  • Ask users to enter the number of measurements (n_iteration)
  • Set iteration variable to 1
  • Open a CSV file on the SD Card (Data.csv)
  • Create header string: "actual, ping, ultrasonic"
  • Write header to SD card
  • Loop n_iteration times with six functions
  • Close the file after loop completion

Six Functions in Loop:

  • Print_iteration: prints "Measurement XXX out of YYY"
  • Get_actual: gets actual distance from user
  • Read_ping: reads distance from ping sensor
  • Read_ultrasonic: reads distance from ultrasonic sensor
  • Write_data: bundles and saves data to SD card
  • Print_data_to_save: prints data to terminal

Save your code as: Lab8_YourInitials_distance_sensors_accuracy (e.g., Lab8_AM_distance_sensors_accuracy)

Measurement Setup

To accurately measure distances, use a measuring tape or ruler. Measure distances at equal intervals from 10 cm up to 1 meter, in 10 cm increments (10 cm, 20 cm, 30 cm, etc.).

  1. Set up the Measuring Tape: Stretch a measuring tape between the sensor and a stationary object.
  2. Position the Sensors: Start by placing the sensors 10 cm away from the object. After recording the distance, move the sensors back another 10 cm.
  3. Record the Data: Measure and record the distance at each interval using both sensors.
Distance Measurement Setup

Blockly Programming Blocks

SD Card Operations

SD File Open Block Create String Header Block Write Data Block Newline Block Close File Block

Sensor Reading Blocks

Laser Ping Distance Block Ultrasonic Distance Block Convert to String Block

Data Analysis in Excel

  1. Access the Data: Insert SD Card into reader and locate the CSV file
  2. Open Excel File: Three columns - actual distances, Laser Ping measurements, Ultrasonic measurements
  3. Create Scatter Plot: Insert > Recommended Charts > X Y (Scatter)
  4. Add Trendline: Right-click on data points > Add Trendline > Display equation and R-squared value
  5. Analyze R-Squared: Values close to 1 indicate high accuracy
  6. Compare Sensors: Determine which sensor has higher R-squared value
Excel Scatter Plot Example

What to Submit

  1. Code Submission: Save Blockly code as .svg file (50 points)
  2. Data Plots: Two scatter plots with R-squared values (40 points total)
    • Actual vs. Laser Ping distances (20 points)
    • Actual vs. Ultrasonic distances (20 points)
  3. Analysis: Determine which sensor has higher accuracy (10 points)
  4. Bonus Task: Test with different materials (black, white, transparent glass) and discuss material effects (20 points)

Naming: Lab8_YourInitials_distance_sensors_accuracy.svg