Skylar Jones
Published

DIY LED Blinking Circuit

This project demonstrates the use of an Arduino UNO, a potentiometer, a push button, and an oscilloscope to control the brightness.

BeginnerFull instructions provided166

Things used in this project

Story

Read more

Schematics

20241106130901_qD07DM7woY.png

Code

Untitled file

Arduino
const int potPin = A0; // The potentiometer is connected to analog input A0
const int buttonPin = 2; // The push button is connected to digital input pin 2
const int ledPin = 3; // The LED is connected to digital output pin 3

void setup() {
    pinMode(ledPin, OUTPUT); // Set the LED pin to output mode
    pinMode(buttonPin, INPUT); // Set the push button pin to input mode
}

void loop() {
    int potValue = analogRead(potPin); // Read the value of the potentiometer (0-1023)
    int ledBrightness = map(potValue, 0, 1023, 0, 255); // Map the value of the potentiometer to 0-255

    if (digitalRead(buttonPin) == HIGH) {
        analogWrite(ledPin, ledBrightness); 
        delay(500);
        analogWrite(ledPin, 0);
        delay(500);
    }
    else
        analogWrite(ledPin, ledBrightness); 
}

Credits

Skylar Jones

Skylar Jones

12 projects • 0 followers
Customer Success: Your one-stop solution for PCB and PCBA services, plus component sourcing. Enjoy FREE online simulation and EDA.

Comments