Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Controlling a DC motor with external power source


  • Please log in to reply
10 replies to this topic

#1 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 20 November 2012 - 03:24 PM

Is it possible for a Netduino Plus to control two DC motors that are powered by batteries?

#2 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 20 November 2012 - 03:54 PM

Absolutely!

There are a few possible solutions that I would suggest that you look into. First off, you should never power a DC motor directly from the Netduino's pin. DC motors are incredilbly hungry for amps (current). Additionally, if powered by same source as your Netduino, the motors can produce a lot of electrical noise causing havoc to any sort of readings on the Netduino. To overcome this, you generally see a motor using it's own power source, such as your battery, that is separate from the Netduino's power source.

Here are a couple common examples written by community members ItsDan and Stefan on how to wire and use your DC motors.

  • This first example, by ItsDan, uses a transistor type system. - Transistor Example
  • The second example by Stefan uses a low cost chip called an H-Bridge to control a motor. - H-Bridge Example
  • The third, and my preferred method of controlling a motor, is using a pre-built motor controller, which generally incorporate H-Bridges Here are two common motor controllers that are known to work with the Netduino. - Adafruit Motor Shield and DFRobot Motor Shield

Hopefully this can get you started. And if you have any question please feel free to ask them here.

Cheers,
Steve

#3 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 22 November 2012 - 09:28 PM

Absolutely!

There are a few possible solutions that I would suggest that you look into. First off, you should never power a DC motor directly from the Netduino's pin. DC motors are incredilbly hungry for amps (current). Additionally, if powered by same source as your Netduino, the motors can produce a lot of electrical noise causing havoc to any sort of readings on the Netduino. To overcome this, you generally see a motor using it's own power source, such as your battery, that is separate from the Netduino's power source.

Here are a couple common examples written by community members ItsDan and Stefan on how to wire and use your DC motors.

  • This first example, by ItsDan, uses a transistor type system. - Transistor Example
  • The second example by Stefan uses a low cost chip called an H-Bridge to control a motor. - H-Bridge Example
  • The third, and my preferred method of controlling a motor, is using a pre-built motor controller, which generally incorporate H-Bridges Here are two common motor controllers that are known to work with the Netduino. - Adafruit Motor Shield and DFRobot Motor Shield

Hopefully this can get you started. And if you have any question please feel free to ask them here.

Cheers,
Steve





Thank you for your reply.I tried the second option you suggested,but it didn't work,and I thought your could give me a hand:
https://netmftoolbox...pported devices

I connected everything exactly as the picture shows,but when the program run,it does not work.I've added a while loop in order to make it go forever,and used the onboard led to tell me when it's off(with a delay of 2 seconds),but nothing works.Both of the engines are off.
What can be the problem? Are they common mistakes out there that maybe I made?

Thank you very much!

#4 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 22 November 2012 - 09:47 PM

Thank you for your reply.I tried the second option you suggested,but it didn't work,and I thought your could give me a hand:
https://netmftoolbox...pported devices

I connected everything exactly as the picture shows,but when the program run,it does not work.I've added a while loop in order to make it go forever,and used the onboard led to tell me when it's off(with a delay of 2 seconds),but nothing works.Both of the engines are off.
What can be the problem? Are they common mistakes out there that maybe I made?

Thank you very much!

I'll try and setup the project later this evening and give you a hand with it. I saw that you were in chat earlier. Sorry I missed you.

Steve

#5 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 23 November 2012 - 12:44 AM

I'll try and setup the project later this evening and give you a hand with it. I saw that you were in chat earlier. Sorry I missed you.

Steve


Thank you for your help! :)

#6 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 23 November 2012 - 06:07 AM

Hi Ben, The first time I ran the sample, I also had the same issue. However now I seem to be getting an error. Unfortunately it's really late here, so I will pick it up again later this morning and try to figure out what's going wrong. Cheers, Steve

#7 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 23 November 2012 - 06:16 AM

Thank you very much! I appreciate your help!

#8 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 23 November 2012 - 02:26 PM

Well, I learnt a couple of new things from my experience last night:
  • Don't start a project after 1 am.
  • Hockey temporarily reduces mental capacity after each game.

Now that I have had some coffee, and the brain is slowly defrosting, I have seen the error of my ways, and the potential step we may have skipped.

First off, the error I was getting was a bad mistake of my part, and introduce when I created a while loop to continually test the motors. In haste I wrapped the HBridge constructor into the while loop, which is a no no. :huh:

So on each iteration of the loop I was attempting to instantiate the MotorDriver with the same pins, over and over again, thus causing my error. No worries, I have placed my dunce hat squarely on my head for the remainder of the day.

Obviously you were wiser than myself, and didn't make that same mistake, however you are still not seeing any movement on your motor. I believe what you may be missing is the external power source need for the VIN pin. This may not be obvious looking at the schematic alone, however you need to plug in an external power adapter such as a wall adapter power supply (wall wart) to the Netduino. I missed step myself, until I looked at the HBridge source code. In it Stefan has created a great ASCII pinout diagram, and mentions that on pin 8 (Vcc2) of the SN754410/L293D is the power source for the motors, such as Vin on the Netduino. The unregulated VIN pin on the Netduino is directly tied to the barrel jack and can be tapped into for external power sources.

When looking for an adapter to use, the most important issue to look at is the polarity of the barrel jack. As long as the centre tap is positive and the outer ring negative, you should be able to use any adapter that is between 7.5v and 12v. For more information you can search the forums or check out the pinout reference sheet.

If this doesn't correct your issue, then let's dig in a little further and get you up and spinning. It would then be helpful if you showed me the code you're using. You may be having issues with the references since the Toolbox samples are compiled using Netduino classic, and .NetMF 4.1.

Cheers,
Steve

Edit: corrected power adapter voltage for the Netduino and Netduino Plus 1.

Edited by Gutworks, 25 November 2012 - 03:37 AM.


#9 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 24 November 2012 - 11:06 PM

I connected the Vin on the Netduino as shown on the diagram. So the reason it doesn't work,is because I need a 7-12V power to the Netduino? It makes sense,because I tried to power it through a USB cable(only gives 5V). One more question - if I'll buy A 12V battery case,can I cut the cables of the wall adapter power supply with the proper jack and connect it to the battery case? Because I need the Netduino to be mobile. I'll post here after I'll get the wall wart and update you.I thank you very much for your help,your time and the effort you've put in to help me.

#10 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 25 November 2012 - 04:12 AM

I connected the Vin on the Netduino as shown on the diagram. So the reason it doesn't work,is because I need a 7-12V power to the Netduino?

Yes, this is correct. However I did misstate the voltage levels for the Netduino Plus 1. It's actually 7.5V-12V. And just as a side note, the new Netduino Plus 2 is 7.5-9V.

One more question - if I'll buy A 12V battery case,can I cut the cables of the wall adapter power supply with the proper jack and connect it to the battery case? Because I need the Netduino to be mobile.

Yes, this should work, but make sure that the centre tap is connected to positive and the outer ring is connected to the negative terminal. I believe there is reverse voltage protection on the Netduino in case you incorrectly wire it, but it's better to be safe than sorry.

As I mentioned before it's often a good idea to have two separate power sources, one dedicated to the motors, and another power the Netduino. Another neat alternative is to use a Lithium ion USB charger that many use to charge cell phones with. You simply plug a microUSB cable from the charger to the Netduino's USB port and, voila, you have a smooth source of 5V power. You can then wire the battery directly to the H-bridge, but make sure the grounds are shared (connect a wire from the battery's negative terminal to the GND on the breadboard or Netduino).

Cheers,
Steve

#11 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 25 November 2012 - 06:18 AM

Great!Thank you!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.