Go Down

Topic: My project (Read 1 time) previous topic - next topic

danielsz

So, I'm a Product Design student, looking to create a musical instrument for physically disabled people, in the end it will be a standalone instrument, speakers and all.

The basis of this is with the sensors, and the output. I believe that using distance sensors is the easiest way for someone of my technical background (ie none). I have basically no experience of Arduino or C++, but have bought some of the parts necessary for my project.

at this moment in my project, I need 3 HC-SR04 ultrasonic sensors to output different notes depending on the ping distance that the sensor reads, I'm assuming I need something like this:

http://www.amazon.co.uk/Adafruit-Music-Maker-Shield-Arduino/dp/B00OKCPE50/ref=sr_1_2?ie=UTF8&qid=1456502369&sr=8-2&keywords=arduino+mp3+shield.

Now as far as my knowledge of the way Arduino and C++ works, is that I need the code to lookup (for instance) the note assigned to 18cm, then play that mp3 file through the speaker. Now my issue is, that I can't find a single resource on the coding for this.

I haven't purchased the shield or speaker yet, but I have enough wires, resistors, a handful of LEDs, 5 HC-SR04s and my Uno.

I've got a simple set up showing that my sensor works, using default ping code, but as you can tell, I need something far more complicated, and the rough prototype is due in just over a week. If anyone can point me to helpful resources, that would be much appreciated.

I live in the South East of the UK (not sure I'm in the right place for this) but if someone feels they could help out IN PERSON, I'd be okay to get together and brainstorm, throw a few ideas around, thought I'd be able to figure this out myself, but it's not looking good.

Grumpy_Mike

It is a pity you got those ultrasonic sensors because they have a very wide angle and have to be used one at a time so they don't interfere with each other. Much better would be the IR distance sensors from Sharp.

Do you need trigger a sample? I would have thought that generating a tone or sending a MIDI message would have been better.

I am surprised yo can not find an example of this sort of project it comes up all the time here.

danielsz

IR distance sensors? I'll have to have a look, as this is the early hand-in, the HC-SR04s will be adequate, but yes, basically I want to have a relatively large library of notes stored on the MP3 player shield, and each file will have a distance and sensor assigned to them. I will counteract the wide angle by insetting them into the body, at least for this proof-of-principle stage. The deeper I inset, the narrower the angle should get, I assume? Not too sure on the actual science of Ultrasonic sound waves, but I figured it made sense.

I may have been using a un-economic method of searching, but I've only found a handful of related projects. Ideally the final product will have MIDI base, but as far as I'm aware, that means I would have to route the MIDI output to a Audio Workstation in a computer or tablet etc.

As i'm completely new to this, I don't know the ins and outs. For this stage, I will be presenting a simple body, with 3 sensors, hooked up to a UNO, then the UNO connected to the Shield, and then speakers, or an audio output to my laptop, depending on time constraints.

Any pointers to a relevant forum or discussion would be much appreciated!

Thanks for the reply.

Grumpy_Mike

Quote
I will counteract the wide angle by insetting them into the body,
What body?
The ultrasonic sensor has a transmit and receive transducer. Attempts to put them in a tube might not work as the sound can hit the walls of the tube.

Quote
Not too sure on the actual science of Ultrasonic sound waves,
Same as audio sound waves.

Quote
I will be presenting a simple body,
I think you need to explain more what you are doing.

danielsz

Sorry, I'm creating a physical musical instrument in late may that has to be as close to a sellable prototype as possible. My next major hand in for this project is next wednesday. I need at least 1, preferably 3, HC-SR04 sensors hooked up to play saved music files (these will be notes, like all notes in a major scale for instance).

The sensors ping out to a max range of 20cm, at least in the way the code was set up, anything >20cm read as 'out of range'. I read somewhere that they have blindspots within 7cm, so I will need the remaining 13cm to play 13 notes. So 7cm plays the lowest pre-recorded note, and 20cm plays the highest.

I have found tutorials for triggering an MP3 file using HC-SR04 sensors, but haven't found any considering multiple files and sensors.

For now, I want to set up 1 sensor to play a file depending on distance. (track001 triggers at 7cm, track 002 triggers at 8cm etc etc.)

That's it, I also need to eventually make a high quality casing of sorts for this, so it looks professional, but that's something I'm more than equipped to handle when I need to.

I just have no prior experience in programming, arduino, and only a basic understanding of electronics.

I understand there are better and more effective solutions to this idea than the HC-SR04 sensors, but I only need to present an understanding of the idea, rather than a fully realised prototype at this stage.

Thanks for your engagement, I appreciate it.

Grumpy_Mike

Quote
I have found tutorials for triggering an MP3 file using HC-SR04 sensors, but haven't found any considering multiple files and sensors.
You just repeat that code three times, just changing the sensors.

Quote
For now, I want to set up 1 sensor to play a file depending on distance. (track001 triggers at 7cm, track 002 triggers at 8cm etc etc.)
Look at using a combination of if ststements. You can have compound statements like
Code: [Select]

if(distance > 70 && distance < 80) {
// play the appropriate file here
}

danielsz

So that code line
Code: [Select]
if(distance > 70&& distance < 80{
// play the appropriate file here
}


Would that parameter play at 70 or 80? or cut off/ change to next note when it hits those values?

Also the commented line, how would that read when uncommented, the same, or with various brackets?

The other question I have, does it matter where in the code I place these extra lines? Assuming I end the other statements and lines properly.

Thanks for your help, it's much appreciated, hopefully the Shield will arrive either tomorrow or the day after, so I'll be able to offer more examples of what I'm doing, and why it might not be working.

I won't be able to reply again tonight, so I'll do some research into those 'if' statements and how they work

Grumpy_Mike

Quote
Would that parameter play at 70 or 80?
No it would play for any value greater than 70 and less than 80. So that is any value from 71 to 79.

Quote
Also the commented line, how would that read when uncommented, the same, or with various brackets?
The commented line is to be replaced with the line of code that actually plays the file you want. You know what that is from the example you found.

Quote
The other question I have, does it matter where in the code I place these extra lines?
Yes of course it matters. You have to place it after you take a reading and work out the distance measurement from the reading.


danielsz

Okay, figured as much, so it needs to be placed after the code line asking for the range, makes sense.

Unfortunately no sign of the shield today... Once I've sorted some of the other stuff needed for the deadline, I'll have to actually try and make a compatible code without the shield, and see if I can't get it to compile. Hopefully I'll get something resembling what I need so it's ready for whenever Amazon decide to deliver it.

I'll post back here if I find any difficulties (solid chance I will)

Thanks

Grumpy_Mike

Quote
I'll have to actually try and make a compatible code without the shield, and see if I can't get it to compile.
Remember you can get any old crap to compile, the trick is the code has to work right.  :)

danielsz

Right, so it's me again. I'm using a tutorial on YouTube for controlling a piezo buzzer with two HC-SR04 sensors. Video is located https://www.youtube.com/watch?v=mr6I8ndBAp4    and the written format (and sketch) is http://www.duino-robotics.com/ultrasonic-music-maker.html.

Now the sketch they have provided doesn't want to compile, saying this;

Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Zack\AppData\Local\Temp\build33548b605f1943a3a2ba4b70b2f9625c.tmp/core\core.a(Tone.cpp.o): In function `__vector_7':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Tone.cpp:539: multiple definition of `__vector_7'

libraries\NewPing\NewPing.cpp.o:C:\Users\Zack\Documents\Arduino\libraries\NewPing/NewPing.cpp:284: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.


Now I don't have any idea what this all means, and it hasn't highlighted an issue with the code? Not sure what's happening, as I haven't changed anything with the code since downloading.

You can download the code from the second link I provided.

Regards.

Grumpy_Mike


danielsz

Yeah I eventually figured out there was a clashing, but i've already got the most recent newping library?

Grumpy_Mike

#13
Mar 07, 2016, 10:34 pm Last Edit: Mar 07, 2016, 10:39 pm by Grumpy_Mike
But the error message was the same in that thread as yours.

So if there are no newer libraries then you will have to rewrite one of them so they don't clash.  

Look at the one in this thread:-
http://forum.arduino.cc/index.php?topic=235774.0;topicseen

danielsz

I figured it out in the end, using that forum as a lead. Had to open up the .h file in a code writer programme and turn the ping_switch setting to 'false' instead of 'true'. That removed the clash, and allowed me to compile and upload, works pretty well, if a bit rudimentary.

Shield FINALLY arrived, so I'll be making a last ditch attempt to get that responding tomorrow, before the deadline the day after. Let you know how I get on, thanks for your help, wouldn't have found the solution to todays issue without that forum link.

regards

Go Up