So i have a project for my College Degree im making a monitoring sistem where i have two servos that one servo is attached with PIR sensor and the other Servo is attachted to An action cam
So the Code is supposed to make the servo that is connected to the PIR move in a loop motion from 0 to 180 and back then when the PIR detects a motion it stops and tells the top servo which is connected to the camera to aim at the PIR direction
so here is the code :
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo servoatas;
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int posatas = 0;
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW;
int val = 0;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(inputPin, INPUT); // declare sensor as input
servoatas.attach(3);
Serial.begin(9600);
}
void loop() {
while(pos>=0){
pos++;
Serial.print(pos);
val = digitalRead(inputPin);
if(val == LOW){
Serial.print("Ga Ada");
Serial.print("\n");
myservo.write(pos);
}
else{
Serial.print("Ada");
Serial.print("\n");
posatas=pos;
servoatas.write(posatas);
delay(1000);
//while(val == HIGH){
//val = digitalRead(inputPin);
//}
}
if (pos==180) break;
}
while(pos<=180){
pos--;
Serial.print(pos);
val = digitalRead(inputPin);
if(val == LOW){
Serial.print("Ga Ada");
Serial.print("\n");
myservo.write(pos);
}
else{
Serial.print("Ada");
Serial.print("\n");
posatas=pos;
servoatas.write(posatas);
delay(1000);
//while(val == HIGH){
//val = digitalRead(inputPin);
//}
}
if (pos==0) break;
}
}
756E6C:
Looks like you're swinging the detector servo near full speed, don't see how you expect to detect anything, stop, and point a camera?
The OPs code auto formatted.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo servoatas;
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int posatas = 0;
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW;
int val = 0;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(inputPin, INPUT); // declare sensor as input
servoatas.attach(3);
Serial.begin(9600);
}
So there are 2 servo Up and Bot Servo. The bottom servo is attached to the PIR sensor what it does is rotate the whole time form 0 to 180 until it detects some motion then it stops until the Top servo which holds the camera that will point on the direction the Bot servo stopped for monitoring the Person or Animal that is exposed to the infrared
Delta_G:
And what is the problem you are having? What does this code do? How does that compare with what you want it to do?
So there are 2 servo Up and Bot Servo. The bottom servo is attached to the PIR sensor what it does is rotate the whole time form 0 to 180 until it detects some motion then it stops until the Top servo which holds the camera that will point on the direction the Bot servo stopped for monitoring the Person or Animal that is exposed to the infrared
First I suggest that you remove your email address unless you're soliciting spam.
Next I suggest that you use decent name for your servos (e.g. servoPir instead of myservo and servoCam instead of servoatas. 'atas' means 'on' (?, Indonesian according to google translate) and that might make sense to you but not to me. It will make it easier for us to follow your thinking and your code.
mecquso:
this code only detects the motion when i see at the serial monitor it doesnt connect to the servo.
What does 'connect to the servo' mean? Have you tried a simple servo example (e.g. the sweep example that comes with the IDE); does that work? Try for both servos.