I pick one of these up this morning and its got me quite confused. The following code is what I am trying to add it to. I think i got it right until the void loop and then i have no idea what to do. Can anyone help me?
And what would I edit for the servo and lights to run longer after it picks up a motion?
#include <Servo.h>
Servo myservo;
int ledPin = 11;
int inputPin = 2;
int pir State = LOW;
int val = 0;
To get the sketch to compile you need to make the following changes:
Change
int pir State = LOW;
to
int pirState = LOW;
remove the following line (myservo is not a pin and the pin mode is set by the servo library):
pinMode(myservo, OUTPUT);
fix the typo and add a semicolon at the end of this line
Serial.beguine(9600)
But to get the code to do what you want will require a clearer description of how you want the sketch to workl. Can you say exactly what you want the servo and LED to do In response to input on the PIR.
You need to say what the state of the LED and servo should be when its not activated.
You also don't say if you are using a continuous rotation servo but I guess you are from reading a post in another thread.
Perhaps something like this at the top of the sketch will help:
#define SERVO_INACTIVE 90 //the value in degrees that stops the CR servo #define SERVO_ACTIVE 180 // the value you want for the motor to spin
Then in your code
myservo.write(SERVO_INACTIVE ); // stop the servo
and
myservo.write(SERVO_ACTIVE ); // spin the servo
ok so here is what I have. You have completely lost me. I know I have to state what the servo and LEDs are doing when active and not but I am confused on how to do so. And yes it is a continuous servo that only has to spin at 1500 microseconds.
#include <Servo.h>
Servo myservo;
int ledPin = 11;
int inputPin = 2;
int pirState = LOW;
int val = 0;
I want everything in the loop to be under the PIR but I am unsure how to take what it is I have and convert it so that it only runs when a motion is detected.
I suggest you move everything currently in loop into a new function called something like activate. Call that function when the PIR activates. Perhaps have another function called deactivate that resets the servo (and led states if necessary).
I think you may find things are clearer if you start with a tutorial that explains how to read the state of a pin and control an LED. This one from ladyada is highly regarded: Arduino Tutorial - Lesson 5