loading
2Comments

Tell us about yourself!

Complete Your Profile
  • RicardoH29 commented on jsvester's instructable Simple Arduino and HC-SR04 Example1 month ago
    Simple Arduino and HC-SR04 Example

    I don't understand how this is working.In your loop method, you do the following:1) Make sure your trigger pin is LOW2) Make your trigger pin HIGH for 10 μs3) Make your trigger pin LOW again4) Start listening to your echo pin. You are waiting for it to get HIGH using the pulseIn method (Reference: https://www.arduino.cc/en/Reference/PulseIn)Now here's the problem: the pulseIn method is waiting for the pin to be high, meaning it is waiting for the sonic waves you sent out for 10 μs to come back and hit the sensor. If I understand this correctly, pulseIn should start it's timer once the echo hits the sensor and stop the timer when the wave stops it. In my expectations, if the object the waves are bouncing back from is not moving, it should return the same time the trigger was HIGH, ...see more »I don't understand how this is working.In your loop method, you do the following:1) Make sure your trigger pin is LOW2) Make your trigger pin HIGH for 10 μs3) Make your trigger pin LOW again4) Start listening to your echo pin. You are waiting for it to get HIGH using the pulseIn method (Reference: https://www.arduino.cc/en/Reference/PulseIn)Now here's the problem: the pulseIn method is waiting for the pin to be high, meaning it is waiting for the sonic waves you sent out for 10 μs to come back and hit the sensor. If I understand this correctly, pulseIn should start it's timer once the echo hits the sensor and stop the timer when the wave stops it. In my expectations, if the object the waves are bouncing back from is not moving, it should return the same time the trigger was HIGH, i.e., 10 μs.The sketch works fine, so what's wrong with my understanding?

    Using the general idea in his code, yes, you can add more sensors. If you can have them share the same pins, then there virtually no limitation (unless you start overwhelming your power supply). Otherwise, if you need them fully independent from one another, then you are limited by the number of digital I/O pins you have available.Note that servos require a special kind of digital I/O pins, i.e. PWM (Pulse Width Modulation) capable pins. The HC-SR04 does not.

    View Instructable »