Go Down

Topic: digitalWrite not giving pin 5v?  (Read 1 time) previous topic - next topic

zodsrc

I built a little tamiya kit and hooked my gearbox to the 5v it runs fast, I hooked it  to the 3.3v it runs a bit slower, I wanted to do this with some code to so it would run around on the floor but I can't get it to send 5v power to any of the pins - it sends power enough to run an LED but when I add the motor to it doens't power it ( and if the LED is still part of the circuit it turns off completely )

what am I doing wrong?

Code: [Select]

void setup()
{
  pinMode(2, OUTPUT);          // sets the digital pin 2 as output
}
 
void loop()
{
  digitalWrite(2, HIGH);       // sets the digital pin 2 on

}



just to be clear when I connect the ground and power to the 5V and GRN it powers up no problem, when physically change the positive connection to the 3.3v it runs slower, but when I put it on pin 2(or any other pin I setup like this) it doesn't power the motor..

Any ideas on what I am doing wrong?

I'll post a Video this evening..

Thanks in advance for any help ! 

ballscrewbob

#1
Sep 28, 2018, 08:44 pm Last Edit: Sep 28, 2018, 08:46 pm by ballscrewbob
Dont try drive motors directly from the Arduino as there is a good chance you may damage it.
Motors can give off reverse spikes when stopping

Instead use a DRIVER shield or board of some description.
Almost any type of robot with motors uses the DRIVER approach.

Also avoid trying to drive motors directly from the Arduinos 5V and 3.3V pins but give them thier own PSU with a common ground.


It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

zodsrc

Ok, I was planning on getting a motor driver shield but just wanted to see how far I could get without one..


It should still work in theory shouldn't it ? I wonder maybe my arduino board is broken

Wawa

In theory a pin should instantly fry if you draw more than 40mA from it.
Practically, I have seen a pin survive a short for several minutes.
Russian roulette though.

Test the pins you have used with a LED with 220ohm resistor in series, and the blink example from the IDE.
Leo..

Southpark

what am I doing wrong?
Possibly not reading enough information and tutorials on the internet. That is, if you read enough tutorials starting from basics, then it might be possible to find out that there are no tutorials that involve driving a motor with a raw arduino pin directly.

GolamMostafa

#5
Sep 29, 2018, 05:36 am Last Edit: Sep 29, 2018, 10:27 am by GolamMostafa
@Op

You may try the following circuit using a Bc327 as a swich and DPin-2 as a control pin. Now, you have to execute digitalWrite(2, LOW); to activate the circuit so as to connect ~5V to the Motor Circuit.

Wawa

That circuit could fry the transistor as well as the pin.
The pin is directly connected (shorted) to 5volt with only a BE diode in between.

Must use a resistor between base and pin (same as you do with an NPN transistor, low-side).
Leo..

GolamMostafa

#7
Sep 29, 2018, 10:41 am Last Edit: Sep 29, 2018, 03:17 pm by GolamMostafa
That circuit could fry the transistor as well as the pin.
The pin is directly connected (shorted) to 5volt with only a BE diode in between.

Must use a resistor between base and pin (same as you do with an NPN transistor, low-side).
Leo..

Figure-1: PNP transistor based switch

1.  When DPin-2 assumes LL-state, the gain (alpha) of Q1 is very close to unity (~0.9); 5V of the E-point immediately appears at the C-point. Most of the currents due to majority carrier (the holes) crosses the C-junction and then goes to the load. I don't see any safety threat neither for Q1 nor for 5V tolerant/20 mA Dpin-2. Edit: in view of Post#8. (A resistor is needed between base and Dpin-2 (Fig-3) to protect the transistor.)

Figure-2: Current distribution in PNP transistor

2. If a resistor (R2 in Fig-3) is placed between the Base and Dpin-2 of Fig-1, the Q1 could not be made ON due to base voltage > 0.7V coming from the voltage divider. The base voltage of Q1 must be very close to 0V for the transistor to enter into saturation zone. Edit: in view of Post#8.

Figure-3

Wawa

#8
Sep 29, 2018, 12:38 pm Last Edit: Sep 29, 2018, 12:39 pm by Wawa
Time to review how a PNP transistor works.
The EB junction is a diode, and base can't be less than "VCC - 0.7volt".
Leo..

GolamMostafa

#9
Sep 29, 2018, 03:00 pm Last Edit: Sep 29, 2018, 03:03 pm by GolamMostafa
Time to review how a PNP transistor works.
The EB junction is a diode, and base can't be less than "VCC - 0.7volt".
Really, getting old; yes, the transistor will become fully ON for VEB = 0.7V; therefore, a voltage divider circuit is indeed needed at the base to consume the 4.3V drop and thus protecting the transistor.  

Wawa

A BJT is current driven, so only a current limiting resistor between pin and base is needed here.

A resistor between emitter and base is only sometimes used to make sure the transistor is fully 'off'.
Not needed here, because the Arduino pin can pull the base fully to emitter level.
Leo..

zodsrc

Thanks for the insight , I will continue studying more tutorials and learn more..

@GolamMostafa thanks for posting that alternative solution !

MarkT

Ok, I was planning on getting a motor driver shield but just wanted to see how far I could get without one..
You can easily get totally fried Arduino.

Any inductive load can put killer voltage pulses onto pins if connected directly - never connect
an inductive load to any output not specifically designed to handle one.
Quote
It should still work in theory shouldn't it ? I wonder maybe my arduino board is broken
It cannot possibly work, motors need current measured in amps, not milliamps, and see above too.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up