Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

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

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by