PIR->WaveShield->Speakers +total noob

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Is the pulldown R6?

also, would adding the randomness to check switches look like this?

Code: Select all

byte check_switches()
{
  if (digitalRead(14) == HIGH)  // check for high signal on pin 14 (analog 0)
    {
       return Random(1,6);
    }
  return 0;
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

The pulldown is that 10K resistor between the input pin and ground.

For the randomness check, you also want to stop the wave when the pin goes LOW:

Code: Select all

byte check_switches()
{
  if (digitalRead(14) == HIGH)  // check for high signal on pin 14 (analog 0)
    {
       return Random(1,6);
    }

  if (wave.isplaying)  // stop it
  {
    wave.stop();
  }

  return 0;

}

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

when i go to upload it says:
sketch_mar14a.cpp: In function 'byte check_switches()':
sketch_mar14a:123: error: 'Random' was not declared in this scope

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

Lower case 'r'. (Computers are sticklers for detail)

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

ok fixed.

So it is playing a song all the way through, then stopping, but I would prefer it to stop immediately upon not being triggered. Is this a code thing?

Sorry I don't see what you mean by a resistor between input and ground. Was I supposed to put one in?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

I would prefer it to stop immediately upon not being triggered
Did you modify "playcomplete" as I suggested? You need to add a check for the PIR state (same as in check_switches) and return when it goes LOW.
Sorry I don't see what you mean by a resistor between input and ground
If it is stopping, you don't need it.

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

oh right forgot that. Soooo lemme give that a whirl...


would that mean inserting a check switches deal?

like:

Code: Select all

byte check_switches()
{
  if (digitalRead(14) == LOW)  // check for high signal on pin 14 (analog 0)
    {
       wave.stop();
    }

 return 0;
  
}
so:

Code: Select all

void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  byte check_switches()
{
  if (digitalRead(14) == LOW)  // check for high signal on pin 14 (analog 0)
    {
       wave.stop();
    }

 return 0;
  
}
  }
  // now its done playing
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

That should work - with one minor change. Because playcomplete is a 'void' function, it can't return a value. You will need to change the:

return 0;

for a simple:

return;

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

okay I don't understand where my brackets are supposed to go I suppose:

my code is:

Code: Select all

void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  byte check_switches()
{
  if (digitalRead(14) == LOW)  // check for high signal on pin 14 (analog 0)
    {
       wave.stop();
    }

return;
 
}
  }
  // now its done playing
}
but I am getting this:

sketch_mar14a.cpp: In function 'void playcomplete(char*)':
sketch_mar14a:141: error: a function-definition is not allowed here before '{' token
sketch_mar14a:170: error: expected `}' at end of input
sketch_mar14a:170: error: expected `}' at end of input

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

Your brackets need to be 'balanced'. It is easier to see if you keep the indenting consistent.
The error was the 'byte' before the call to check_switches. But that call was redundant because you are also checking the input directly with your digitalRead().
A simplified version is below:

Code: Select all

void playcomplete(char *name) 
{
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying)
  {
      if (digitalRead(14) == LOW)  // check for high signal on pin 14 (analog 0)
      {
          wave.stop();  // stop and return if no person detected
          return;
      }
  }
  // now its done playing
}

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Okay I see thanks very much arduwino. Anyway, success!!

So, the way it is behaving now will require a little modification, because if someone stops moving for just a moment it shuts off and then starts again when someone moves again. This is exactly what it's programmed to do, but the effect is rather choppy and jumpy, so I suppose I should insert a delay in there somewhere, say of about 30 seconds. Perhaps, if it does the check every 20 seconds for LOW, it might mitigate that effect. Can I slip that in before the digital read after while (wave.isplaying)?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

The PIR module has an adjustable timeout (on the ones I have here, it is a small trim-pot on the circuit board). You may be able to adjust that for a long enough delay to solve your problem.

In code, it would be a little trickier than what you propose. You want to start timing when the signal goes low, and test it again before deciding to stop the wav.

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Right, I see.

This is my PIR, looks pretty standard. Does it have the trim-pot you speak of?
photo.JPG
photo.JPG (104.22 KiB) Viewed 1751 times
photo1.JPG
photo1.JPG (517.36 KiB) Viewed 1751 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

Looks like yours has fixed - surface mount resistors. There is a good article here on how to modify them: http://www.neufeld.newton.ks.us/electronics/?p=208

If that looks too intimidating, we can take a look at a software solution. I'll check back here later this afternoon.

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Okay great I'll take a look at that. Thanks arduwino.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”