I read about PWM and how it should work nice with DC motors, I upload the code to the Arduino Uno, using pin 3,5,6,9 or 10 - and mappes the speed from 0 - 256. But it do not work. 0 = off, and any number between 1 and 256 = on, but no change in speed at all.
But it do not work. 0 = off, and any number between 1 and 256 = on, but no change in speed at all.
It's hard to believe that a "1" runs the motor at all!
Try simplifying your code to a single analogWrite() (probably followed by a delay while you wait to see what happens). What you're describing will happen with digitalWrite().
Or connect an LED (and resistor) in parallel with the motor to see if it dims with PWM. If it doesn't dim, you're not getting PWM. If it doesn't dim at the motor connection (driver output) try directly connecting the LED & resistor to the Arduino I/O pin.
I'd guess you've got a bug in your code, but there could be something screwy with your driver circuit. (You are using a motor driver circuit, right?)
Hi. This is my code, real simpel. Yes the engine run on 1 or any number, I thought is runs like a boolean operation, 0 = "false", while any number is "true".
No motor driving circuit, small engine connected directly to the Arduino board to ground and pin 3.
Don't feel bad, analogWrite is a poor name for writing PWM anyway!
And digitalWrite should really take a boolean so that your mistake would be spotted by the compiler!
No motor driving circuit, small engine connected directly to the Arduino board to ground and pin 3.
You really need to change that. The I/O pins are only good for 40mA MAX, and I wouldn't recommend anything over 30mA. The motor also needs a diode across it, and it's own supply and controlled by either a mosfet or bjt. What's about to happen is you are going to fry your arduino.
MarkT:
Don't feel bad, analogWrite is a poor name for writing PWM anyway!
And digitalWrite should really take a boolean so that your mistake would be spotted by the compiler!
C++ does not know the concept of boolean AFAIK. Did I miss something? I agree that it would be nice to have at least a compiler warning for "strange" values.
Thanks Tinman13kup, the small motors use 35 mA. I did not know about mosfet before you mention it, but I will buy them from Ebay. What kind of diode would you recommend?
Hi Olf 2012, have to say I don't know what an AFAIK is?
If you only ever plan on running the motors in one direction, then the mosfet is all fine and dandy, and any common 1N400x diode will be fine. If you decide you want the motor to spin both directions, then a motor controller (h-bridge) is what you need. The controllers also make it easy to attach that critical second power source.
Your motor might only pull 35mA freewheeling, but it will pull much more current when under load or stalled. Start up also sees a very brief current surge.
Generally yes, but given your limited experience in electronics, I would recommend sticking to reputable sellers with good tutorials, libraries, and even customer support. Here is a DC/stepper motor driver from Adafruit. They have lots of interesting items for the arduino, backed by the aforementioned support. SparkFun is another site to visit.
Most of the stuff of ebay is cheap knockoffs using inferior parts. They tend to leave you on your own after the sale, and documentation is normally non-existent. When you buy something, you need to know what the pinout is, what voltage/current specs are, what input parameters are needed, any libraries, and what the output specs are.
Take a simple buck/boost module. It doesn't help that it's real cheap if you don't know what the current limits are, or how much ripple is on the output.