Position Controlling DC-motor with L298N. is it possible?

Hello

I have a project where we are to make a turret that we wish to controll both automaticly and by joystick
is it possible to use a dc geared motor and the L298N motor driver for this ? in any case what is the easiest way to do this ?

The components i have now is:
2x L298N
3x dc-geared motors https://www1.elfa.se/data1/wwwroot/assets/datasheets/05445507.pdf
1x arduino Nano
battery

do i need more ? or is it possible to write a feasible code for the project with this ?

It's possible. Getting the turret to move would be easy enough but you'd likely want a method of detecting it's position. The methods available to achieve this are endless. Just a few ideas that could be used

A potentiometer driven by the turret.
A set of microswitches placed at strategic positions.
An led with a sensor each side of a printed acetate disc
Angular position sensing chip
An optical mouse strapped to the side of the turret so that it rides over a flat surface.

So in general the best way would be to use a motor with built in sensors so i dont have to make my own?

You can use servo motors but these are generally either very lightweight (ok for moving small light components) or expensive. For the turret on a toy tank, this may be the ideal solution (as long as you handle it carefully). Anything much larger and you'll likely want to choose an alternative method.

Another approach is to use a stepper motor. At startup it could automatically rotate until a fixed switch is triggered (and therefore puts the turret into a known position). After that, any position can be chosen by just moving it the required number of steps in the right direction. Typically these have something like 200 steps per revolution and can even be configured to give half steps. The controller keeps track of the position by just updating a variable every time it takes a step.

The turret will carry the arduino with components so it can if we wish it turn 360 degrees around, it will also carry a softgun with the weight of about 2,2kg so the safe bet on total weight is 3kg on the whole build on top of the turntable.

In that case I'd probably go with a stepper motor. They provide a lot of torque in a small package and they also have the benefit that they can automatically clamp the turret in set position. This would provide some stability when the turret is not actually being rotated.

A stepper motor with a Home flag /sensor (opto interrupter) on the turret. (flag on the turret, sensor on the base)

since this is a school project there are some limitations to the materials.. we are stuck with the motors.

we are going to use rasberry pi for the camera we are to attach, how would it work to place end switches and perhaps a center switch and then try using the camera function for position when the automated tracker is in function? controlling the unit with a joystick should be ok either way i guess. that would be just stop and go function.

Check out the attached sketch.
It uses a single motor and a pot.
Center the pot and the motor doesn’t move.
Turn the pot CW and the motor moves one direction at a speed determined by how far from center the pot is.
Turn the pot CCW and the motor moves opposite direction at a speed determined by how far from center the pot is.

I don’t know if this helps but you might be able to get some ideas to control the turret using the pot position.

ACTUATOR_no_delay.ino (1.46 KB)

KenF:
In that case I'd probably go with a stepper motor. They provide a lot of torque in a small package and they also have the benefit that they can automatically clamp the turret in set position. This would provide some stability when the turret is not actually being rotated.

An ordinary DC motor with encoder and servo-loop control can do the same, but with much
less power drain. Its finding a reasonable encoder for position feedback that's usually the
tricky part. A gear motor with built in encoder would be ideal.

A simple PID loop driving the H-bridge from position-error signal will work reasonably
well if the encoder resolution is respectable (with a gear motor the gears increase the
effective encoder resolution (good), although they can introduce some backlash (not good))

Pololu makes several gearmotors that have add-on encoders. These usually have about 48 or 64 pulses per turn on the MOTOR, so by the time you get it geared, you have 64x100 or 6400 pulses if you have 100:1 gear ratio. You should have no trouble counting pulses with most Arduinos.

http://www.pololu.com/search/compare/22