• 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 , increase blink rate in arduino , 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 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

This Article Has Been Shared 184 Times!

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

  • Securing Jumper Wire Connections : Prototyping Daugterboard

    Securing Jumper Wire Connections Is An Important Part Of Breadboard Wiring. Prototyping Daugterboard (Prototyping Shield) Can Help Securing.

  • Arduino Fingerprint Scanner Module GT-511C3, GT-511C1R

    Here is Arduino Fingerprint Scanner Module GT-511C3 or GT-511C1R Buying Guide and Basic Details On Unknown Matters Around Fingerprint Scanner.

  • Light Measurement With Arduino, LDR and LCD

    It is difficult to measure in light in Lux but possible to measure in unit. Here is How To on Light Measurement With Arduino, LDR and LCD.

  • Turn On LED in Dark With LDR and Arduino

    Turn On LED in Dark With LDR and Arduino. Very easy circuit diagram with minimum components. These basic projects with components are helpful to learn using sensor based logic.

  • Arduino LCD CPU RAM Monitor

    Here is How To Create An Arduino LCD CPU RAM Monitor So That The Values Can Be Seen With USB Connection Without Need of Looking Via GUI.

Additionally, 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 (22.1K 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

  • Big Data in Sports May 20, 2022
  • FaaS Versus PaaS Deployment: What You Should Know May 18, 2022
  • What Is A Digital Media Consultancy? May 17, 2022
  • How Artificial Intelligence (AI) Is Changing The Way We Play Bingo May 16, 2022
  • Why You Need A Big Data Consultant May 15, 2022

About This Article

Cite this article as: Abhishek Ghosh, "Arduino Blink LED Rate Depending On Push Button Press Duration," in The Customize Windows, September 7, 2018, May 20, 2022, https://thecustomizewindows.com/2018/09/arduino-blink-led-rate-depending-on-push-button-press-duration/.

Source:The Customize Windows, JiMA.in

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Privacy Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

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

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