ive started to play a little bit around with my arduino and some sensors. With the help of the supportpackages for arduino i was able to connect the arduino mega 2560 to matlab an to simulink.
I want to turn off/on 2 leds in dependency of the distance of my hand. I know the physical theory how the ultrasonic waves work but i am not able to read a pin. I dont want to code anything in arduino sketcher. I trie to use only matlab/simulink.
I tried to to a simple sketch in simulink to see if i get a signal but the Display doesnt shows any reaction.
I uploaded a screenshot of my simulink model and the wiring.
I hope someone can help me with my problem. Sorry if my english is not so good, im no native speaker.
Look at the steps that need to be taken in order to use a ping sensor to measure distance.
The trigger pin needs to be turned on and then off, with a specific interval between turning the pin on and off.
Then, the echo pin is read continuously, using pulseIn(), until the state changes, indicating that an echo has been received.
To do that from Matlab is going to require some fancy coding, not just turning the trigger pin on and expecting to read anything meaningful from the state of the echo pin.
I think this is excactly what i did in that example in simulink....or am i wrong?
With the pulse generator i set the input to high an then to low. While the input measures all the time.
But the problem is that the display always sticks at 0, so it seems like i cant really measure anything, although it works in arduino sketcher.
I think this is excactly what i did in that example in simulink....or am i wrong?
I can't see where the element of time is a factor in the simulink code.
It appears to turn pin 2 (the trigger pin?) on permanently. It then appears to read the state of pin 3 (the echo pin) continuously. It does not seem to matter how long it takes for the echo pin to go high, and that is critical for measuring distance.
As you can see in the attached file the pulse generator creates a pulse with the time period of 15 samples and a pulse width of 10 samples and an amplitude of 1. That means during 5 samples the pulse is low an during 10 samples the pulse is high. Because i set a sample time of 1/100 s ...we have a time duration of about 0.15 seconds per time period.
I uploaded the File again, hope it works.
As you can see in the description this is just a try to see if the functions of the ultrasonic sensors work because it didnt work in matlab. If i could measure at least a signal, i would do the rest in matlab or think about a solution in simulink.
But at this point i even cant measure any signal.