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.

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 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


This article provides a comprehensive guide on using CMake and rosserial_client to compile and upload code to Arduino for larger Arduino projects, offering an alternative to the Arduino IDE. The


In this comprehensive tutorial, we will provide a detailed exploration of various Arduino boards, delve into essential concepts, and highlight their distinctive features. Our aim is to assist you in


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


This article will explore the fundamental principles of controlling stepper motors with Arduino, providing code examples to guide readers step by step in mastering precise motor control and ultimately achieving


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


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


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


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