Fading LED with timer

I´m trying to make several LEDs fade to a timer with a button, so far all I´ve been able to do is make the LED HIGH for a set period off time but I can´t seem to make it fade as well. Any help is appreciated:D

int ledPin = 2;                
int inputPin = 3;               
int val = 0; 
int timer= 3000;

void setup() {
  pinMode(ledPin, OUTPUT);      
  pinMode(inputPin, INPUT);     

void loop(){
  val = digitalRead(inputPin);  
  if (val == HIGH) {            
    digitalWrite(ledPin, LOW);

  else {
    digitalWrite(ledPin, HIGH); 


I think this is why the arduino.cc site has a "Learning" section, with various tutorials on the basics. :slight_smile: Work through the examples diligently, you'll learn a lot.

Yeah I know I tried using that but I couldn´t get it to work

You can't get what working? The tutorial exactly as shown, or applying the concept of PWM fading into your own program?

Start with following the exact circuit and code in the Fading example. Does that work?