Turning an Arduino servo motor to emulate turning of handle bars

조회 수: 1 (최근 30일)
Connor Harrell
Connor Harrell 2022년 11월 15일
답변: Ashu 2022년 11월 30일
I need to turn a servo to roughly emulate handle bars of a bike being turned. I have a list of latitiude and longitude coordinates each spaced two seconds apart to work off.

답변 (1개)

Ashu
Ashu 2022년 11월 30일
Hey Connor,
You can use MATLAB to control servo motors with arduino.
Support Packages Needed -
  1. Arduino Support from MATLAB : https://www.mathworks.com/hardware-support/arduino-matlab.html
  2. Arduino Support from Simulink : https://www.mathworks.com/hardware-support/arduino-simulink.html
% To connect with arduino on COM3 USB port
a = arduino('COM3', 'Uno', 'Libraries', 'Servo');
% To connect servo motor on D9 pin of arduino
s = servo(a, 'D9');
%% Sample code to move your servo motor to desired location
for angle = 0:0.2:1
writePosition(s, angle); %% 0<= angle <=1
current_pos = readPosition(s);
current_pos = current_pos*180;
fprintf('Current motor position is %d degrees\n', current_pos);
pause(0.01);
end

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by