Sorry to ask but im struggling with code,
the sketch looks at inputs from 2 sensors and when a sensor is high it turns a led on and a output to a motor for 10 seconds then turns off and the cycle starts again
it works ok until i connect the motor which is ran from a npn transistor then the 10 seconds on rate is anything from 1-10 seconds
int ledPin = 12; // vibration output
int led = 10; // pir output
int vibPin = 7; // choose the input pin (for Vib sensor)
int pirPin = 6; // choose the input pin (for PIR sensor)
int motor_pin=8;
int val = 0; // variable for reading the pin status
void setup() {
Serial.begin(9600);
pinMode(pirPin, INPUT); // declare sensor as input
pinMode(vibPin, INPUT); // declare sensor as input
pinMode(motor_pin,OUTPUT);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(led, OUTPUT); // declare LED as output
}
void loop(){
int val;
val=digitalRead(vibPin); // read input value
if(val==1)
digitalWrite(motor_pin,HIGH);
digitalWrite(ledPin, HIGH); // turn LED ON
delay(10000);
digitalWrite(motor_pin,LOW);
val = digitalRead(vibPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(led, HIGH); // turn LED ON
digitalWrite(motor_pin,HIGH);
delay(10000);
digitalWrite(motor_pin,LOW);
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
digitalWrite(led, LOW); // turn LED OFF
digitalWrite(motor_pin,LOW);
delay(300);
}
}