Free-fall and Incline Motion
Setup of hardware and software
Use a search engine and find the Arduino cloud editor. Set up the editor so that it connects to your Arduino R4. Make sure the Modulino library is installed.[br][br]Load this code onto the Arduino R4:[br][br]#include "Modulino.h"[br][br]ModulinoDistance distance;[br][br]void setup() {[br] Serial.begin(115200);[br] [br] // Initialize Modulino system and sensor[br] Modulino.begin();[br] distance.begin();[br]}[br][br]void loop() {[br] // Check if the sensor has a new reading available[br] if (distance.available()) {[br] unsigned long timeMicros = micros();[br] int measure = distance.get(); // Returns distance in mm[br][br] // Send to MATLAB: "Time,Distance"[br] Serial.print(timeMicros);[br] Serial.print(",");[br] Serial.println(measure);[br] }[br]}[br][br][br]You can test that it works by checking in the serial monitor (look in drop-down menus for it) if data is being reported by the sensor. Once it is working, close the Arduino editor so that the connection to the Arduino R4 is available for MATLAB in the next step.
MATLAB code
Once you have the sensor working, open a new MATLAB live script (not a regular m-file). Your lab submission will be this live script, so use a text block to add your name, a title, and today’s date.[br][br]Insert this in a code block: [br]% MATLAB Real-Time Plotting Script[br]clear; clc;[br][br]% --- Configuration ---[br]port = "COM3"; % Update this to your Arduino's COM port[br]baudRate = 115200;[br]s = serialport(port, baudRate);[br]flush(s);[br][br]% Prepare Figure[br]fig = figure('Name', 'Real-Time Sensor Data', 'KeyPressFcn', @(src, event)setappdata(src, 'stop', true));[br]setappdata(fig, 'stop', false);[br]h = animatedline('Color', 'b', 'LineWidth', 1.5);[br]grid on;[br]xlabel('Time (Seconds)');[br]ylabel('Position/Sensor Value');[br]title('Press SPACEBAR in the figure window to stop');[br][br]% --- Data Acquisition Loop ---[br]startTime = []; [br][br]while ~getappdata(fig, 'stop')[br] % Read the latest line from Serial[br] dataStr = readline(s);[br] [br] if ~isempty(dataStr)[br] % Parse the comma-separated string[br] nums = str2double(split(dataStr, ','));[br] [br] if numel(nums) == 2[br] rawMicros = nums(1);[br] sensorVal = nums(2);[br] [br] % Initialize startTime on the first valid read[br] if isempty(startTime)[br] startTime = rawMicros;[br] end[br] [br] % Convert microseconds to elapsed seconds[br] elapsedSecs = (rawMicros - startTime) / 1e6;[br] [br] % Update Plot[br] addpoints(h, elapsedSecs, sensorVal);[br] [br] drawnow limitrate; [br] end[br] end[br]end[br][br]fprintf('Data acquisition stopped by user.\n');[br]clear s; % Release the serial port
Data Acquisition
Use the sensor and steel ball in lab to measure free-fall motion. When you have what looks like a clean data run, it’ll be analyzed in order to extract ‘g’.
Data Analysis
Your data is position vs time. Take this data and decide how you need to analyze it in order to extract the value of acceleration (assumed constant) for the falling motion. Once you have what you think is a good idea, call me over so I can verify. You will be using a curve fit to most easily extract the acceleration data. [br][br]Perform that curve fit and include the plot with the data and curve fit in the lab. The parameters are reported with error margins. Use that data to report ‘g’ to the precision allowed by the fitting parameters and associated error. MAKE SURE YOU ONLY FIT THE RELEVANT PART OF THE CURVE. This is easiest to do in the curve fit app. If you do it that way, you have to export that plot for use in your live script.[br][br]
Incline Motion
Use the sensor in the same way to measure the acceleration of a car both up and down a ramp. It is possible to work out two things with only the acceleration data (for up and down the ramp separately): The slope and the friction coefficient. YOU DO NOT NEED TO MEASURE EITHER ONE. The math will tell you both of them with only an acceleration value on the way up the track and a slightly different acceleration down the track. [br][br]So your agenda is the following: Give the car a brief push (or use the rubber band) so that it rolls most of the way up the track, stops on its own, and rolls back down. Measure that whole trip with the sensor.[br][br]Then extract the values of acceleration up and acceleration down the track and record them. [br][br]Then use them to find the slope and the friction coefficient of the car/track system. Report these as well with error. Error will come from the fact that the accelerations you’re using have error bars. So, just do three calculations - one that uses the mean values, one that makes friction and slope as big as possible, and one that makes them as small as possible. If that leads to slope, for instance, of 15.2 degrees, 14.8 degrees, and 15.5 degrees, report it as 15.2 (+0.3/-0.4) degrees.[br][br]Do the same with the friction coefficient.