dc motor roation for 30,45 and 90 degree using switches.

Hello,
I am using 10rpm dc motor.i want to rotate the motor by some angle in upward direction and downward direction when i press two switches respectively.it means i want to rotate a dc motor in yaxis direction by using yplus and yminus switches.
I am using ARDUINO MEGA 2560 and L298 H-Bridge.
Please help me.
my code is as follow

sketch_jun15a.ino (926 Bytes)

How accurate you want to be - the movement won't be precise or fully
repeatable without some form of position feeback, but using duration to
control rotation with a large reduction gear train like this is roughly going
to work (if the load is even).

Have you looked at the BlinkWithoutDelay example yet?

hello,
When i will press yplus switch,mototo should move in yplus direction(say by 30 or 45 degrres).If I press Yminus switch.then motor should rotate in negative yaxis direction.and motor should ON only when i will press the switch

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How are you powering your motors?

Tom.... :slight_smile:

i am using 12volt power supply to power up the dc motor via l298 H-Bridge..

set up of my experiment is as shown in the image.

IMG_20150624_141056.jpg

Have you got any feedback from the motor so you know how far it's turned? I see only 2 wires to the motor so seems there's no encoder of any sort, as MarkT has suggested you need. Don't see anything in the code that would read an encoder. I'm pretty sure the merest "blip of the throttle" so to speak, will send your motor off to do a few revs.

Is there a compelling reason to use a plain old DC motor for this?- might be better to consider a servo or a stepper.

JimboZA:
I'm pretty sure the merest "blip of the throttle" so to speak, will send your motor off to do a few revs.

Not a problem, reread the original post!

MarkT:
Not a problem, reread the original post!

I had, and was thinking that even a slow motor would shoot off more than 30 degrees, although perhaps not a few revs.

I am facing problem with the code not with dc motor..code is executing but not entering into the loop..so i am not able to get the required result.

hello,
i am using ardunio mega 2560,L298 H-bridge along with 12volt dc power supply to power up the dc motors.i want motor to rotate by 180 degree in automatic and manual mode..
I am using four switches,xauto,xmanual,xplus and xminus to rotate the dc motor in respective direction..xplus and xminus switches will be used for manual mode..
please help me out in writing a code.

vinsan:
code is executing but not entering into the loop

Not entering into loop() do you mean? I doubt it, and anyway how do you know?

I'd suggest you use serial prints in your code, in the various ifs and elses so you have evidence of the route the logic is taking through the code. Have it print simple text so you know where it is.

(In future it's muuuuuch easier if you put the code in your post in code tags: otherwise we have to bugger around with the IDE making folders and stuff. Much easier to just read the code in the post, and copy the code from the screen into the ide to compile if necessary.)

Making the motor move is one thing. There must be hundreds of Forum Threads about L298s.

Knowing when it has rotated 180 degrees is an altogether different matter. You will need some for of external sensor to detect the orientation of the shaft - probably a rotary encoder.

...R

Robin2:
Knowing when it has rotated 180 degrees is an altogether different matter. You will need some for of external sensor to detect the orientation of the shaft - probably a rotary encoder.

And that's exactly the advice you were given in your other thread on the exact same subject, here, and which you didn't seem to like very much.