Go Down

Topic: analogWrite not working (Read 781 times) previous topic - next topic

DrugMile

Hi, I'm new to Arduino world. I'm using Arduino Micro with 1.6.9. IDE. All simple examples I did without any problem, i.e. reading analog inputs, connecting LCD, controlling LEDs etc.

PROBLEM: I connected LED to pin with PWM function, I declared this pin as OUTPUT, and wrote some analog value to it, i.e.

Code: [Select]

  pinMode(11,OUTPUT);
  analogWrite(11,200);
}


...but I get on this pin full 5V, tested with multimeter, and LED lits with full intensity. When I change analog value to i.e. 50, I get 0V on pin11 and LED goes off. Then I noticed that when I remove pinMode line from the code (first line in my example), this pin works as it should, and I can control LED intensity. In reference I found that it is not necessary to declare a pin as an OUTPUT, but I did not found that you *must not* declare it as OUTPUT if you want to use PWM.

Now my program is working as it should, but I'm curious if I'm doing something wrong? I found many examples where people use analogWrite after declaring pin as OUTPUT, so it seems that I'm the only one who can not do it?

AWOL

#1
Aug 11, 2016, 01:47 pm Last Edit: Aug 11, 2016, 01:49 pm by AWOL
We can't see your code.

Quote
..but I get on this pin full 5V, tested with multimeter
What about using an oscilloscope?

Go Up