The most glaring error is that you do an analog write of 0 to the LED's pin, then you enter an infinite loop in which ALL you do is cycle the value of a variable. I see you finally posted your code, and yes, I do see something wrong with it. You will be doing damage to your LED and to the AVR micro on the Arduino. When your LED begins to light, any more voltage applied will cause more current to flow, keep increasing it, and the current goes VERY high while the voltage remains just above the point where it started lighting.īecause of this, it is NOT a good idea to remove the resistor, as it will cause a very large current to flow through the LED and worse, through the output circuit of the pin on the Arduino, likely a lot more than it's rated maximum current. But you are putting it across an LED, and the LED is a non-linear device that will limit the voltage to somewhere just above 2 Volts (more or less depending on the LED (Blue and white take more voltage, red takes a little less). When you send a PWM of 255, you would get a reading of 5V if you were putting it across a resistor. You are trying to read a digital signal that is going on and off, and your DC meter will not give you a meaningful value. The way a PWM signal changes brightness on an LED is that it switches the LED on and off, and the longer it is on in each PWM cycle, the brighter it seems. You can use a resistor/capacitor filter on the output, to end up with a variable voltage. 0)īut when I tried this in arduino program my led didnt emit any light.ĭoes anybody knows whats wrong with this code? or can anybody rewrite the fading program with using "for". I wrote this and it works well in C++ program (the output is 0 5 10 15. Shouldn't it be 5 V?Īlso I tried to make the fading program with for. I removed the resistor and directly connected led with my arduino ( to get higher voltage and brightness and my led still works well) but when I measure the voltage between the legs of my led i get 2.75 V. I set my brightness (pwm) to 255 (maximum value) and I wanted to control my led brightness with changing it's voltage between 0 to 5v.Īs I read in arduino website with its pwm control it can simulate the voltage between 0 and 5 v (analogwrite(255) for 5 v and analogwrite(0) for 0 v) First of all I must say i am very new in Arduino, and sorry for bothering with such a simple question.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |