So, I completed the getting started with Arduino guide and exercises. I proceeded to buy the L298N motor shield and two small dc motors (not steppers) and two Photo resistors. I am trying to make a basic photovore that will determine engine speed based on light level for each side and thereby steer. Fairly straightforward or so one would assume. I am going to be hooking up the motors to the a and b motor drivers on the L298N. I am currently trying to figure out how to control speed. I am using this code at present, which I found on some site:
int pwm_a = 3; //PWM control for motor outputs 1 and 2 is on digital pin 3 (or 5,6)
int pwm_b = 9; //PWM control for motor outputs 3 and 4 is on digital pin 9 (or 10,11)
int dir_a = 2; //direction control for motor outputs 1 and 2 is on digital pin 2 (or 4,7)
int dir_b = 8; //direction control for motor outputs 3 and 4 is on digital pin 8 (or 12,13)
void setup()
{
pinMode(pwm_a, OUTPUT); //Set control pins to be outputs
pinMode(pwm_b, OUTPUT);
pinMode(dir_a, OUTPUT);
pinMode(dir_b, OUTPUT);
analogWrite(pwm_a, 100); //set both motors to run at (100/255 = 39)% duty cycle (slow)
analogWrite(pwm_b, 100);
}
void loop()
{
digitalWrite(dir_a, LOW); //Set motor direction, 1 low, 2 high
digitalWrite(dir_b, LOW); //Set motor direction, 3 high, 4 low
delay(1000);
analogWrite(pwm_a, 255); //set both motors to run at 100% duty cycle (fast)
analogWrite(pwm_b, 255);
delay(1000);
digitalWrite(dir_a, HIGH); //Reverse motor direction, 1 high, 2 low
digitalWrite(dir_b, HIGH); //Reverse motor direction, 3 low, 4 high
delay(1000);
analogWrite(pwm_a, 100); //set both motors to run at (100/255 = 39)% duty cycle
analogWrite(pwm_b, 100);
delay(1000);
}
at this point I only have one motor hooked up and 9v batter going to the Uno board. The motor is hooked up to A, and I can hear it engage and the LED is lighting, however the motor is not rotating. I beesech one kind soul to hook me up with a working code snippet to drive the motor, and I can figure out the rest from there. Much thanks.