Help with controlling PIR and Stepper

Not sure whats wrong with my code. Please help

int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
#include <Servo.h>
Servo myservo;
int pos = 0;//variable for reading the pin status
int count = 1;

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
myservo.attach(9); // attaches the servo on pin 9 to the servo object

Serial.begin(9600);
}

void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) { // we have just turned on
Serial.println(“Motion detected!”); // We only want to print on the output change, not state
pirState = HIGH;
if (count == 1) {
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15);
count == 2;
}
}
if (count == 2){
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15);
count ==5;// waits 15ms for the servo to reach the position
}
}
}

}
else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println(“Motion ended!”);

// We only want to print on the output change, not state
pirState = LOW;

}
}
}

Not sure whats wrong with my code.

It does something. You need to tell us what it does.

You expect it to do something. You need to tell us what you expect.

By the way, you can't control a PIR sensor. They do what they want, despite your best efforts to control them.

YOLOLJJ:
Not sure whats wrong with my code. Please help

          count == 2;

This line does nothing useful. It compares 'count' to 2 and ignores the result. That is why the servo always sweeps from 0 to 90. If you fix this (use "count = 2;") the servo will sweep from 0 to 90, jump from 90 to 180 and then sweep to 0. It will then only jump from 0 to 180 and then sweep to 0.

          count == 5;

This line does nothing useful. It compares 'count' to 5 and ignores the result. If you change it to "count = 5;" the servo will never move again. If you change it to "count = 1;" the servo will go back to sweeping from 0 to 90, jumping from 90 to 180 and then sweeping to 0.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile: