Jeff-Paredes
Published © Apache-2.0

LED With Arduino 101

Learn how to light a LEDs using Digital Write and AnalogWrite on Arduino 101!

BeginnerProtip1 hour4,530
LED With Arduino 101

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
Resistor 221 ohm
Resistor 221 ohm
×1
LED (generic)
LED (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Alternate Blink LED Circuit

Code

Blink LED

C/C++
Turns on an LED on for one second, then off for one second, repeatedly.
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
*/

int ledPin = 13;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin ledPin, as an output.
  pinMode(ledPin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

AnalogWrite.ino

C/C++
Increase and Decrease brightness of LED
/*
  Blink
  Increase and Decrease brightness of LED
*/

int ledPin = 9;                 // LED connected to digital pin 13
int val = 0;                    // brightness (0 ~ 255)
bool onLed = true;              // increase or decrease brightness

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  if(onLed)
    val++;                      // increase brightness
  else
    val--;                      //decrease brightness
  
  
  analogWrite(ledPin, val); 
  
  if(val==255)
    onLed = false;              // turns off LED
  else if(val==0){
    onLed = true;               // lights on LED
    delay(1000);                // waits for a second before on again
  }
    delay(10);
}

Credits

Jeff-Paredes

Jeff-Paredes

1 project • 126 followers
Programming is my love and engineering is my third party :)

Comments