Led blink with potentiometer but without delay or millis

Hey guys so I have been trying but can not wrap my head around this,
Can we blink led with potentiometer and without delay or millis if yes pls help

If you are a newbie the answer is no
If you know something about the procesor you are using, then the answer is yes.

2 Likes

Yes,

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
 }

That code will blink the internal LED of a UNO without delays and millis(). The potentiometer is not needed but you can wire one in if you like.

See the one about using timers.

@Idahowalker Yes, in theory the LED 'blinks'(more on that in a moment), but not at a rate the user can discern.

@tanishq06 If you run the code @Idahowalker provides, the LED will appear, but somewhat dim compared to it's brightness if you just provide a constant high.

You ask about a potentiometer - what is it's purpose, in your mind? Changing blink rate, or changing LED brightness?

About the LED and the code - if you flip the output back and forth at the rate loop() can execute, the LED is changing state millions of times per second. Your eye cannot reliably discern an LED blink at much more than 40 Hz, IIRC. (I'm sure the data is out there on the web).
To blink a LED for the user to see, without delay(), millis(), or other software timing constructs, you'll need to discover the timer facilities built into the processor of your particular Arduino. So tell us, what have you got? A Nano? A Mega? An ESP32?

LED blinking discernment was not in the spec.

Also, I added a link to a "5 Different ways to Blink and LED using...", that has a possible solution.

Think frame rate of analog TV's with a 15Hz refresh for a good refresh rate. One of the old TV systems I worked on the refresh rate for no- see-the-blink was 7.5Hz. Any slower and the screen would flicker between refresh cycle.

That's conflated with phosphor persistence, though, so it's not a complete answer. That's how they got away with it; same with interlace, if you recall that term.

Anyway, this is irrelevant to the OP's question, and since he's not participating, I'm done.

Thanks for the reply , I have Arduino uno and i want to change the blink rate of the led


This is how my circuit looks

Post your code, please, in code tags.

Hello tanishq06

Use the BlinkWithOutDelay example of the IDE and exchange the millis() function against the micros() function.

Have a nice day and enjoy coding in C++.

OHHH Okay thanksss

As long as the professor will accept the use of micros()... I would mark it down if the course material covers hardware timers, PWM outputs and so on... then you are really expected to use those...

2 Likes

Hello tanishq06

Post the description of your homework.

Blink led light using potentiometer without delay or millis() .

In this case you have a proper solution :sunglasses:

Might get an 'F' for using micros();
I think the intent was to figure out how to use a timer.
It's shown in the wokwi writeup posted by @Idahowalker

1 Like

Can we see your attempt using millis() first? Or even, delay()?

so you are able to use the potentiometer as a simple switch. Therefore, switching back and forth will light on and light off the led accordingly.

Obviously not the answer your teacher is waiting for, but only cuz he lacks imagination :wink:

1 Like

Charge 47uF capacitor from an output pin through a 10k pot wired as a variable resistor in series with a 330Ω resistor , connect the resistor / capacitor junction to an analog input.
When the ADC value reaches 1000, set the output LOW, when it falls below 500, set the output HIGH.

byte ledPin = LED_BUILTIN, inPin = A0, outPin = 8;

void setup()
{
  //Serial.begin(9600);
  pinMode(ledPin,OUTPUT);
  pinMode(outPin,OUTPUT);
}

void loop()
{
  int val = analogRead(inPin);
  if(val > 1000)
    digitalWrite(outPin,LOW);
  else if(val < 500)
    digitalWrite(outPin,HIGH);
  digitalWrite(ledPin,!digitalRead(outPin));

}