Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB Code to Read Magnetic Field Sensor % File to acquire live voltage data from analog port A 0 . % If this produces an

MATLAB Code to Read Magnetic Field Sensor
% 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
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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions