Controlling a 12V device with a microcontroller

Discussion in 'The Projects Forum' started by KansaiRobot, Jul 20, 2010.

  1. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Hello all

    this must look like a really dumb question but please allow me.
    say I have a 12V motor that I want to control with a micro (that is powered on 5V)

    the normal thing I have done so far is to isolate the circuits with a photocoupler.

    Instead of that, I have been suggested to connect the output to a transistor and use that as a switch to the 12V circuit. now I dont know if that is stable or not but my question is even MORE BASIC than that.:(

    1) If I connect the output of the micro to the transistor and the ground pin to ground, where do I connect the 5V pin to???

    2) do I need a power source with two outputs (12V and 5v)?

    3) What if I am using batteries? if I use 8 batteries(12V) where do I connect the micro 5V pin?

    Thanks for the answers...

    Kansai
     
  2. JoeJester

    AAC Fanatic!

    Apr 26, 2005
    3,373
    1,157
    you can use a 7805 connected to your 12V supply to make 5V.

    Look up H-bridges to see how to power your motor.
     
  3. windoze killa

    AAC Fanatic!

    Feb 23, 2006
    605
    24
    As Jester said you can use a 7805 regulator for the 5V. I would suggest a 12V powersupply for the motor and use that to power to 7805 to supply the 5V for the micro. You use an output of the micro to switch the base of a transistor to operate the motor. You could alos use an H-Bridge if you need more control over motor speed and direction.
     
  4. mrmeval

    Distinguished Member

    Jun 30, 2006
    833
    2
    The microcontroller would be powered by +5 volts, an output pin or pin configured as an output would go to a resistor, that would go to a transistor that uses 12 volts to drive the motor. There are some other components needed and they are in the article. Any microcontroller should be able to at minimum do on/off..

    The arduino is a microcontroller system as it has a built in regulator, usb-serial converter and other features. Since the arduino has analog inputs and pwm (analog) outputs the transistor can be sent varying voltage. The pot would simulate several analog sensors. The pot is there so you can actually do something and see it happen. After verifying the circuit you can use hard coded behavior, analog sensor, digital input, rf or ir input like a remote control, serial input from a PC etc

    http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads
     
  5. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    thanks for the answers!:)

    so basically I have to use that .
    Isnt There no other way...? (I know it must sound stupid but I was even thinking of taking a cable from the middle of the series of batteries (4 batteries so 6V) and using the extremes for the motor- i guess that wont work)

    I mean it looks so simple in tutorials (just connect this to 12v and that to 5V) but in reality I guess it is more complicated. Am I wrong?


    about the other stuff (H-bridges and stuff, I will ask about that in another thread. thanks for the useful info)
     
  6. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5

    thanks for the useful link.
    I basically knew almost all of what is written there, but my question is MORE BASIC

    take a look at the picture from that tutorial
    [​IMG]

    in the upper side you can see the 12V power source.
    and the micro is connected to a 5V source.

    the INTERESTING thing is that the ground of the 12V power source IS CONNECTED to the ground of the 5V source!!!!

    Can you do that???

    So, in other words, there is no necessity of complicated circutry as the other posters kindly suggested????

    I would like to clarify that, please

    thanks

    Kansai
     
  7. Bosparra

    Member

    Feb 17, 2010
    79
    3
    The two grounds HAVE to be connected, else the circuit wont work. GND serves as reference, from which voltage is measured. If the two power sources are not referenced by the same GND, then there is no point in referring to 12V and 5V, because they will not be 12V and 5V with respect to each other.
    Hope that makes sense.
     
  8. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    To control a DC Motor with a microcontroller, it is best to use an H-Bridge,

    A typical H-Bridge setup is shown in the pic below... the microcontroller will have its own 5 volt source and the motor will be powered off of the 12 volts.... only 3 I/O pins are needed from the micro for the Brake, PWM, and Direction control of the Motor...

    [​IMG]

    B. Morse
     
  9. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    thank you for your responses. In conclusion i will join both power sources grounds.

    Now for the H-bridge part.

    I was thinking of using 2N3904 transistors (cause I have a few) but turns out that the maximum Ic is 200 mA. now normally motors require like 1A I read in a tutorial. I called the provider of my motor (cause there is no datasheet) and he told me my motor uses around 250~270 mA.

    so in anycase i believe 2N3904 are out.
    I am checking and it seems 2N2222 are much better for this (can deal with 800mA) but the Hfe is 75 compared to 2N3904's 100. Still it seems like a good option to build a H-bridge.

    Now, my question:

    I have also with me one Toshiba TA7291S ( a bridge driver).

    TA7291S datasheet (pdf)

    Do you think this is a good option for my motor. I cant seem to understand the specs in the datasheet. Are the transistors of this bridge driver adequate for my motor?

    Also i dont understand very well what VCC VS and Vref are. i am using a 12V motor and a normal PIC (5V)

    thanks a lot

    kansai
     
  10. sage.radachowsky

    Member

    May 11, 2010
    241
    38
    Look down further on the data sheet to see what the pin names mean -- there is a table.



    Check out this link. There's a video, and there is a very simple schematic.

    If you only want the motor to go in one direction, then you only need a transistor and a diode, in addition to the microcontroller and its power supply.

    (The diode is there to snub back EMF, or inductive kickback, which results from the coil inside the motor when it is turned off.)

    Your question about the microcontroller power supply -- it is best to use a linear regulator to produce 5V from the 12V source. I suppose you could pull a nominal 4.5V from the stack of 1.5V cells... at the top of the 3rd cell. Don't put nominal 6V into a PIC. I think they only accept up to 5.5V. You'll stress it out. Also, 1.5V cells are often 1.6V in reality when they are fresh, so it could be 6.4V at top of the 4th cell. But best to find a linear regulator -- simple and reliable.

    Now to go further -- if you tell the microcontroller to turn the transistor on and off fast, you will be doing PWM (pulse width modulation). That will allow you to control the speed. You will also want to add a capacitor in parallel with the motor then, to smooth out the supply, and prevent excessive kickback.

    The H-bridge is useful if you want to go in reverse, and it's a nice package that is already designed with the snubbing diodes and nice heatsink, etc. But it's complex if you just want to go in one direction, and you want to use this experience to learn about electricity.
     
  11. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Well unfortunately I have to control the robot in both directions...

    So I have decided to use the bridge even though I am not really sure their transistors can support the necessary current...:eek:

    so now, questions about this chip

    1) I dont really need to put resistors between the output of the PIC and the input to the bridge. Do I??? I dont want to fry my PIC but I want to make sure about this

    2) For PWM. lets say we have TA, TB, TC and TD on the bridge. To go on one direction you turn on TA and TC and on the other direction TB and TD. Now I read in a PWM tutorial that the way to do it is to :

    Forward: High on TA and PWM on TC
    Backward: High on TB and PWM on TD

    Ok. that is fine if you directly control four different transistors.
    But in the case of the bridge in which you only control I1 and I2 how do you do this?

    I am thinkin:

    Forward PWM on I1 and 0 on I2
    Backward PWM on I2 and 0 on I1

    Any thoughts on this??

    Thanks a thousand

    Kansai
     
  12. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    I found one tutorial in which they use the bridge chip I plan to use.

    they indicate to use just 1 or 0 to the inputs to select direction for the motors.
    And to apply the PWM signal to the Vref input.

    I am going to try this and report back here

    Kansai
     
  13. JoeJester

    AAC Fanatic!

    Apr 26, 2005
    3,373
    1,157
    Did you look up H-bridge? That is typically four transistors or four FETs.

    Do not confuse that with a diode bridge.
     
  14. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    I believe that the Toshiba TA7291S ( a bridge driver). is H-bridge.

    I now have another problem. The PWM that I am gonna feed the Vref with, is 0-5V but at 5V the motor barely moves...(it requires 6V~12V)

    So I guess what I am going to do is not directly connect the PIC to the bridge but put a transistor in the middle to direct up to 12V to the bridge Vref....
     
  15. JoeJester

    AAC Fanatic!

    Apr 26, 2005
    3,373
    1,157
    The five volts is connected to the base of the transistors. The Bridge is connected to +12V and Ground (return)
     
  16. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Some how I can not do it...:(

    I know I am really unexperienced...but I tried...

    please take a look at the attached image

    I apply ON/OFF (5V/0V) to the base with a RB=82K and a RC=220Ω

    I want to generate a signal ON/OFF (12V/0V) for the bridge...

    but in the point with the arrow I only get 12V to 8V (and inverted!!!!)

    What am I doing wrong????

    I tried to put the resistor in the emitter and it goes from 0v to 2V

    Help

    Kansai
     
  17. windoze killa

    AAC Fanatic!

    Feb 23, 2006
    605
    24
    Try reducing the value of R8 to about 10K. 82K seems way too high. That will turn the transistor on harder. I assume you are using an NPN in that configuration.

    Measuring the voltage at the collector like you are it will be inverted. If you want the same polarity pulse you would need a PNP with the emmitter going to +12V and the resistor in the collectorto ground. You take you output from the collector.

    Another option would be to invert the output of the micro. That way the collector will go to 12V when the input to the base is 0V.
     
    KansaiRobot likes this.
  18. JoeJester

    AAC Fanatic!

    Apr 26, 2005
    3,373
    1,157
    Do you have the TA7291S datasheet?

    You do not need the level translators, that last circuit you posted.

    How much current does your motor draw?
     
  19. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Thanks for the advice. i tried reducing it to 10K and it worked!
    Well it didnt go to 0 but anyway now I got 12V when base is 0 and 0.5V when base is 5V. I guess I am going to invert the base signal (cause I have no idea how PNP works and anyway I dont have one)

    if you have any advice please tell me. I am worrying about the current... I suppose I ll have to measure it.

    Kansai
     
  20. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    I have but cant understand it totally
    I am connecting Vs to 12V (the motor works from 6V to 12V)
    and Vcc to 5V
    and providing the PWM to Vref. But the output Voltage to the motors is reflection of Vref so if I give the PIC PWM to it, the motor only will get 5V max.

    that is why I need the transistor

    What is a "level translator"?
     
Loading...