0% found this document useful (0 votes)
19 views3 pages

Arduino Joystick DC Motor Speed and Rotation Direction Control

Uploaded by

favioslopez85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Arduino Joystick DC Motor Speed and Rotation Direction Control

Uploaded by

favioslopez85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// Arduino joystick DC motor speed and rotation direction control

#define joystick1 A0

#define pwm1 9

#define pwm2 10

#define joystick2 A1

#define pwm3 5

#define pwm4 6

int motor_control;

void setup() {

pinMode(pwm1, OUTPUT);

pinMode(pwm2, OUTPUT);

pinMode(pwm3, OUTPUT);

pinMode(pwm4, OUTPUT);
}

void loop() {

// read the input on analog pin 0:

// For joystick on/off, fast/slow

int sensorValue = analogRead(A2);

int sensorValue = analogRead(A3);

// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

//float voltage = sensorValue * (5.0 / 1023.0);

// print out the value you read:

// Serial.println(voltage);

motor_control = analogRead(joystick1);

motor_control >>= 1;

if(motor_control > 255){

digitalWrite(pwm2, 0);

analogWrite(pwm1, (motor_control - 256));

else

if(motor_control < 255){

digitalWrite(pwm1, 0);

analogWrite(pwm2, (255 - motor_control));

else{

digitalWrite(pwm1, 0);

digitalWrite(pwm2, 0);

}
motor_control = analogRead(joystick2);

motor_control >>= 1;

if(motor_control > 255){

digitalWrite(pwm4, 0);

analogWrite(pwm3, (motor_control - 256));

else

if(motor_control < 255){

digitalWrite(pwm3, 0);

analogWrite(pwm4, (255 - motor_control));

else{

digitalWrite(pwm3, 0);

digitalWrite(pwm4, 0);

You might also like