Hello Alejandro,
While using the HC-SR04 ultrasonic sensor to measure distance from an obstacle or object while using an Arduino Uno board in Simulink, I presume that you would be using the 'Ultrasonic Sensor' block from the Sensor library of the Simulink Support Package for Arduino Hardware.
In the case of the sensor producing only zeroes, which I believe is not OS or platform dependent, here are a few possible reasons that could be causing the issue:
- If the object is placed beyond the range of sensor detection.
- The Sample time parameter is not equal to the model base rate.
- When the block Sample time and model base rate are not greater than the total time required by the sensor to transmit and receive the sound wave. More information on this can be found at - Calculate the Time of a Sound Wave.
- When the model is not run on target hardware or if External Mode is not being used.
Here are some things to try:
- Check if the Uno board's digital pin values, to which the Trig and Echo pins of the sensor are connected, have been correctly mentioned in the block parameters.
- Check the voltage of the supply to the sensor and ensure the Vcc pin of the sensor is connected to 5 volts, which is recommended for reliable performance.
I hope this helps.
Swathi.D.