Help me with this problem!

i need some help with this project! i’m really confused by it and would appreciate some guidance, schematics and code wise! thanks.

What parts of it can you work out on your own?
Do you know how to connect an LED and turn it on and off in a program?
Do you know how to connect and read the state of a button?
Do you know how to connect and read a potentiometer?
If not, answer these questions first.
When is this assignment due?

1 Like

Welcome arduinoguy14, this should be an interesting exercise for you. I would suggest you get a copy of the Arduino Cookbook and read it. I feel confident that by the time you finish you will have built your circuit and be able to explain exactly how it is put together and working. Read the first two chapters, then go to the index and read what appears to solve parts of your problem. This will help your understanding of what is possible with the hardware and software. This will not be a one or two day read!

I can connect and use a potentiometer to control the brightness of an LED, where i run into issues i think is mapping out the values to get 4volts and then decided what to use to trigger the light after 4 volts. I’m thinking something like an if conditional but all i have tried hasn’t worked

Will do, the project is semi time sensitive, but i will try to get it done as fast as possible! any other advice?

The max value is 5V, what number does that return?
The minimum value is 0V, what number does that return?
Calculate from there what the percentage 4V is, and then apply that percentage to the representative values.

1 Like

do you mean from the value on the potentiometer? if so, 820 is roughly 4/5 of 1023

There you go.
You need a variable to record of the read value exceeds 820. That same variable can be reset by pressing the button.
That variable should represent the state of the LED.

1 Like

so something in the realm of

if (readValue >= 820){
digitalWrite(ledPin, HIGH)

after i have defined the value read from the potentiometer as readValue and whatever pin i use at my output as ledPin?

Separate the ideas
If the value is met change the state of a variable.
That way it doesn't change back if the value goes below 820.
The push of the button can change it back.
Each iteration set the LED based on this state.
I'm happy to help more but I'd like you to write a sketch that compiles before I look at it again.

1 Like

got it! I’ll work on it, all the help is appreciated.

Reading and trying are the some of the keys to getting the best help here.
I'll check back tomorrow morning.

1 Like

morning! this is what i came up with last night. from my initial testing this program works! the light turns on at a certain point on the pot, and only turns off when i press my external reset. what do u think?

Please read this to learn how to post code:

I'll check back when I have my coffee :slightly_smiling_face:

// constants
const int POT_PIN   = A0; // Arduino pin connected to Potentiometer pin
const int LED_PIN             = 13; // Arduino pin connected to LED's pin
const float VOLTS_LIMIT = 4; // Voltages

//setup- defining pinMODE
void setup() {
  pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode
void loop() {
  int analogValue = analogRead(POT_PIN);      // read the input on analog pin
  float voltage = floatMap(analogValue, 0, 1023, 0, 5); // Rescale to potentiometer's voltage

  if (voltage > VOLTS_LIMIT) //if the voltage is greater than set limit
    digitalWrite(LED_PIN, HIGH); // turn on LED_PIN

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;

apologies! this is my first post here, hows this look?

1 Like



 float voltage = floatMap((float)analogValue, 0.0, 1023.0, 0.0, 5.0); // Res

So much better. I'll read it now.

Are you required to use floats? It slows things on a lot of Arduino models.

no, it is not a requirement. would you suggest sticking to integers?

Indeed, just check the read value against your number 820 from a previous reply.