[Solved] analogWrite() at 0 value still moves motor!

Hi, using the following code, from "0-255", it does increase speed the higher the value, but at value of "0" it still moves the AC servo "5" RPM.

int ledPin = 5;      // LED connected to digital pin 5
int val = 0;         // variable to store the read value

void setup() {
  pinMode(ledPin, OUTPUT);  // sets the pin as output

}

void loop() {
  analogWrite(ledPin, 0); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}

What Arduino PCB do you have ?

What is the voltage on the output ?

AC servo link ?


Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

Treat 0 and 255 as special cases and use digitalWrite(Pin, LOW) and digitalWrite(Pin, HIGH) for them

Using Arduino Uno. All details are in:

the drive takes analog of 0-10V, arduino has 0-5v, so was thinking whatever ill test with 5v yayks... is that why it doesnt stop completely at "0". Well i ask because a 0 is a 0 weather in 0-10v or in 0-5v.

Last time I looked, that is exactly what analogWrite does

Edit: Back at a PC now. Yup:

void analogWrite(uint8_t pin, int val)
{
	// We need to make sure the PWM output is enabled for those pins
	// that support it, as we turn it off when digitally reading or
	// writing with them.  Also, make sure the pin is in output mode
	// for consistenty with Wiring, which doesn't require a pinMode
	// call for the analog output pins.
	pinMode(pin, OUTPUT);
	if (val == 0)
	{
		digitalWrite(pin, LOW);
	}
	else if (val == 255)
	{
		digitalWrite(pin, HIGH);
	}
	else

No, Uno has no analog outputs. It has only PWM outputs, which switch between 0V and 5V with a frequency of ~500Hz or ~1000Hz. analogWrite() sets the "duty cycle" which is the % of time in each cycle that the signal is 5V.

What happens if you connect the AC servo input to 0V?

Do you have a common ground between the Arduino and the servo?

Driver moves servo 5 RPM

yes just like this:

Does that mean i need to use something like "DAC MCP4725"?

You need a true DAC capable of producing 0-10V.

do you know of a model number :slight_smile: i cant find

First Google result:

https://store.ncd.io/product/1-channel-0-10v-dac-digital-analog-converter-i²c/

would it be also ok to use a 0-5v DAC but amplify it to 0-10v, or would it give problems?

That is exactly what the board linked in post #11 does. Take a moment to read the board description.

And what is the servo supposed to do when it's input is 0V?

I'm pretty certain that using a DAC is not going to get your servo to stop if connecting it's input to 0V does not stop it.

:sweat_smile: :sweat_smile: ok back to square one, what is the solution to this problem?

Read the servo controller user manual.

how can i add a line of code saying, if volt = 0, then cutoff pin 5 completely!

int ledPin = 5;      // LED connected to digital pin 5
int val = 0;         // variable to store the read value

void setup() {
  pinMode(ledPin, OUTPUT);  // sets the pin as output

}

void loop() {
  analogWrite(ledPin, 0); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}

After reading the user manual, please answer this question:

Or post a link to the user manual. Perhaps forum members will read it, and explain it to you.

Why? When you disconnect the servo input completely, does the servo stop?

i just tried, it does keep spinning