URM37 and MP3 Shield


dear community,

recently started explore beautiful world of arduino. reached point need advice.

what want create
a stationary device should play music while person standing or moving within predefined distance sensor. person leaves area playback should paused , again within range, playback should continued (of course same point of track). activation range: 20 400 cm. long predefined area empty playback on hold. playback 4gb usb stick.

what have
arduino uno r3
arduino usb-sd mp3 shield elechouse http://www.elechouse.com/elechouse/index.php?main_page=product_info&cpath=168_170&products_id=2193
urm37 v3.2 ultrasonic sensor http://www.elechouse.com/elechouse/index.php?main_page=product_info&cpath=168_170&products_id=2193


what able right now
measure distance urm37 , lighting led if s.o. within predefined range
playing tracks usb stick (both @ same time)
really basic c++
wiring+soldering
following advices
reading tutorials

distance measuring led lightup
code: [select]
// # editor    :jiang dfrobot
// # data      :18.09.2012

// # product name:ultrasonic scanner
// # product sku:sen0001
// # version :  0.2

// # description:
// # sketch scanning 180 degree area 4-500cm detecting range

// # connection:
// #       pin 1 vcc (urm v3.2) -> vcc (arduino)
// #       pin 2 gnd (urm v3.2) -> gnd (arduino)
// #       pin 4 pwm (urm v3.2) -> pin 3 (arduino)
// #       pin 6 comp/trig (urm v3.2) -> pin 5 (arduino)
// #
int urpwm = 3; // pwm output 0?25000us?every 50us represent 1cm
int urtrig=5; // pwm trigger pin
int rangelow = 20;
int rangehigh = 400;
int led = 13;

unsigned int distance=0;
uint8_t enpwmcmd[4]={0x44,0x02,0xbb,0x01};    // distance measure command

void setup(){                                 // serial initialization
 pinmode(led, output);
 serial.begin(9600);                         // sets baud rate 9600
 pwm_mode_setup();
}

void loop()
{
pwm_mode();
delay(20);
}                      //pwm mode setup function

void pwm_mode_setup(){
 pinmode(urtrig,output);                     // low pull on pin comp/trig
 digitalwrite(urtrig,high);                  // set high
 
 pinmode(urpwm, input);                      // sending enable pwm mode command
 
 for(int i=0;i<4;i++){
     serial.write(enpwmcmd[i]);
  }
}

void pwm_mode(){                              // low pull on pin comp/trig  triggering sensor reading
   digitalwrite(urtrig, low);
   digitalwrite(urtrig, high);               // reading pin pwm output pulses
   
   unsigned long distancemeasured=pulsein(urpwm,low);
   
   if(distancemeasured==50000){              // reading invalid.
     serial.print("invalid");  
  }
   else{
     distance=distancemeasured/50;           // every 50us low level stands 1cm
  }
 serial.print("distance=");
 serial.print(distance);
 serial.println("cm");
 
 if((distance > rangelow) && (distance < rangehigh))
      {
         digitalwrite(led, high);
      }
      else
      {
         digitalwrite(led, low);
      }
}


playback
code: [select]
#include <softwareserial.h>
#include <mp3.h>

/** define mp3 class */
mp3 mp3;

void setup()
{
 /** begin function */
 mp3.begin(mp3_software_serial);    // select software serial
 
 /** set volum max */
 mp3.volume(0x1f);
 
 /** set mp3 shield cycle mode */
 mp3.set_mode(mp3::cycle);
 
 /** play music in sd, '0001' first music */
 mp3.play_usb_disk(0x0001);
 
}

void loop()
{
 mp3.volume(0x1f);
 //mp3.set_mode(mp3::cycle);
 mp3.play_usb_disk(0x0001);
}


basicly need if-loop or while-loop control mp3 shield.

any kind of replies welcome!
sorry bad english :(





Arduino Forum > Using Arduino > Project Guidance > URM37 and MP3 Shield


arduino

Comments

Popular posts from this blog

Authentication error while password reset - Raspberry Pi Forums

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums