// constants won't change. Used here to set a pin number: const int buttonPin = 3;//the number of the pushbutton pin const int ldrPin = A2;//the number of LDR pin const int ledPingreen = 8;// the number of the greenLED pin const int ledPinred = 7;// the number of the redLED pin // Variables will change: int ledState = LOW; // ledState used to set the LED int buttonState = 0; int sensorValue = 0; // variable to store the value coming from the sensor int value = 0; void setup() { // put your setup code here, to run once: // set the digital pin as output: pinMode(ledPingreen, OUTPUT); pinMode(ledPinred, OUTPUT); // set the digital pin as input: pinMode(buttonPin, INPUT); pinMode(ldrPin, INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { // read the value from the sensor: sensorValue = analogRead(ldrPin); value = map(sensorValue,0,1023,0,100); if ( value>50) { // put your main code here, to run repeatedly: digitalWrite(ledPingreen, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(ledPinred, LOW); // turn the LED on (HIGH is the voltage level) delay(1000); } else { // put your main code here, to run repeatedly: digitalWrite(ledPingreen, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(ledPinred, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); } } else { digitalWrite(ledPingreen, LOW); // turn the LED off by making the voltage LOW digitalWrite(ledPinred, LOW); // turn the LED off by making the voltage LOW } // wait for a second }