Professional Documents
Culture Documents
int rel_ch2 = 10; //output pin for relay board channel-2 IN2;
void setup() {
// Serial.begin (9600);
pinMode(trigPin1, OUTPUT); //from where we will transmit the ultrasonic wave
(left)
pinMode(echoPin1, INPUT); //from where we will recive the feedback (left)
if (distance3 > 20 && distance4 > 20) { // Change the number for long or short
distances according to your need.
digitalWrite (rel_ch1, HIGH);
digitalWrite (rel_ch2, HIGH);
digitalWrite (fan1, HIGH);
digitalWrite (fan2, HIGH);
} else {
digitalWrite (rel_ch1, LOW);
digitalWrite (rel_ch2, LOW);
digitalWrite (fan1, LOW);
digitalWrite (fan2, LOW);
}
}
if (distance1 > 20) { // Change the number for long or short distances according
to your need.
digitalWrite (rel_ch1, HIGH);
digitalWrite (fan1, HIGH);
} else {
digitalWrite (rel_ch1, LOW);
digitalWrite (fan1, LOW);
}
}
if (distance2 > 20) { // Change the number for long or short distances according
to your need.
digitalWrite (rel_ch2, HIGH);
digitalWrite (fan2, HIGH);
} else {
digitalWrite (rel_ch2, LOW);
digitalWrite (fan2, LOW);
}
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("\n");
bothsensor();
firstsensor();
secondsensor();
delay(100);
}