Arduino Output Pin to Switch a Transistor

Discussion in 'General Electronics Chat' started by CoachKalk, Oct 6, 2014.

  1. CoachKalk

    Thread Starter Member

    Sep 20, 2011
    139
    2
    Hello again! I have not visited here for quite some time. This forum was incredible with the help I was given to get my laser maze up and running.

    Now, several years down the road, I am on to another project. I have built a DIY motion simulator for driving games and a roller coaster game.

    The software I use to drive my motors also has the ability to output "virtual" speed to an Arduino. I have included a drawing of a basic transistor circuit that I copied from this site. The transistor switches like expected when I close the switch.

    My question is, can I use an output pin from an Arduino UNO instead of the switch? The ultimate goal is to use PWM to vary fan speed based on ride speed.

    Thank you in advance for any help.
    Steve
    [​IMG]
     
  2. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,058
    3,820
    Yes, just remove the 10k transistor and switch from your circuit. Add a 4.7k transistor from your output pin on Arduino to the base of the transistor. If you are not getting enough current to the fan, you can boost the current from the Arduino to the transistor by using a smaller resistor to the base (down to 220 ohm should be ok).
     
  3. wayneh

    Expert

    Sep 9, 2010
    12,126
    3,048
    And in case it isn't clear, the Arduino and the fan need to share the same ground, so that the Arduino signal causes the transistor base voltage to rise above that ground.
     
    GopherT likes this.
  4. CoachKalk

    Thread Starter Member

    Sep 20, 2011
    139
    2
    Thank you both! I am currently just powering my Arduino via the USB connection and am using a separate 12v power supply for my fan. I thought I read that the PWM pins have a 5v max. Should a use a jumper from the prototype board ground to the Arduino ground?

    Thanks
     
  5. ScottWang

    Moderator

    Aug 23, 2012
    4,855
    767
    Your two boards need a common ground to become a DC circuit loop.
     
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,548
    2,373
    If the fan is less than 200 ma continuous, maybe use a 2N7000,? this is what I tend to go to using a PIC.
    Max.
     
  7. CoachKalk

    Thread Starter Member

    Sep 20, 2011
    139
    2
    I am currently just using an extra PC cooling fan 12v .13A in order to figure everything out. I have a bigger 12v 2.5A fan that I hope to use to really add some fun to the roller coaster ride. Hopefully my current transistor can be used for both the debugging and the final fan.

    While running the game, I can see the RX led blinking which I assume means the game is sending data. At this time, the fan just stares back at me ...

    I will take another look at my simulation software settings as well as the Arduino code.
     
  8. CoachKalk

    Thread Starter Member

    Sep 20, 2011
    139
    2
    Ok, I made a change to my simulation software and the fan spins! The problem is the fan now spins whether I have the game running or not. As soon as I plug the USB into the computer, the fan starts.

    Do I need to change the resistor value or is it likely an issue with my output pin not ever be "off"?
     
  9. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,058
    3,820
    Draw out how you connected the circuit. It could be that the arduino output pin is never turning off. Measure the voltage at the transistor base, and let us know what that is as well.
     
  10. wayneh

    Expert

    Sep 9, 2010
    12,126
    3,048
    The transistor and the fan will turn on if/when that transistor sees >~0.6V on the base pin, compared to the emitter pin. You can check that with a meter and maybe track down where the ∆V is coming from.

    Be careful with "ground". Depending how these things are powered, and particularly if there are two mains-powered supplies involved, the ground of one may not be at the same voltage as another, and current can flow from one to another when you connect them. A schematic, diagram or photo might help folks see the problem for you.
     
  11. CoachKalk

    Thread Starter Member

    Sep 20, 2011
    139
    2
    I have included a pic of my circuit below. I checked again and my first description of the condition was not accurate.

    When I plug the USB into the computer, the fan stays off. As soon as I start the game, the fan starts turning, but does not change speeds per the game. After I exit the game, the fan continues to turn until I unplug the USB. When plugged back in, it again stays off until I open the game.

    Let me know if you have questions about the pic.

    Thanks again for your help.
    [​IMG]
     
  12. wayneh

    Expert

    Sep 9, 2010
    12,126
    3,048
    Well that sounds like software? Can't help.
     
  13. CoachKalk

    Thread Starter Member

    Sep 20, 2011
    139
    2
    The only thing I was wondering about whether a pull down resistor should/could be used to pull pin 11 low.
     
  14. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    What is the part number on your transistor?
    There are different lead identifications for 2N2222. Try turning the transistor around.
     
  15. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,058
    3,820
    Yes, I think there are multiple versions of that transistor. Check the leads of your specific transistor.
     
  16. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,058
    3,820
    Post your arduino script.
     
Loading...