Issue: Preventing errors in the input being read by an interrupt pin

3 views
Skip to first unread message

Meenakshi Sundaram

unread,
Sep 24, 2010, 3:18:49 AM9/24/10
to arduinob...@googlegroups.com
Hi,

When I attach an interrupt to pin 3 of my Arduino board, I notice that the pin's state changes without any input actually being given to that pin. How is this possible? If this is possible due to some fluctuations, how do I prevent this from happening?

M. Meenakshi Sundaram

Ram_Tenet

unread,
Sep 24, 2010, 4:33:53 AM9/24/10
to arduinobangalore
Can u post in your code ? May be that can uncover some facts !

Thanks,
Ram

On Sep 24, 12:18 pm, Meenakshi Sundaram <boukenseic...@gmail.com>
wrote:

Meenakshi Sundaram

unread,
Sep 24, 2010, 5:29:20 AM9/24/10
to arduinob...@googlegroups.com
Here is the code

#define motorPin1 8
#define motorPin2 9
#define motorPin3 10
#define motorPin4 11

#define motorPin5 4
#define motorPin6 5
#define motorPin7 6
#define motorPin8 7

#define readPin 2
#define delayTime 3
volatile int a =HIGH;
void setup() {
 
  Serial.begin(9600);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
 
  pinMode(motorPin5, OUTPUT);
  pinMode(motorPin6, OUTPUT);
  pinMode(motorPin7, OUTPUT);
  pinMode(motorPin8, OUTPUT);
 
 attachInterrupt(1,drivemotor,CHANGE);
 
}

void drivemotor(){
 a=!a;
}
void loop() {
  if(!a){
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
 
  digitalWrite(motorPin5, HIGH);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
 
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);

  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, HIGH);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
 
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
 
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, HIGH);
  digitalWrite(motorPin8, LOW);
 
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
 
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, HIGH);
  delay(delayTime);
  }
}

Meenakshi Sundaram

unread,
Sep 24, 2010, 6:18:43 AM9/24/10
to arduinob...@googlegroups.com
Well
I found the culprit.. It was the IR sensor.. If the sunlight falling on it from the window (near which I was working), exceeds a certain limit, the IR sensor gets triggered on.
Reply all
Reply to author
Forward
0 new messages