hello everyone,
I want to move a servomotor according to the distance I get from this distance sensor by using an Arduino Uno.
But as soon as I activate the feedback loop, the distance sensor’s output gets random.
Controlled by an I/O-Box the servo works fine, but with the feedback loop it trembles according to the distorted sensor output.
Connecting a Battery to the Arduino also doesn’t help.
If it’s any help, I have attached an arduino sketch that works with the exact same setup. (But I need the vvvv patch for easier development)
I’m glad for any help.
https://vvvv.org/sites/default/files/imagecache/large/images/Screenshot%202014-12-12%2019.07.27.png
working arduino sketch:
- include "Maxbotix.h"
- include <Servo.h>
Servo myservo;
int pos = 0;
int old = 0;
Maxbotix rangeSensorAD(A0, Maxbotix::AN, Maxbotix::LV);
void setup()
{
Serial.begin(9600);
myservo.attach(9);
}
void loop()
{
// AD
int range = rangeSensorAD.getRange();
Serial.print("AD: ");
Serial.print(range);
Serial.print("cm ");
int mr5 = map(range,15,300,0,56);
int mr = map(mr5,0,56,170,80);
if(mr != old) {
Serial.print(mr);
myservo.write(mr);
old = mr;
}
Serial.println();
delay(200);
}