Go Down

Topic: Re: When using analogWrite output only goes high 255 or low 0 -SOLVED (Read 687 times) previous topic - next topic


int     medpin = A5; //analog
int     motorlevel = 0;                // motor

pinMode(medpin, OUTPUT); // set pin a5 to output

//lets check if anything  should be turned on
//  - Check the value of M and if it is =1 then turn motor / fan on full (255)  or if M is =0 turn fan on mid speed (110)
if (Me > 1){

           if (readString.substring(Me,(Me+3)) == "M=1") { //motor has to be turned ON
             motorlevel = 255; / full  max
             analogWrite(medpin, motorlevel); // set the motor on

           else if (readString.substring(Me,(Me+3)) == "M=0") {
             motorlevel = 110;  //motor  should be set to or mid speed / dim
             analogWrite(medpin,motorlevel); // set the motorLED mid speed
                 // HTML CODE

          client.print(F("<form method=get name=LED>"));
          client.print(F("<input type='radio' name='M' value='1'>FAN HIGH<br>"));       // MAKE FAN GO FULL SPEED
          client.print(F("<input type='radio' name='M' value='0'>FAN MED<br><br>"));  // MAKE FAN GO HALF SPEED
          client.println(F("<input type=submit value=submit></form>"));
          client.println(F("<hr />"));

The above code turns the fan / motor on   or off  but does not make it go mid speed.... when i look at the voltage at the analog out pin 5 it goes to 4.92v  if M=1

but when M= 0  and the motorvalue gets set to 110 - the voltages stays the same .
If i set motorvalue to 0 or a very low figure then the voltage drops to 0.

What gives?


analogWrite uses the PWM pins. A5 isn't one of them.

Check the documentation for analogWrite.

On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Feb 09, 2012, 02:50 pm Last Edit: Feb 09, 2012, 05:01 pm by joeman Reason: 1
Thanks for the pointer Nick,

I switched the pin to  pin 9,  modified int to = pin 9 and its working fine now.

I had it plugged in an Analog input......pin...oops...


Go Up