• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Arduino Blink LED Rate Depending On Push Button Press Duration

By Abhishek Ghosh September 7, 2018 11:06 pm Updated on September 7, 2018

Arduino Blink LED Rate Depending On Push Button Press Duration

Advertisement

We Can Use millis() To Perform Many Things Without Using the delay() Function. We can code to read a push button to determine the rate at which the LED should blink. In that system, if we hold the push button down for x milliseconds, the LED will blink on and off every x milliseconds. Here is Arduino Blink LED Rate Depending On Push Button Press Duration Guide With Circuit and Code. For our regular readers, just for recall with Arduino and basic coding, we already have some similar guides like :

  1. LED Blink Rate Control With LDR
  2. Blink LED and Beep Every X Seconds Upon Push Button Press
  3. Flip-Flop Blinking LED With Push Button
  4. Blink LED With Pushbutton Control to Turn ON and Off

In most of those guides, our basis is this example guide on millis() :

Vim
1
https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

More newer users can check official guide on just control of one LED with push button :

Advertisement

---

Vim
1
https://www.arduino.cc/en/Tutorial/Button

 

Code And Connection To Blink LED Rate Depending On Push Button Press Duration

 

We can connect LED to Pin 13 of Arduino and push button to Pin 6 of Arduino and run this code :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int ledPin = 13;
int ledValue = LOW;
long ledStartTime = 0;
long ledBlinkInterval = 1000;  
 
int buttonPin = 6;  
int buttonValue = HIGH;
long buttonPressTime = 0;  
 
 
void setup()
{
pinMode(ledPin, OUTPUT);
}
 
void loop()
{
buttonValue = digitalRead(buttonPin);
if (buttonValue==LOW && buttonPressTime==0) {
   buttonPressTime = millis();  
}
if (buttonValue==HIGH && buttonPressTime!=0) {
   ledBlinkInterval = millis() - buttonPressTime;  
   buttonPressTime = 0;  
}
if (millis() - ledStartTime > ledBlinkInterval) {
   ledStartTime = millis();
   if (ledValue == LOW)
     ledValue = HIGH;
   else
     ledValue = LOW;
 
   digitalWrite(ledPin, ledValue);
}
}

Arduino Blink LED Rate Depending On Push Button Press Duration

What the code is doing? First, we are telling that the LED is connected to digital pin 13, LOW is the previous value of the LED. ledStartTime will store last time LED was updated. ledBlinkInterval is the interval at which to blink. Then we have set a momentary pushbutton on pin 6, stating HIGH is the current state of the button. In void setup(), we have set the LED pin as output.

In void loop(), from the line buttonValue = digitalRead(buttonPin);` we are checking if the button is pressed and mark the time upon press and when is released. From that calculate how long it was pressed. Then carry the value to make the led to blink at the same rate.

Tagged With arduino blink led with button , arduino blink led during button press , how to press button and led will turn on and second will blink in arduino , change led blink rate if push button is held , blink rate led sensor arduino , blink led using push button , blink led once after button pressed arduino , arduino led blink speed push button , arduino change an led based on button press , rate at which button is pressed arduino
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Arduino Blink LED Rate Depending On Push Button Press Duration

  • Arduino Blink LED With Pushbutton Control to Turn ON and Off

    Arduino Blink LED With Pushbutton Control to Turn ON and Off is Few Steps Higher Than Basic Example. There is Matter of Repeat Checking by Microcontroller.

  • Arduino and LED Bar Display : Circuit Diagram, Code

    Here is a Guide Explaining the Basics, Circuit Diagram, Code on Arduino and LED Bar Display. LED Bar Display is Actually Like Multiple LED.

  • Arduino 3 LED and One Push Button

    We can control more than 2 LEDs with one push button. Here is Arduino Project on How to Control 3 LED With One Push Button.

  • Arduino : One Push Button Multiple Functions (Single Press, Double Press, Long-Time Press)

    With Arduino, We Can Have One Push Button Multiple Functions Like Single Press, Double Press, Long-Time Press. There is Nice Library For Faster Prototyping.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy