Arduino Forum

Products => The Arduino Starter Kit and Basic Kit => Topic started by: mustafa27 on Mar 07, 2015, 10:22 am

Title: Servo Motor And PIR
Post by: mustafa27 on Mar 07, 2015, 10:22 am
There are 4 pir and 1 servo motor and each pir has its own degree. when a pir detect the motion then servo motor rotates to degree of motion but this  pir returns to its degree as triggered after the servo motor return to starting point. servo motor makes this situation 2 or 3 times.

is the problem about connection or codes ?


#include <Servo.h>

Servo myservo;
int pin1 = 2;
int pin2 = 4;
int pin3 = 11;
int pos = 0;
int pin4 = 6;
int wait = 1000;

void setup(){
  Serial.begin(9600);
  pinMode (pin1,INPUT);
  pinMode (pin2,INPUT);
  pinMode (pin3,INPUT);
  pinMode (pin4,INPUT);
  myservo.attach(13);
  myservo.write(90);
}

void loop (){

  int sensor_1 = digitalRead(pin1);
  int sensor_2 = digitalRead(pin2);
  int sensor_3 = digitalRead(pin3);
  int sensor_4 = digitalRead(pin4);
 
  if (sensor_1 == HIGH){
   Serial.println(sensor_1); 
   myservo.write(125);
   delay(wait);
 }
 else if (sensor_2 == HIGH){
   Serial.println(sensor_2); 
   myservo.write(106);
   delay(wait);
 }
 else if (sensor_3 == HIGH){
   Serial.println(sensor_3); 
   myservo.write(68);
   delay(wait);
 } 
   else if (sensor_4 == HIGH){
   Serial.println(sensor_4); 
   myservo.write(55);
   delay(wait);
   
 }
 else
 {
   
    myservo.write(90);
 }


}
Title: Re: Servo Motor And PIR
Post by: mustafa27 on Mar 11, 2015, 08:23 pm
++++