monostable LED circuit using potentiometer and button (EDITED)

Hello, Im really new in arduino and need help. Im trying to do code for monostable circuit which is using button, LED and potentiometer. I want to set time LED will light using potentiometer from 1ms to 10ms. And when you press the button LED will light for the setted time. Engagement is ok but Im unable to make right code for this. Any suggestions please? Thanks.

(EDITED) I did not understood assigment properly. Sorry

You can not controll and LED using voltage. Read the pot and convert that value to the range 0-255 and use a PWM output of the controller. If You need more than 20 mA to the LED, use an N-channel logic MOSFET transistor.

Example code to light an LED using PWM set by a pot read with an analog input for 3 seconds when a momentary switch is closed. The switch is wired to ground and pin 4 digital input. The LED is wired Vcc-LED-1K resistor-pin 3 output. The pot is wired to Vcc, A0 and ground. The program uses millis() for timing.
Non-blocking timing (millis()) tutorials:
Several things at a time.
Beginner's guide to millis().
Blink without delay().

const byte potPin = A0;
const byte ledPin = 3;
const byte buttonPin = 4;

void setup()
{
   Serial.begin(115200);
   pinMode(buttonPin, INPUT_PULLUP);
   digitalWrite(ledPin, HIGH);
   pinMode(ledPin, OUTPUT);
}

void loop()
{
   int potValue = analogRead(A0);
   int pwmOut = potValue / 4;
   static unsigned long timer = 0;
   static boolean timing = false;
   unsigned long interval = 3000;
   
   if (digitalRead(buttonPin) == LOW && timing == false)
   {
      timer = millis();
      analogWrite(ledPin, pwmOut);
      timing = true;
   }
   if (timing == true && (millis() - timer >= interval))
   {
      digitalWrite(ledPin, HIGH);
      timing = false;
   }
}

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: