Beginner help Potmeter

Hello !

Thanks for the time to visit this message!
I'm vary new to arduino but I have done some programming allready.

Hope some one can show me a way to code this.

Example

I want to use a sensor (Analglog input) to controll a output.
I know the analoginput read 0 - 1023.

How can I use this signal to example.

Signal read 400-500 = turn on a LED (or anything)
Signal read 700-1000 = turn on a realy

I cant find a way to use my input value , to turn on and off things.

Thanks ! :smiley:

Basically this.
I'll leave pin declarations & setup() to you.

void loop(){
if (analogRead(A0)>400){
//turn on LED
}
else {
// turn off LED
}
if (analogRead(A1)>700){
//turn on relay
}
else {
// turn off relay
}
}

I was looking on youtube and google, but all just make the code to read the value on serial and did not use the value to a simple task as turn something on and off.

I will try this out right away! Thank you!

CrossRoads:
Basically this.
I'll leave pin declarations & setup() to you.

void loop(){

if (analogRead(A0)>400){
//turn on LED
}
else {
// turn off LED
}
if (analogRead(A1)>700){
//turn on relay
}
else {
// turn off relay
}
}

How do I write the code to turn the realy on , only between 400-500. 400>500

if (X >= 400 && X <= 500)

GrooveFlotilla:
if (X >= 400 && X <= 500)

Thanks for the help! but its late and my brian works slow :smiley:

this is not working :smiley:

if (analogRead (potPin) (>=400) && analogRead (potPin) (<=500) digitalWrite (ledPin2, HIGH); else (digitalWrite (ledPin2, LOW)

Why do you read the pot twice?
That just wastes 200 microseconds.
Read it once and assign the result to a variable, then test that.

Please don't work Brian too hard.

this is not working

Does it even compile?

haha!

But I dont get it what to fill inn here.

if (analogRead (potPin) (?????) digitalWrite (ledPin2, HIGH); else (digitalWrite (ledPin2, LOW)

??????? = the value from 400 to 500 = HIGH anything else = LOW.

Keep up with me pleas :smiley:

No, how about you keep up with me?
Read the analogue pin and assign the result to a variable.

int potval = analogRead (potpin);

Now test potval instead of X, like I showed you in reply 4

Keep up with me was a joke sorry :slight_smile:

Yey!! It works now ! Thank you!! I'm so new to this, and did not even have a clue to use Potval.

GrooveFlotilla:
No, how about you keep up with me?
Read the analogue pin and assign the result to a variable.

int potval = analogRead (potpin);

Now test potval instead of X, like I showed you in reply 4

Last thing"

If i want to use more then one potmeter. Is this the way to keep it going.

int potPin = A0;
int potPin2 = A1; ?

int potval = analogRead (potPin);
int potval2 = analogRead ( potPin2); ?

Yes, that’s the idea, but as a beginner, there’s no better time than now to learn about arrays[]
This will let you write shorter, easier to understand code.