79321059

Date: 2025-01-01 02:02:30
Score: 0.5
Natty:
Report link

If I'm understanding your problem correctly, you want ledPin to be turned on when you run your sketch, correct?

Looking at your logic in sensor() it seems that you want ledPin to turn off when sensorPin is triggered. In this case it would make sense for you to set ledPin to HIGH in your setup function.

It can look something like this:

void setup() {
  pinMode(ledPin, OUTPUT);
  // Setting ledPin to on by default:
  digitalWrite(ledPin, HIGH);
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
  delay(2000);
  Serial.println("Available! Give command ('on' or 'off').");
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: K.Sx0000