How to output digital 5V from Arduino Uno

I have a motor connected directly to Pin 4 (digital) on an Arduino Uno. The motor goes when motion is detected. I understand I should have the motor hooked up to a transistor circuit instead so I can power it with more than the 5V that an Arduino can give me, but for what I'm doing 5V is sufficient. However, when the motion is detected, sometimes it outputs 2V and sometimes it outputs 0.5V (I'm measuring this directly with a voltage meter across the motor). I need at least 3V. Is there a way to make the Uno output at least 3V every time? 5V would be even better.

Basically, right now I just have an if statement that makes the motor go if motion is detected. I just simply have a digitalWrite(motorpin, HIGH). However, its inconsistent and outputs too little voltage...

// Motion Control Motor

// Button Variables
int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;

//Motor Variables
int motorPin = 4;

//Sensor Variables
int sensePin = 1;

// Program Setup
void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(motorPin, OUTPUT);
pinMode(sensePin,INPUT);

Serial.begin(9600);
}

// Button Debounce Function
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}

// Reset Function
void reset(){
lastButton = LOW;
currentButton = LOW;
ledOn = false;
digitalWrite(ledPin, ledOn);
}

// Program Loop
void loop()
{
Serial.println(analogRead(sensePin));
delay(100);

currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH){
ledOn = !ledOn;

lastButton = currentButton;

digitalWrite(ledPin, ledOn);

while(true){
Serial.println(analogRead(sensePin));
delay(100);

if (analogRead(sensePin) > 80){

digitalWrite(motorPin, HIGH);

delay(1000);

digitalWrite(motorPin, LOW);

//for(int i=255; i>=0; i--){
//analogWrite(motorPin, i);
//delay(10);
//}

reset();
break;
}

else{
delay(100);
}
}
}

}

My electrical engineering knowledge isn't very vast, but it seems like there is a simple solution that I am missing. Any help would be greatly appreciated. Thanks!

Unless you are using an VERY small motor the Arduino will not be able to drive it. Voltage is not the only reason we use a transistor, there's current as well.

Almost certainly your motor draws too much current and that in turn pulls the voltage down.


Rob

So there's no way to sufficiently power my motor without a transistor circuit? :frowning:

Not unless the motor only need about 20mA (very unlikely).

You can use more than 1 Arduino pin to beef things up a bit, do you have data for your motor?

I didn't even look at at the code because of this, but you can test it by removing the motor and using a LED and resistor.


Rob

My motor will need a few more amps than that. The omission of a transistor was simply due to laziness and frugality (and I suppose ignorance). I guess I'll have to get one tomorrow and redo my circuit...

Thanks again for the help!

For driving motors see:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

The omission of a transistor was simply due to laziness and frugality

Frugality?
http://www.radioshack.com/search/index.jsp?kwCatId=&kw=transistors&origkw=transistor&sr=1
$1.19 is a lot cheaper than f**king up the Arduino. And rat shack isn't the cheapest source of transistors.

Do you think I will be able to use the 9v I'm using to power my Arduino to also power my motor as well? In other words, will the 9v still be able to sufficiently power my Arduino if it is also powering a motor for a brief 3 seconds or so...?

It depends on what size (capacity) the battery is, if it is one of those small rectangular ones then be prepared to change it often.

I know this question is no longer in the right forum, but can you guys possibly help me? I have my motor hooked up to an NPN transistor, with the base being hooked up to the pin just like the schematic in the link posted above. This allows me to power my motor with a separate 9V battery. The pin outputs a HIGH voltage of about 4.5V to the base, but the motor barely goes. The transistor is 2N4401

You really, and I mean really, need to define what kind of 9V battery you are referring to.

If it is one of those rectangular 9V batteries, put it back in the smoke detector where it belongs, and get a real battery. 9V batteries put out practically no current - nothing like what is needed to make a motor go.

The pin outputs a HIGH voltage of about 4.5V to the base,

I assume that is going through a resistor, what value did you use?

I used 1K on the one I made before, so I used 1K again

Ok so one side of the resistor is 4.5V, the other side should be about 0.7V, have you measured this.
While you are at it measure the voltage of the battery when it is trying to power the motor.

Ok, for some reason now, the motor goes on for half a second and off for half a second over and over again when I connect the 9V to the positive end of the motor and ground. The arduino isn't even on, so nothing is going into the base. What's happening?

Without seeing the circuit, it's impossible to say how it will behave when the Arduino is switched off.

Also bear in mind that if you have tried to drive a motor directly from the digital output pins of the Arduino, you may have damaged the Arduino. It could have destroyed just the driver for that pin, or the whole power supply.

So have you taken the voltage measurements of the battery I asked you to?

Is there smoke? Heat? What motor is it?