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

Table of Contents

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.

More content you may be interested in

How to Enable Multi-Core on ESP32 Microcontroller
How to Enable Multi-Core on ESP32 Microcontroller

This comprehensive guide elucidates the process of enabling multi-core functionality on the ESP32 microcontroller, leveraging its dual-core architecture for enhanced parallel processing capabilities. Through detailed

Arduino MQ-3 Alcohol Sensor Project
Arduino MQ-3 Alcohol Sensor Project

Creating an alcohol sensing project with an MQ-3 sensor and Arduino allows for accurate alcohol concentration monitoring in environments like bars and factories. The MQ-3

Arduino Temperature Alarm Project
Arduino Temperature Alarm Project

This Arduino temperature alarm project effectively demonstrates how to create a practical temperature monitoring system. By utilizing the LM35 temperature sensor and a buzzer, it

Arduino Breathing LED Project
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

Scroll to Top