system
September 6, 2009, 11:08pm
1
I am using a salvaged computer CD drive to design a display of vocabulary words as our students pass through the hallway. The PIR sensor is responding as it should but my motor is not functioning as intended; a single movement of the tray with a short delay fully extended and a return to the case. I am not an experienced programmer and would appreciate help. Thank you.
int timer = 500;
int alarmPin = 0;
int alarmValue = 0;
int ledPin = 13;
int motorPin1 = 9;
int motorPin2 = 10;
int motorEnable = 11;
void setup () {
Serial.begin (9600);
pinMode(ledPin, OUTPUT);
pinMode(alarmPin, INPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
delay (1000);
}
void loop (){
alarmValue = analogRead(alarmPin);
if (alarmValue < 100){
blinky(); // blinks when the motion has been detected, just for confirmation.
}
delay(timer);
Serial.println (alarmValue);
delay (10);
}
void blinky() {
for(int i=0; i<2; i++) {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(9,HIGH);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay (1000);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11, HIGH);
delay (1000);
//digitalWrite(11,LOW);
}
}
system
September 7, 2009, 6:38am
2
but my motor is not functioning as intended
OK, so what is it doing?
for(int i=0; i<2; i++) {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(9,HIGH);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay (1000);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11, HIGH);
delay (1000);
//digitalWrite(11,LOW);
What happened to the nice names?
system
September 7, 2009, 1:26pm
3
This works:
digitalWrite(9,HIGH);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay (1000);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11, HIGH);
delay (1000);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite((9,LOW);
Extends the tray, pauses, returns, then stops and waits for the next PIR input. Not sure what you mean by fancy "names"? Thanks.
system
September 7, 2009, 1:49pm
4
int alarmPin = 0;
int alarmValue = 0;
int ledPin = 13;
int motorPin1 = 9;
int motorPin2 = 10;
int motorEnable = 11;
here, the pins have nice names (not fancy, just nice), but here
for(int i=0; i<2; i++) {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(9,HIGH);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay (1000);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11, HIGH);
delay (1000);
//digitalWrite(11,LOW);
}
they don't. They'd just make reading your sketch easier.
system
September 7, 2009, 5:42pm
5
I see what you mean and appreciate the advise.