{"id":23317157,"url":"https://github.com/adnksharp/ino-hcsrs04","last_synced_at":"2025-07-27T05:38:46.308Z","repository":{"id":135392581,"uuid":"508478007","full_name":"adnksharp/ino-HCSRS04","owner":"adnksharp","description":"Medir distancia con el sensor HC-SR04 y Arduino","archived":false,"fork":false,"pushed_at":"2022-08-12T18:28:13.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"base","last_synced_at":"2024-12-22T06:58:07.549Z","etag":null,"topics":["arduino-sketch"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adnksharp.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-28T22:56:21.000Z","updated_at":"2023-06-27T19:27:47.000Z","dependencies_parsed_at":"2024-07-22T09:21:48.153Z","dependency_job_id":null,"html_url":"https://github.com/adnksharp/ino-HCSRS04","commit_stats":null,"previous_names":["adnksharp/ino-hcsrs04","adnksharp/ihcsrs04"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnksharp%2Fino-HCSRS04","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnksharp%2Fino-HCSRS04/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnksharp%2Fino-HCSRS04/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnksharp%2Fino-HCSRS04/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adnksharp","download_url":"https://codeload.github.com/adnksharp/ino-HCSRS04/tar.gz/refs/heads/base","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238621897,"owners_count":19502747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino-sketch"],"created_at":"2024-12-20T16:20:36.709Z","updated_at":"2025-02-13T08:28:43.511Z","avatar_url":"https://github.com/adnksharp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HC-SR04\n[![hc-sr04-bb.png](https://i.postimg.cc/cJWJVQxS/hc-sr04-bb.png)](https://postimg.cc/Wd9jZqqW)\n\nLeer distancias usando el sensor ultrasonico [HC-SR04](https://www.luisllamas.es/medir-distancia-con-arduino-y-sensor-de-ultrasonidos-hc-sr04/).\n\n## Hardware y software necesarios\n- Placa de desarrollo Arduino \n- Sensor ultrasonico HC-SR04\n- [Arduino IDE](https://www.arduino.cc/en/software) o [Arduino CLI](https://arduino.github.io/arduino-cli/0.23/installation/)\n\n## Funcionamiento\n### Variables\n- ```Sensor```: Vector que contiene los pines a los que se conecta el sensor.\n    - ```Sensor[0]```: Pin de salida (Trigger al pin 5 del microcontrolador).\n    - ```Sensor[1]```: Pin de entrada (Echo al pin 6 del microcontrolador).\n- ```Out```: Estado de ```Sensor[0]```.\n- ```mdelay```: Vector que contiene el tiempo en microsegundos que el programa permanecera pausado mientras ```Sensor[0]``` esté en alto o bajo.\n- ```c``` e ```i```: Variables usadas para bucles for.\n- ```Time```: Tiempo que el pin ```Sensor[1]``` tarda en recibir el pulso de ```Sensor[0]```.\n- ```Dist```: Distancia actual leida.\n- ```Cache```: Distancia anterior.\n- ```Trash```: Vector usado para leer el promedio de varios tiempos leidos.\n\n### Funcionamiento\n\n Dentro de un bucle se leen 13 veces el tiempo que tarda **Echo** en leer el pulso de **Trigger**:\n\n - Dentro de un bucle se pone el Pin **Sensor[0]** en ```Out``` (0 o 1) ```mdelay``` microsegundos.\n - Usando [```pulseIn()```](https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/) se lee el tiempo que tarda el pin **Sensor[1]** en recibir la señal de **Sensor[0]** en la variable ```Time```.\n - Usando\n\n    ![](https://www.luisllamas.es/wp-content/ql-cache/quicklatex.com-83780eae753d9e35a70b0ebb4f6803fa_l3.png)\n\n    se calcula la distancia en cm para cambiar la variable ```Time``` a distancia en cm.\n    \nSi la distancia cambia respecto a la lectura anterior, se imprime la distancia en pantalla.\n\n[![hc-sr04-esquem-tico.png](https://i.postimg.cc/7LNLDfhT/hc-sr04-esquem-tico.png)](https://postimg.cc/mct4yZQb)\n\n###### Fuente: [Luis Llamas](https://www.luisllamas.es/medir-distancia-con-arduino-y-sensor-de-ultrasonidos-hc-sr04/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadnksharp%2Fino-hcsrs04","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadnksharp%2Fino-hcsrs04","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadnksharp%2Fino-hcsrs04/lists"}