Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int trig = 9;
- const int echo = 10;
- long duration;
- int distance;
- int photoSensor = A3;
- int photoSensorValue;
- int led = 3;
- void setup(){
- pinMode(trig, OUTPUT);
- pinMode(echo, INPUT);
- pinMode(led, OUTPUT);
- pinMode(photoSensor, INPUT);
- Serial.begin(9600);
- }
- void loop(){
- digitalWrite(trig, LOW);
- delayMicroseconds(5);
- digitalWrite(trig, HIGH);
- delayMicroseconds(10);
- digitalWrite(trig, LOW);
- duration = pulseIn(echo, HIGH);
- distance = duration*0.034/2;
- //DEBUG
- Serial.print("Distance: ");
- Serial.println(distance);
- Serial.print("Photosens: ");
- Serial.println(photoSensorValue);
- photoSensorValue = analogRead(photoSensor);
- if(distance >= 150 && photoSensorValue < 40){
- Serial.print("LIGHT");
- digitalWrite(led, HIGH);
- delay(1000);
- }else{
- digitalWrite(led, LOW);
- delay(200);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement