im trying to use a if else command and a line sensor to turn a led on and off.
I know the fruit works and all the pins are correct but i still can not get it to work
int const ledpin = 13;
int const senpin = 2;
void setup()
{
Serial.begin(9600);
pinMode ( senpin, INPUT);
pinMode ( ledpin, OUTPUT);
}
void loop()
{
if (senpin == 0) {
digitalWrite(ledpin, HIGH);
} else {
digitalWrite(ledpin, LOW);
}
Serial.println(digitalRead(senpin)); // print the data from the sensor
delay(500);
}
It was you who said "I know the fruit works...". I just wondered what you meant.
As for the if statement, don't you want to check the VALUE on that pin? Not the pin NUMBER? It's done correctly a few lines later in the Serial.println().
Did you actually write that code or just copy it from somewhere without understanding it? It's not a real problem if you did, many of us start out that way. But it helps if you mention it because the assistance needs to be at a different level if you're not asking about code you've put some thought into yourself.