I am using the code below to control a servo motor arm with a sound sensor. The code has some issues I am not seasoned enough to solve. I have played around with the delay numbers trying to get the servo arm to not be so spastic. That is, I want the servo arm to move with the sound emitted without the ‘extra’ movements that don’t match up with the sound emitted.
I appreciate your time.
#include <Servo.h>
Servo arm1;
int degree;
int sensorValue;
void setup() {
Serial.begin(9600);
arm1.attach(3);
}
void loop() {
sensorValue = analogRead(A0);
degree = sensorValue / 100, 500;
Serial.println(sensorValue);
if (sensorValue < 400) {
arm1.write(30);
delay(260);
}
else if (sensorValue > 400) {
arm1.write(0);
delay(35);
}
}
edit: code tags added by mods, please remember to use them