Go Down

Topic: Arduino DC Motor squeal (Read 1 time) previous topic - next topic

rs3973

Hi, lately I've been having problems with a DC motor I have hooked up to my Arduino board. The motor is running on a circuit with a PN2222 transistor that is being controlled by a photocell (if the photocell reading is above 300, the motor turns on). However, when the motor turns on, all I hear is a high-pitched squeal or chime. A few weeks ago, to use the board for something else, I took the circuit apart. At that time, the motor was functioning properly. The original problem was that the power was coming from the USB cable, so I connected a 9V to Vin and that fixed the problem. Right now, I can't find any solution to the problem. I would appreicate any comments or suggestions.

This is my code:

Quote

int motor = 3;
int photocell = 1;
int photocellValue;

void setup() {               
  // initialize the digital pin as an output.
  pinMode(motor, OUTPUT);
  pinMode(photocell, INPUT);
  Serial.begin(9600);
}

void loop() {
  photocellValue = analogRead(photocell);
  if (photocellValue > 300) {
  analogWrite(motor, 10);
  }
  else {
    analogWrite(motor, 0);
  }
}


MAS3

Hi.

Is that all code ?
You're currently using pin 3 to send a PWM signal to your motor.
Can you change that to pin 5 or 6 ?
Pins 3, 9, 10, and 11 send PWM at a frequency of 31250 Hz.
That is well beyond audible (supposed to be max 22000 Hz).
But pins 5 and 6 are on a frequency of 62500 Hz, twice that of the other pins.

PWM frequency can be set to an other, lower value, but that has other consequences which will complicate things.
And you do not want to go lower.

The start value of 10 might be too low to get your motor started.
A motor needs a higher current (you're using current to control the speed here) to start.
Try to increase it a bit and see what happens.
I suspect a value of about 30 % to be a good start value.
If you need a lower speed, perhaps you could start higher and the decrease a little bit.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

MarkT

No, the standard AVT Arduino's use a much lower frequency, 500Hz and 1kHz approximately - you would
typically reconfigure a timer to get faster PWM.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

raschemmel

Quote
the standard AVT Arduino's use a much lower frequency, 500Hz and 1kHz   


As explained here:
http://arduino.cc/en/Reference/analogWrite 

MAS3

Oops, so i dug up some incorrect info from this site (or rather didn't interpret it correctly), using Google's first result.
Sorry for that.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

rmetzner49

Quote
Hi, lately I've been having problems with a DC motor I have hooked up to my Arduino board. The motor is running on a circuit with a PN2222 transistor that is being controlled by a photocell


Please post a schematic showing your motor connections including how you power the Arduino, the motor and the 2N2222.  Without a road map, it's difficult to guess where  the problem is.

Go Up