no interrupt awake from power down

Using 1.6.5 on pro mini 16mHz
I have 3 PIR connected with only pin-hole lenses to obtain clockwise/anticlockwise hand sweeps around circular table.
All code works fine up to implementing sleep mode which is to save power when nobody is around.

I’ve lost a lot of references when my PC motherboard kaput, but I know there is no definitive answer to Atmega waking with level change interrupt HIGH or LOW only in power down mode.

The PIR in any case outputs a pulse, ie LOW to HIGH and back again, therefore fulfilling both conditions at some point in the detection.
So I have tried both level changes.

I could hardwire in an inverter transistor, but I want to diode logic all 3 PIR signals to the one interrupt pin ultimately and the voltage drop will be larger with both.

I really want to just bugsolder a component or two onto the board, not expand into a satellite PCB with logic inverters etc.

#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>

int state [2];//detected movement flags

void motorcw(void)
{
  state[0]=0;//clear detected movement flag array
  state[1]=0;
  state[2]=0;
  digitalWrite(6,LOW);//de-activate motor
  digitalWrite(7,HIGH);
  for (int x=1;x<=2;x++)//slow flash diagnostic indicator
  {digitalWrite(13,HIGH);
  delay(250);
  digitalWrite(13,LOW);
  delay(250);}
  digitalWrite(6,HIGH);
  digitalWrite(7,LOW);
}

void motorccw(void)
{
  state[0]=0;//clear detected movement flag arrary
  state[1]=0;
  state[2]=0;
  digitalWrite(8,LOW);//de-activate motor
  digitalWrite(9,HIGH);
  for (int x=1;x<=4;x++)//fast flash diagnostic indicator
  {digitalWrite(13,HIGH);
  delay(100);
  digitalWrite(13,LOW);
  delay(100);}
  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
}

void sleepNow(void)
{
    // Set pin 2 as interrupt and attach handler:
    attachInterrupt(0, pinInterrupt, LOW);
    delay(100);
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    // Set sleep enable (SE) bit:
    sleep_enable();    
    sleep_mode();
    // Upon waking up, sketch continues from this point.
    sleep_disable();

}

void pinInterrupt(void)
{
    detachInterrupt(0);
}

void setup()
{
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
  pinMode(3,INPUT);
  pinMode(4,INPUT);
  pinMode(5,INPUT);
  //bridge motor drive outputs as follows
  //write inactive values to bridge first to avoid shoot-through
  digitalWrite(6,HIGH);
  digitalWrite(7,LOW);
  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
  pinMode(6,OUTPUT);//pnp cw
  pinMode(7,OUTPUT);//npn cw
  pinMode(8,OUTPUT);//pnp ccw
  pinMode(9,OUTPUT);//npn ccw
}

void loop()
{
  for (int long awake=0;awake<1000000;awake++)
  {
  if(digitalRead(3)==HIGH){state[0]=1;}
  if(state[0]==1 && state[1]==1){motorccw();}
  if(state[0]==1 && state[2]==1){motorcw();}

  if(digitalRead(4)==HIGH){state[1]=1;}
  if(state[1]==1 && state[2]==1){motorccw();}
  if(state[1]==1 && state[0]==1){motorcw();}

  if(digitalRead(5)==HIGH){state[2]=1;}
  if(state[2]==1 && state[1]==1){motorcw();}
  if(state[2]==1 && state[0]==1){motorccw();}
  }
  sleepNow();
}
int state [2];//detected movement flags
void motorcw(void)
{
  state[0]=0;//clear detected movement flag array
  state[1]=0;
  state[2]=0;

That’s wrong, for a start. You have an array of 2 items and you are putting 3 things into it?


Your formatting is appallingly bad. You should not have things on the same line as: {

For example:

 if(digitalRead(3)==HIGH){state[0]=1;}

New lines are cheap. Use them.

And as for this? Pffft.

  for (int x=1;x<=2;x++)//slow flash diagnostic indicator
  {digitalWrite(13,HIGH);
  delay(250);
  digitalWrite(13,LOW);
  delay(250);}

Try:

  for (int x = 1; x <= 2; x++)  //slow flash diagnostic indicator
    {
    digitalWrite(13,HIGH);
    delay(250);
    digitalWrite(13,LOW);
    delay(250);
    }

  for (int x=1;x<=2;x++)

So, do this once? Why have a loop? How many numbers start with 1 and are less than 2? One?

Using 1.6.5 on pro mini 16mHz

Nope.

Edit: Don't you think that reporting moderators for pointing out problems with your code might be a bit, (how shall I put this?) counter-productive?
Buffer overflows are not "nit-picking"
Or is your handle not as ironic as you'd like us to think?

@simplystupid: Did you really report me for pointing out you had overflowed an array?

Unbelievable.

This is the third time one of my requests for help has been hijacked and killed off by more experienced arduinists for a nit-picking session …

It’s not “nit-picking”, buddy.

Once you write outside a buffer the program’s behaviour is undefined.

See: Undefined behavior - Wikipedia

In the C community, undefined behavior may be humorously referred to as “nasal demons”, after a comp.std.c post that explained undefined behavior as allowing the compiler to do anything it chooses, even “to make demons fly out of your nose”.

So, did demons fly out of your nose?

Fix those problems, with a little bit of humility, and then get back to us.

You are lucky, frankly, that some of the other forum members seem to be asleep right now.

  for (int x = 1; x <= 2; x++)  //slow flash diagnostic indicator

I wouldn’t call flashing something once a slow flash.

No idea what you are talking about?
1.6.5 installed 6am this morning on laptop from arduino.cc
programming pro min 5v 16mHz board successfully.

Sketch is in window 'turret1 Arduino 1.6.5'

AWOL - why would you think it ok to post your comments?But not the actual report to a moderator to which you refer sarcastically..
I am very good at what I do.
Are you?

I mean, this is the first posting anywhere on the web which explicitly answers the question of how to use cheap PIR and arduino to detect direction of motion.
Thank you simplystupid. A contribution to the communal knowledge.

As long as you don't delete this post,the seekers can find it and correct my appalling sketch layout and the oversight at 6am with state[3] number of elements in array.

On a previous post for help over 2 hours was spent endlessly debating where and how a variable was declared, by experts on the forum here, without ever answering the OP post....

This is really a cross-post of forum.arduino.cc/index.php?topic=336181, right?

int state[2];
...
state[2] = 0;

In that you said:

simplystupid:
Whoops!
Yes, arrays begin at zero, thanks for spotting that obvious one.

Looks like you didn't pick up on that fact that an array of 2 items, which starts at zero, can't use offset 2.

simplystupid:
AWOL - why would you think it ok to post your comments?But not the actual report to a moderator to which you refer sarcastically..
I am very good at what I do.
Are you?

Time-out for you, my lad. Come back in a week.

User banned for insulting remarks.

I am very good at what I do.
Are you?

I'm very good at knowing my millis from my megas :wink:

I'm also good at naming my pins (so I get a clue what they do when I come back to my code in six weeks time), not using sixteen bits of RAM to store one bit of data, not writing to memory I don't own, laying out my code to make it legible to others . . .

And if anyone thinks the ban is harsh, here is the report to moderators text, posted less than 30 minutes after Nick's first reply.

This is the third time one of my requests for help has been hijacked and killed off by more experienced arduinists for a nit-picking session, which is of no help to myself or any other Forum readers.
This thread has been killed off by Nick Gammon.