Arduino Breathing LED Project

A breathing light is an LED lighting effect that simulates the human breathing process, gradually increasing or decreasing in brightness within a specific cycle. This project can be achieved through a microcontroller or LED control circuit. In this article, we will use an Arduino program to control the LED’s PWM signal, incrementing and decrementing the PWM value to achieve the fading effect.

arduino breathing led

Required Components and Wiring

  • 1 × Arduino UNO R3 (with a matching USB data cable)
  • 1 × Breadboard
  • 2 × Colored jumper wires
  • 1 × 5mm LED light
  • 1 × 220-ohm resistor

Arduino breathing LED wiring diagram

Arduino Breathing LED Project Code

				
					int ledPin = 10;
void setup() {
  pinMode(ledPin, OUTPUT);
}
void loop() {
  fadeOn(1000, 5);
  fadeOff(1000, 5);
}
void fadeOn(unsigned int time, int increment) {
  for (int value = 0; value <= 255; value += increment) {
    analogWrite(ledPin, value);
    delay(time / (255 / increment));
  }
}
void fadeOff(unsigned int time, int decrement) {
  for (int value = 255; value >= 0; value -= decrement) {
    analogWrite(ledPin, value);
    delay(time / (255 / decrement));
  }
}

				
			

Code Explanation

int ledPin = 10;: This line defines an integer variable ledPin to store the pin number to which an LED is connected on the Arduino. In this case, it’s connected to pin 10.

void setup(): This is the setup section of the Arduino program, executed once at the beginning. In this setup, we set the ledPin to an output mode, allowing us to send PWM (Pulse Width Modulation) signals to it.

void loop(): This is the main loop of the Arduino program, continuously repeating. In this loop, we alternate between two functions for creating the breathing LED effect: fadeOn (gradually increasing brightness) and fadeOff (gradually decreasing brightness).

void fadeOn(unsigned int time, int increment): This is a custom function for gradually increasing the LED’s brightness. The time parameter represents the total transition time in milliseconds, and the increment parameter indicates the brightness increment at each step.

  • Inside a loop, it starts from the LED’s current brightness and gradually increases it.
  • It uses the analogWrite function to control the LED’s brightness by writing a value to the LED pin.
  • The delay function controls the time between each increment to complete the transition within the specified total time.

void fadeOff(unsigned int time, int decrement): This is another custom function similar to fadeOn, but it gradually decreases the LED’s brightness, achieving a gradual dimming effect.

You Might Be Interested

Arduino Nano Pinout Guide
A Comprehensive Guide to Arduino Nano Pinout

This article will explore the Arduino Nano’s pinout, explaining each pin’s function and providing practical insights on how to effectively use them in your DIY projects—whether you’re working with digital

What is Arduino UNO
What is Arduino UNO?

Unlock the power of Arduino UNO! This versatile development board lets you build everything from automated systems to robots. Explore its features and discover how it can turn your creative

Arduino Proximity Detector Project
Arduino Proximity Detector Project

This Arduino project utilizes the Keyes Infrared (IR) Proximity Sensor Module to create a proximity detector. When an object is detected within a certain range, an HW-480 Red/Green 2-Colour LED

Guide to Arduino LCD
Guide to Arduino LCD Display with 3 Project Examples

This comprehensive guide explores how to use Arduino with LCD displays, covering essential concepts and pin configurations. It includes three practical projects: basic text display, dynamic number updates, and real-time

How to Download and Install Arduino IDE
How to Download and Install Arduino IDE

Learn how to easily download and install the Arduino IDE on Windows, Linux, and macOS! This step-by-step guide will walk you through the entire process, from downloading the software to

Scroll to Top