Hello, i'm working a simple project using sensor Ping to control two relays that connected to heater and UV light.
so if we put hand in front of sensor, blower and UV light will turning ON at the same time, otherwise will off.
i want to modify the sketch
there must be a delay 4 seconds between UV and blower, so first UV will on, wait 4 second, and blower will on.
but there is a problem. when no longer hand in front of the sensor, UV and blower also turning off in 4 seconds delay.
i want to make the UV and blower turn on with delay, but i want to make them off at the same time.
here is the sketch
//------------ultrasonic----------
int trigPin = 7;
int echoPin = 8;
//-----------motor---------------
int uv = 11;
int led1 = 12;
int motor = 13;
void setup() {
Serial.begin (9600);
//-----------ultraxonic---------------
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
//-------------motor-------------------
pinMode(uv, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(motor, OUTPUT);
}
void loop() {
//----------------ultasonic---------------
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(4);
digitalWrite(trigPin, HIGH);
delayMicroseconds(50);
delayMicroseconds(4);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29;
if (distance >= 2 && distance <= 20){
// Serial.println("Out of range");
//-------------motor----------------
digitalWrite(uv,HIGH);
delay(4000);
digitalWrite(motor,HIGH);
}
else {
digitalWrite(motor,LOW);
digitalWrite(uv,LOW);
}
}