I am running the following code to run the motor activated by sound. Need help with code to run the motor for 1 minute before stopping when the "digitalValue==LOW". Thanks
// Include the library
#include <Servo.h>
// Create the servo object
#define servoPin 9
Servo myservo;
// Create a variable to store the servo position:
int angle = 0;
int sensorDigitalPin = 3; // Select the Arduino input pin to accept the Sound Sensor's digital output
int digitalValue; // Define variable to store the digital value coming from the Sound Sensor
int Led13 = 13; // Define LED port; this is the LED built in to the Arduino (labled L)
void setup()
{
pinMode(sensorDigitalPin, INPUT); // Define pin 3 as an input port, to accept digital input
pinMode(Led13, OUTPUT); // Define LED13 as an output port, to indicate digital trigger reached
myservo.attach(servoPin); // attach the servo to our servo object
myservo.write(0);
}
void loop() {
digitalValue = digitalRead(sensorDigitalPin); // Read the value of the digital interface 3 assigned to digitalValue
if (digitalValue == HIGH) // When the Sound Sensor sends signal, via voltage present, light LED13 (L)
{
// scan from 0 to 180 degrees
for (angle = 0; angle < 180; angle++)
{
myservo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for (angle = 180; angle > 0; angle--)
{
myservo.write(angle);
delay(15);
}
}
else
if(digitalValue==LOW) // When there is no sound and LED is OFF)
{
myservo.write(0); // stop the motor
}
}
// Include the library
#include <Servo.h>
// Create the servo object
#define servoPin 9
Servo myservo;
// Create a variable to store the servo position:
int angle = 0;
int sensorDigitalPin = 3; // Select the Arduino input pin to accept the Sound Sensor's digital output
int digitalValue; // Define variable to store the digital value coming from the Sound Sensor
int Led13 = 13; // Define LED port; this is the LED built in to the Arduino (labled L)
void setup()
{
pinMode(sensorDigitalPin, INPUT); // Define pin 3 as an input port, to accept digital input
pinMode(Led13, OUTPUT); // Define LED13 as an output port, to indicate digital trigger reached
myservo.attach(servoPin); // attach the servo to our servo object
myservo.write(0);
}
void loop() {
digitalValue = digitalRead(sensorDigitalPin); // Read the value of the digital interface 3 assigned to digitalValue
if (digitalValue == HIGH) // When the Sound Sensor sends signal, via voltage present, light LED13 (L)
{
// scan from 0 to 180 degrees
for (angle = 0; angle < 180; angle++)
{
myservo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for (angle = 180; angle > 0; angle--)
{
myservo.write(angle);
delay(15);
}
}
else
if(digitalValue==LOW) // When there is no sound and LED is OFF)
{
myservo.write(0); // stop the motor
}
}