I'm not too familiar with Arduino's but I'm very interested to get involved with them as I would like to build my own projects!
The circuit that I have built is shown below:
I am trying to control 3V DC motor using the PWM pins on the Arduino. I'm using an LDR in a voltage divider to provide an analog input into the A0 pin. The code I'm using is provided below:
int sensorPin = A0; // select the input pin for the voltage read from sensor
int motorPin = 9; // select the pin for the motor
int sensorValue = 0; // variable to store the value coming from the sensor
int val = 0;
void setup() {
//set the pin mode for the motor to be an output
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
//Print the value read on A0 into the serial monitor.
Serial.print(sensorValue);
Serial.print(' ');
delay(1000);
//sensorPin ranges between 0 -> 1023 so val ranges between 0 -> 255.
val = sensorPin/4;
//Motor speed changes relative to the value read at A0.
analogWrite(motorPin, val);
}
THE PROBLEM:
I can't see what is wrong with the circuit but the output voltage from the PWM pin 9 always seems to be roughly 0.05V and the VCC voltage 3.3V is all being dropped across VCE. Therefore I have concluded that there is no current flowing through the transistor.
I am not sure how to solve this problem.
Thanks for any help!