Hi! I am new to Arduino and I’m trying to make a LED turn on for a certain time (delay) that is set by a potentiometre. I want to use à potentiometre in order to choose the delay. After this delay is reached i want it to turn off for a set time as well controled by a second potentiometre before turning back on in a loop. I am guessing this must be done usine millis() but i have no clue how nor what configuration of wiring i have to set up… can someone help me on that?
What part are you having trouble with ?
Hi! I’m having a trouble with the entire project actually… I tried making a simple code with a potentiometre changing the state of a LED but i can’t find any explanations on how to use a potentiometre to change the delay of activity of the LED. (make the LED on for 30 sec for then turn of for 10sec for example) but with the variables (seconds) being changed by potentiometres.
That’s not much to work with is it ?
Start with sharing what code you have tried to get to work.
In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.
BTW
Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.,
Hello stillnew
You may start with the BLINKWITHOUTDELAY example of the IDE.
This will gain the knowlwdge how to build an Arduino timer.
Which Arduino? How are the pots wired? How is the LED wired?
If this is your first attempt at programming, I'd start with the 'Blink' example: File -> Examples -> 01.Basics -> Blink
// the setup function runs once when you press reset or power the board
void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop()
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Then you can change the 1000 millisecond values passed to the 'delay()' function from literals to variables:
unsigned long OnTime = 1000;
unsigned long OffTime = 1000;
// the setup function runs once when you press reset or power the board
void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop()
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(OnTime); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(OffTime); // wait for a second
}
That will do exactly the same thing. Then follow the Analog Read Serial tutorial for the potentiometers:
After that you just need to map your analog input values (0-1023) into the times you want to be able to select, say 100 to 5000 milliseconds (0.1 to 5 seconds). Check out the map() function for that:
or use basic math with addition, subtraction and multiplication.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.