Motor rate

Breadboard layout of motor circuit. I used a PN2222 transistor to change the voltage that the motor receives. The Base is connected to the motor’s ground, the collector to pin 3 and the emitter to ground and a diode for when the motor shuts down. The pots was connected to A0.


Arduino sketch


int analogInPin = A0;
int sensorValue = 0;
int outputValue = 0;
int transistorPin = 3;

void setup() {

pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(transistorPin, OUTPUT);

void loop() {
sensorValue = analogRead(analogInPin)/4;
outputValue = map(sensorValue, 0, 1023, 0, 255);

analogWrite(transistorPin, sensorValue);

if (sensorValue >= 160) { //example
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
} else {
digitalWrite(9, HIGH);
digitalWrite(8, LOW);



Here’s the circuit in action.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s