0

I'm trying to program an Arduino to control a motor at different intensities by giving a 0-5V reference value from the board. I have some programming experience, but have very little knowledge of manipulating an Arduino or about electricity. As I understand from reading this, I need to call the AnalogWrite function to output the signal, but how do I do this? How can I control when the voltage (and by extension, the motor intensity) is increased or decreased. Is it possible to do this without additional hardware?

Any help is much appreciated, it doesn't have to be code. I mostly want to understand how to use the Arduino, but code would also help a lot with that. I'm using an Arduino Due, which as I understand, has true analog out.

  • 1
    What is the motor you are trying to control? – Majenko Aug 28 '18 at 14:28
  • I'll do my best to describe it, but essentially it is a robot that has a series of pressure regulators that supply air to pneumatic tubes in a mesh that act like muscles when pressurized. The regulators control which group gets pressure. The arduino will not be powering the motor, simply controlling the level of pressure the "muscles" are getting from intensities 0-5 based on what the board is outputting. I realize that's a bit different from what I wrote in the OP, but I explained it that way for simplicity. – Nyra Aug 28 '18 at 14:39
  • 1
    The actual hardware used matters in this case. If the pressure regulator is only getting a "signal" and not drawing it's operating current from the Arduino, then you may not need to fool with MOSFETs. But it depends a great deal on the actual item the Arduino is connected to. Would you be able to provide a link to a datasheet for the pressure regulator or whatever device the Arduino would be connected to? It might also be that the device really requires a true Analog signal and not a PWM average voltage. – jose can u c Aug 28 '18 at 14:46
  • Why do you want true DAC? PWM can be amplified with MOSFET. For analog you need a voltage convertor. – Juraj Aug 28 '18 at 15:20
1

You would indeed need to use analogWrite to send a PWM signal to the motor. PWM will turn on and off the power to the pin really fast. In effect powering the motor with pulses. The length of these pulses will determine how much power the motor receives.

The DUE also has a true analog output, but you don't want to use that for motors. The use of the word analogWrite is a bit misleading when it's used for generating a PWM signal.

analogWrite will ask for a value between 0 and 255 to indicate the pulse length. 0 is OFF, 255 is full ON, 127 is ON for 50% of the time.

Also note that most motors require more current that the Arduino pins can provide, so you need to use a transistor/mosfet to "amplify" the signal to a higher current.

  • So is there a way I can control the voltage output rather than pulse length? – Nyra Aug 28 '18 at 14:55
  • @Gerben correct, I missed the Due tag. – Michel Keijzers Aug 28 '18 at 14:59
  • not only to amplify the current, but to go to 5 V – Juraj Aug 28 '18 at 15:18
  • @Nyra why would you want to? Like I said; for a motor you’d want to use PWM instead. – Gerben Aug 28 '18 at 15:20
0

You can't do it without additional hardware because Due output is max 3.3 V. You need to amplify PWM or the analog output. PWM can be amplified using a MOSFET. If you are new to electronics I would recommend Grove MOSFET module. I use it to amplify PWM of M0 to 5 V.

It is normal to use PWM for regulation. True analog output is used for sound and similar waves. If you really need true analog value to 5 V with Due, you must use a voltage converter like in the tutorial linked by Majenko in comments.

The Arduino core handles the DAC of the SAMD boards with analogWrite() too.

Quote from the analogWrite reference:

The Arduino DUE supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs.

And you can set the resolution with analogWriteResolution():

By setting the write resolution to 12, you can use analogWrite() with values between 0 and 4095 to exploit the full DAC resolution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.