Clear Filters
Clear Filters

How can i set the sampling rate for Arduino analogRead in matlab code?

3 views (last 30 days)
I want to use current sensor ACS712 to read the real time value for of 50Hz line current with the following code I found on the internet, but it not given the real-time signal. How can I set the sampling rate?
if true
% code
end
a = arduino(); % Create a figure window to monitor the live data
tmax = 10; % Total time for data collection in seconds
figure(1),
grid on,
xlabel ('Time (s)'), ylabel('Voltage');
axis([0 tmax -2.5 2.5]); % set initial index value, starting value
k = 0; %index
v = 0; %voltage
t = 0; %time
tic % Start timer
while toc <= tmax
k = k + 1;
v(k) = readVoltage(a,'A0')-1.47; %maximum value=3.935
t(k) = toc;
% Now plot the data
if k > 1
line([t(k-1) t(k)],[v(k-1) v(k)]);
drawnow;
end
end

Answers (1)

Sadam Hussain
Sadam Hussain on 10 Aug 2018
Hello, friend, I have the same problem I can not get accurate data did you get correct once

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!