Home 2018 Forums Crumble Support HC-SR04 sensor support

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3572
    Nusrat
    Participant

    Hi Folks,

    I have just bought the HC-SR04 sensor, and I see that there is a an Input/Output block called ‘Distance T: ( A ) E: ( B )’ which I suspect is related to the distance sensor. Could someone please point me to some documentation on how I might use that with the sensor? If not how else does one go about programming that? Thanks
    Nusrat

    #3574
    Joseph
    Keymaster

    Hi Nusrat,

    You need to connect two pads (e.g. A and B) to echo and trig (marked as E and T) on the sensor. You also need to connect + and – for power. You can then use the distance block to read the distance, making sure that E and T are set appropriately.

    I’ve attached a simple program which reads the distance into a variable and sets a Sparkle red if the distance is less than 20cm. You could skip the use of the variable and use the distance block statement directly in the if statement, but the variable allows you to monitor the value while it’s running.

    I hope this helps.

    Joseph

    Attachments:
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.