HI,
I am new to Arduino. I was wondering if someone could help me with the code for a project I am working on.
I am using a ping sensor to control an LED pin, and found this code online:
#define fP 7 //ping sensor pin
void setup ()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop ()
{
if (ping() < 70)
{digitalWrite(13, HIGH); //set LED on
}
else
{
digitalWrite(13, LOW); //set LED off
}
}
int ping() //get CM to obstacle in front of the sensor
{
long duration;
pinMode(fP, OUTPUT);
digitalWrite(fP, LOW);
delayMicroseconds (2);
digitalWrite(fP, HIGH);
delayMicroseconds (15);
digitalWrite(fP, LOW);
delayMicroseconds (20);
pinMode(fP, INPUT);
duration = pulseIn(fP, HIGH);
return duration / 29.0 / 2.0;
}
This is great for me to get started with, but I was wondering if someone could help me figure out how I should write code to make the LED stay on for 10 minutes and then turn off after being detected by the PING sensor.
I also would like to have a pushbutton connected to the same ledPin that would turn it on and off at any time, overriding the ping sensor.
I have been messing with a timer function, but can't seem to get it to work properly.
Any suggestions?