Question: Am I supposed to move the magnet while this code is running in order to get the proper data? % File to acquire live voltage
Am I supposed to move the magnet while this code is running in order to get the proper data?
File to acquire live voltage data from analog port A If this produces an error, check the COM port number. if notexista aarduino; end N; number of data points figure; open a figure window tzerosN; preallocated memory for time array BzerosN; preallocated memory for Bfield array panimatedline; create plot xlabeltimes; plot axis label ylabelMagnetic FieldG; plot axis label Bbaseline areadVoltageA; Read baseline B field for comparison tcputime; initial CPU time loop to acquire realtime Bfield for N iterations for i:N ticputimet; update current time BiareadVoltageABbaseline; update Bfield array addpointsp tiBi; add latest datum to plot drawnow; draw updated plot end
The code above will allow you to read the magnetic field sensor using MATLAB and get a plot of field strength in real time. All that's really needed to get a reading from the sensor is the aarduino line and the areadVoltage line. That voltage will not, however, be calibrated in magnetic field units. According to the datasheet for the sensor the sensors voltage varies by mV per gauss G of magnetic field. The Bi line of code accounts for that calibration and therefore outputs field strength in gauss. But the sensor needs to know what zero field feels like. The code, therefore, is written with the assumption that the very first reading when you press start is done in zero field, so have the magnet far from the sensor when you press start. If thats done, then every subsequent voltage will be appropriately scaled such that you get the correct field in gauss after that first reading. NOTE: The sensor can only measure a single vector component of the magnetic field. The sensor is oriented so that a downward field componentwhen looking down on the red circuit board will read a positive field component, and therefore upward will read negative. Field that is in the plane perpendicular to that direction will not be detected. Using your mini breadboard and jumper wires, you will connect three of the four pins on the sensor to the Arduino: G to GND to V and AO analog output to A or any other analog pin that you want to connect it to so long as the code expects data from that pin Using the code above as an mfile in MATLAB read the highest and lowest values of magnetic field that you get when you place your magnet nearest the field sensor on your little chip the black protrusion at the top is the sensor Q: What is the highest level in gauss G Q: What is the lowest? Q: Are they roughly equal and opposite? HINT: Use max or min once you have a B array. When you have your sensor working and you understand how it responds, you will construct a curve of field strength versus distance between the magnet and the sensor Please use distances of cmcmcmcmcmcm and find the field strength at each of those locations. To measure the field in gauss, you can just use BareadVoltageA; rather than using the code above. Please plot the field strength yaxis versus distance and fit the data with whatever inverse power of distance works best to fit the data. Keep in mind that the data can have an offset due to a background field. Your fit function needs to account for this background. Q: What is the power that best fits the data in the plot? Q: Based on the textbook reading, how is the field strength of a magnetic dipole like the permanent magnet in the kit supposed to decrease with distance? Q: Does your data seem to match this?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
