Turning LED off when light is shown

Hello,
I have managed to get everything to work for my project. When Pressure sensor is being pressed my LED flashes which is what I want it to do, though with my light sensor I can't get it to turn off when light is on it and i don't know how to make it on when it is dark and off when its light

Here is my code

// constants won't change
const int ANALOG_THRESHOLD = 340;

// constants that will change 
int light_sensor = A2;
int light_sensor_Value;
int ledPin = 10;

int fsrPin = A3;     // the FSR and 10K pulldown are connected to a0
int fsrReading;     // the analog reading from the FSR resistor divider

void setup() {
// initialize serial communication at 9600 bits per second:
 Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(light_sensor, INPUT);
  pinMode(fsrPin, INPUT);
}

void loop() {
//light_sensor_Value = analogRead(light_sensor); // read the input on analog pin2
//Serial.println(light_sensor_Value); // print out the value you read
  
  fsrReading = analogRead(fsrPin);  
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);     // print the raw analog reading
  
if (light_sensor_Value > 120) {
  digitalWrite(ledPin, LOW);
}
else if (fsrReading > ANALOG_THRESHOLD){
  digitalWrite(ledPin, HIGH);
  delay (100);
  digitalWrite(ledPin, LOW);
  delay (100) ;
  
  
}
  
  else {
    digitalWrite(ledPin, HIGH);
  }
    

  
delay(100); // delay in between reads for stability
  
}


  //light_sensor_Value = analogRead(light_sensor); // read the input on analog pin2

You have the reading of the light sensor pin commented out. Is that deliberate ?

yes it is, its so i can interchange the fsr and the light sensor when needed :slight_smile:

As your problem is

Do you think it would be better to post the code that does not work ?

Is this the same as the project about a scarf? If so where is the other thread and why are you posting this one? In fact is this the fourth topic on the same project when the first two had to be merged?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.