Go Down

Topic: Power issue? (Read 466 times) previous topic - next topic


I'm using a Duemilanove and WAV Shield connected to some small headphones and a MaxSonar - EZ1 to act like a doorbell. This works fine.
 I also want to turn on an led and have them hooked up through a 3906 transistor and a 9 volt battery.
The light only comes on when the WAV shield is playing and doesn't stay on .  Ideally I want the light to stay on for 30 seconds or so, but am just trying to get it to stay on for now.
Is this a power or coding issue?

Code: [Select]
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
#define ledPin 12

int i;
int x=0;
int y=0;
int distsensor=0;
int pread=0;
int county=0;
int counttime=0;
int prevcounttime=0;
int xy=0;
int lo=0;

AF_Wave card;
File f;
Wavefile wave;      // only one!
#define redled 9
uint16_t samplerate;

void setup() {
 Serial.begin(9600);           // set up Serial library at 9600 bps
 Serial.println("Wave test!");
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(redled, OUTPUT);

 if (!card.init_card()) {
   putstring_nl("Card init. failed!");
 if (!card.open_partition()) {
   putstring_nl("No partition!");
 if (!card.open_filesys()) {
   putstring_nl("Couldn't open filesys");

 if (!card.open_rootdir()) {
   putstring_nl("Couldn't open dir");

 putstring_nl("Files found:");

void ls() {
 char name[13];
 int ret;
 putstring_nl("Files found:");
 while (1) {
   ret = card.get_next_name_in_dir(name);
   if (!ret) {

uint8_t tracknum = 0;

void loop() {
// digitalWrite(ledPin, LOW);
if (lo==1)
 digitalWrite(ledPin, HIGH);
 uint8_t i, r;
 char c, name[15];

 for (i=0; i<5; i++) {
   distsensor += analogRead(5);
 distsensor /= 6;
 //digitalWrite(ledPin, LOW);
 Serial.print("Sensor = ");
 Serial.print("Hits = ");

 // if (pread < (distsensor -8) || pread > (distsensor +8))
 if (pread > (distsensor +8))
   if (y!=1 || prevcounttime +50 <= counttime)// Ignore first time through as sensors stabilize y=0;
     //digitalWrite(ledPin, LOW);

   digitalWrite(ledPin, HIGH);
   lo =1;
   Serial.println("in loop..... ");
   Serial.write("xy = ");


   // add counttime=0;
   //county=x/2;// try ceil or floor? to round up
 if (counttime >=50000)


void playcomplete(char *name) {
 uint16_t potval;
 uint32_t newsamplerate;
 Serial.write ("Playing ");
 samplerate = wave.dwSamplesPerSec;
 while (wave.isplaying) {    
   // you can do stuff here!
   //  delay(5);

void playfile(char *name) {
 f = card.open_file(name);
 if (!f) {
   putstring_nl(" Couldn't open file");
 if (!wave.create(f)) {
   putstring_nl(" Not a valid WAV");
 // ok time to play!



Which LED are you having issues with? The one attached to ledPin or the one attached to redled?



It looks like you turn the LED on before the call to playcomplete. I see nothing in playcomplete that turns it off, and playcomplete does not return until the wav file has completed playing.

Is this what you are seeing?

Some comments in the code would be helpful, as well as meaningful names for variables. county doesn't mean anything. What are you counting, and why?

What pins does the wave shield use?


Thanks.  It was the pin I was using.  I've got it now.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131