79Views0Replies

Author Options:

sensors and servos Answered

I am working on a piece where I need to hook up 7 servo motors to the arduino (each rotating at a different speed, some in one direction, others in the other) but basically an on/off with a motion sensor. I am using a full rotation servo.
I amusing an infrared sensor but the servo is still moving (awkwardly and jerky) when not sensing motion, but then runs as normal.Here is the code I am using (right now, I am only at 1 servo – trying to get the sensor right first) :

#include <Servo.h>
Servo myservo;int potPin = 0; //analog pin used to connect the sensor
int ledPin = 9; //select pin for the servoint val = 0; //variable to read the value from the analog pin
void setup(){
  myservo.attach(9); //set up the servo as usual pinMode(ledPin, OUTPUT); //variable to store the value coming from the sensor
  Serial.begin(9600); //for watching the speeds in the serial monitor}

void loop() { val = analogRead(potPin); // read the value from the sensor
  val = map(val,0,600,0,255); if (val>80) digitalWrite(ledPin, HIGH); //turn the ledPin on

   else if (val<80) digitalWrite(ledPin, LOW); //turn the LedPin off


  Serial.println(val); delay(10);

}
– any suggestions?

Discussions