0% found this document useful (0 votes)
42 views

(B) // DC Motor With Motor Driver L298N and Potentiometer

This document describes code to control two DC motors using a motor driver chip. The code defines pin connections for two DC motors and a motor driver chip. It sets the pins as outputs and loops to gradually increase the motor speed from 0 to 255 over 256 iterations, pausing 20ms between each step. A second section of code controls the two motors using potentiometers, mapping the potentiometer readings to motor speeds from 0 to 255 and driving the motors independently based on the potentiometer values read each loop iteration.

Uploaded by

raymart caluag
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

(B) // DC Motor With Motor Driver L298N and Potentiometer

This document describes code to control two DC motors using a motor driver chip. The code defines pin connections for two DC motors and a motor driver chip. It sets the pins as outputs and loops to gradually increase the motor speed from 0 to 255 over 256 iterations, pausing 20ms between each step. A second section of code controls the two motors using potentiometers, mapping the potentiometer readings to motor speeds from 0 to 255 and driving the motors independently based on the potentiometer values read each loop iteration.

Uploaded by

raymart caluag
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercise # 9 }

for (int i = 255; i >= 0; --i)


Two DC Motors and Motor Driver L298N {
analogWrite(motor1, i);
Component connection: analogWrite(motor2, i);
delay(20);
}
digitalWrite(inAmotor1, LOW);
digitalWrite(inBmotor1, LOW);
digitalWrite(inAmotor2, LOW);
digitalWrite(inBmotor2, LOW);
}

P1 (b)
// DC Motor with Motor Driver L298N and Potentiometer
int VAR1 = A0;
P2 int VARVALUE1 = 0;
int motorSpeed1 = 0;
int VAR2 = A4;
int VARVALUE2 = 0;
int motorSpeed2 = 0;
Program: int motor1 = 10;
int inAmotor1 = 9;
(a) int inBmotor1 = 8;
// Two DC Motors with Motor Driver L298N int motor2 = 5;
int motor1 = 10; int inAmotor2 = 7;
int inAmotor1 = 9; int inBmotor2 = 6;
int inBmotor1 = 8; void setup() {
int motor2 = 5; pinMode(VAR1, INPUT);
int inAmotor2 = 7; pinMode(VAR2, INPUT);
int inBmotor2 = 6; pinMode(motor1, OUTPUT);
void setup() { pinMode(motor2, OUTPUT);
pinMode(motor1, OUTPUT); pinMode(inAmotor1, OUTPUT);
pinMode(motor2, OUTPUT); pinMode(inAmotor2, OUTPUT);
pinMode(inAmotor1, OUTPUT); pinMode(inBmotor1, OUTPUT);
pinMode(inAmotor2, OUTPUT); pinMode(inBmotor2, OUTPUT);
pinMode(inBmotor1, OUTPUT); }
pinMode(inBmotor2, OUTPUT); void loop(){
} VARVALUE1 = analogRead(VAR1);
void loop(){ motorSpeed1 = map(VARVALUE1, 0, 1023, 0, 255);
digitalWrite(inAmotor1, LOW); digitalWrite(inAmotor1, HIGH);
digitalWrite(inBmotor1, HIGH); digitalWrite(inBmotor1, LOW);
digitalWrite(inAmotor2, LOW); analogWrite(motor1, motorSpeed);
digitalWrite(inBmotor2, HIGH); VARVALUE2 = analogRead(VAR2);
for (int i = 0; i < 256; i++) motorSpeed2 = map(VARVALUE2, 0, 1023, 0, 255);
{ digitalWrite(inAmotor2, HIGH);
analogWrite(motor1, i); digitalWrite(inBmotor2, LOW);
analogWrite(motor2, i); analogWrite(motor2, motorSpeed);
delay(20); }

You might also like