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 A0.% If this produces an error, check the COM port number. if not(exist('a')) a=arduino; end N=1000; %number of data points figure; %open a figure window t=zeros(1,N); %preallocated memory for time array B=zeros(1,N); %preallocated memory for B-field array p=animatedline; %create plot xlabel('time(s)'); %plot axis label ylabel('Magnetic Field(G)'); %plot axis label Bbaseline = a.readVoltage("A0"); %Read baseline B field for comparison t0=cputime; %initial CPU time %loop to acquire real-time B-field for N iterations for i=1:N t(i)=cputime-t0; %update current time B(i)=(a.readVoltage("A0")-Bbaseline)/0.0014; %update B-field array addpoints(p, t(i),B(i)); %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 a=arduino line and the a.readVoltage line. That voltage will not, however, be calibrated in magnetic field units. According to the datasheet for the sensor, the sensor's voltage varies by 1.4mV per gauss (G) of magnetic field. The B(i) 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 component(when 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. 1. 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 5V and AO (analog output) to A0 or any other analog pin that you want to connect it to (so long as the code expects data from that pin).2. Using the code above (as an m-file 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). Q3: What is the highest level in gauss (G)? Q4: What is the lowest? Q5: Are they roughly equal and opposite? HINT: Use max or min once you have a B array. 3. 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 1cm,2cm,5cm,10cm,15cm,20cm, and find the field strength at each of those locations. To measure the field in gauss, you can just use B=a.readVoltage("A0")/0.0014; rather than using the code above. Please plot the field strength (y-axis) 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. Q6: What is the power that best fits the data in the plot? Q7: 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? Q8: 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!