// #include "UBL.h"
int Red_LED = A0;
int Yelow_LED = A1;
int Green_LED = A2;
#define TRIGGER_PIN 9 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 8 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
void setup() {
// put your setup code here, to run once:
//pinMode(13,OUTPUT);
//digitalWrite(13, HIGH);
//delay(1000); // 1000 = 1 sec.
//pinMode(A0,OUTPUT);
//digitalWrite(A0, HIGH);
//delay(1000); // 1000 = 1 sec.
//pinMode(A1,OUTPUT);
//digitalWrite(A1, HIGH);
//delay(1000); // 1000 = 1 sec.
//pinMode(A2,OUTPUT);
//digitalWrite(A2, HIGH);
//delay(1000); // 1000 = 1 sec.
// #include <NewPing.h>
void setup() {
Serial.begin(9600); // Open serial monitor at 115200(or 9600) baud to see ping results.
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
int l = sonar.ping_cm();
if (l > 5 ) {
digitalWrite(A0 , 0);
else {
digitalWrite(A0 , 1);
}
}