
I also threw in a bunch of print statements. I also don't have access to the sensor you are using, so I did INPUT_PULLUP for the sensor pin and used a push button for testing purposes, which of course means that HIGH and LOW had to be swapped. Other IDEs will not allow a function to be used before declaration. The Arduino IDE does not require the declaration but I find it a good C++ habit to get into. It is declared at the beginning and the definition is at the end.

#Programar servo motor arduino code#
Please look at it first: you will find that it is simply your code for sweeping back and forth once only. I also created a simple function called servoSweep. I looked at your code and reviewed why the servo was not stopping: the extra sweep time had to be folded into the part where the servo is first checked and activated. Sorry about not getting back to you sooner. Long extraTime = 1000 * 60 * 1 // millisec in second * sec in min * minutes of extra sweep I would appreciate if you can take a look at the code and let me know what I did wrong as I am very new at this.

I tried your solution, but could not get the servo to stop. If (digitalValue = HIGH) // When the Sound Sensor sends signal, via voltage present, light LED13 (L) PinMode(Led13, OUTPUT) // Define LED13 as an output port, to indicate digital trigger reachedĭigitalValue = digitalRead(sensorDigitalPin) // Read the value of the digital interface 3 assigned to digitalValue PinMode(sensorDigitalPin, INPUT) // Define pin 3 as an input port, to accept digital input Worked perfectly.`// Include the library #include If(digitalValue=HIGH) // When the Sound Sensor sends signal, via voltage present, light LED13 (L) Myservo.attach(servoPin) // attach the servo to our servo objectĭigitalValue=digitalRead(sensorDigitalPin) // Read the value of the digital interface 3 assigned to digitalValue

PinMode(Led13,OUTPUT) // Define LED13 as an output port, to indicate digital trigger reached PinMode(sensorDigitalPin,INPUT) // Define pin 3 as an input port, to accept digital input Int Led13 = 13 // Define LED port this is the LED built in to the Arduino (labled L) Int digitalValue // Define variable to store the digital value coming from the Sound Sensor Int sensorDigitalPin = 3 // Select the Arduino input pin to accept the Sound Sensor's digital output Create a variable to store the servo position: Need help with code to run the motor for 1 minute before stopping when the "digitalValue=LOW". I am running the following code to run the motor activated by sound.
