line sensor (qrb1114( and led

hi

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);
}

What fruit works?

But anyway:

int const senpin = 2;
...
  if (senpin == 0) {

I don't think you really meant to compare the pin number to 0 did you?

Steve

hi steve

im very new to coding, it is part of my degree. however i do not know what a fruit is or what i should put instead in the if else command

georgia

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.

Steve