Loading
Loading
IoT Lab content is currently available in Arabic only. We're working on an English version.
عرض بالعربية →Arduino can't output 3 volts — only 0 or 5. So how do we gradually control LED brightness?
Connect the LED to pin 9 (or 3, 5, 6, 10, 11) through a resistor.
void setup() {
pinMode(9, OUTPUT);
}
void loop() {
// تدرج الإضاءة من 0 (مطفأ) إلى 255 (أقصى إضاءة)
for(int i = 0; i <= 255; i++) {
analogWrite(9, i);
delay(10);
}
}Using analogWrite() on a pin without the (~) symbol — the LED won't dim gradually but will suddenly turn on and off.