Hello all,
I am working on a school project and am attempting to run a Linear Actuator (12V, max 3A draw) and small DC motor (12V, 150mA avg current and 600mA stall current) using an Arduino Duemilanove and L298N motor driver and controlled by a joystick with button switch (its actually the type of joystick used on those claw arcade games). Right now I'm just trying to get the motor to turn for 1 second upon pressing the button on the joystick, and will add the linear actuator later. However I can't get the motor to spin and have no idea what the problem is. Any advice would be greatly appreciated, thank you in advance. Also I have detailed pictures that clearly show my setup but I can't figure out how to add them to this post, so perhaps someone can tell me how to do that. In the mean time, I'll try and describe my wiring as best as possible...
On the Arduino:
-digital pin 2 is the input from the switch (the other side of the switch is connected to ground)
-digital pin 5 goes to IN1 on the L298N
-digital pin 8 goes to ENA on the L298N
-digital pin 10 goes to IN2 on the L298N
-Vin is connected to an external 12V battery
-Gnd is connected to neg side of battery
-5V goes to VLS on the L298N
(Also note that both Vin and VLS are connected to a 100nF capacitor which is connected to ground)
On the L298N (in addition to the previously mentioned connections from the Arduino) :
-OUT1 and OUT2 are connected to the two terminals of the motor
-Vs is connected to the 12V battery
-Gnd is connnected to neg side of battery
Finally heres the code I've written:
const int buttonPin = 2; //RedButton switch pin
const int motorPin = 5; //motor output pin
const int motorPin2 = 10; //other motor pin
const int EnableMotor = 8; //Enables H-Bridge for Motor
void setup()
{
// initialize the input and output pins from switch and to L298:
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
pinMode(motorPin, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(EnableMotor, OUTPUT);
digitalWrite(EnableMotor, HIGH); //enable IN1 on L298N
}
void loop(){
if ((digitalRead(buttonPin) == HIGH))
{
// turn motor on:
digitalWrite(motorPin, HIGH);
digitalWrite(motorPin2, LOW);
delay(1000); //rotate motor for 1 sec
digitalWrite(motorPin, LOW);
delay(2000); //Pause for 2 sec to disallow rapidfire
}
else
{
// turn motor off:
digitalWrite(motorPin, LOW);
}
}