Last active
May 22, 2023 23:57
-
-
Save CodeNextAdmin/be8f904f684dd7d9704a423acf59f174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ARDUINO 2 MOTOR EXAMPLE - L298N | |
// This version does not include the potentiometer | |
int SPEED = 255; // 0 - NO SPEED, 255 - FULL SPEED | |
//motor 1 | |
#define enA 9 // should be pwm pin(~) | |
#define in1 6 | |
#define in2 7 | |
//motor 2 | |
#define in3 5 | |
#define in4 4 | |
#define enB 3 //pwm for motor 2 | |
void setup() { | |
// Set all the motor control pins to outputs | |
pinMode(enA, OUTPUT); | |
pinMode(enB, OUTPUT); | |
pinMode(in1, OUTPUT); | |
pinMode(in2, OUTPUT); | |
pinMode(in3, OUTPUT); | |
pinMode(in4, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
//SET THE SPEED OF THE MOTORS - CHANGE AT THE TOP. | |
analogWrite(enA, SPEED); | |
analogWrite(enB, SPEED); | |
//try changing these from HIGH to LOW. | |
digitalWrite(in1, HIGH); //motor 1 | |
digitalWrite(in2, LOW); //motor 1 | |
digitalWrite(in3, LOW); //motor 2 | |
digitalWrite(in4, HIGH); //motor 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment