TOP Contributors

  1. MIKROE (2784 codes)
  2. Alcides Ramos (400 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (128 codes)
  5. Bugz Bensce (97 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (140752 times)
  2. FAT32 Library (73323 times)
  3. Network Ethernet Library (58186 times)
  4. USB Device Library (48374 times)
  5. Network WiFi Library (43963 times)
  6. FT800 Library (43522 times)
  7. GSM click (30450 times)
  8. mikroSDK (29151 times)
  9. PID Library (27160 times)
  10. microSD click (26833 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
Library

HC-SR04 Library

Rating:

0

Author: Tiago Henrique

Last Updated: 2016-02-23

Package Version: 1.0.0.1

Category: Measurement

Downloaded: 2235 times

Followed by: 2 users

License: MIT license  

Biblioteca para trabalhar com o sensor ultrassônico HC-SR04. Este sensor é utilizado para medir distâncias de até 4m e identificar a presença de objetos ou captar movimentos.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "HC-SR04 Library" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "HC-SR04 Library" changes.

Do you want to report abuse regarding "HC-SR04 Library".

  • Information
  • Comments (0)
DOWNLOAD LINK RELATED COMPILER CONTAINS
mikroC PRO for PIC
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc

Library Blog

BLOGhttp://microcontrolandos.blogspot.com.br

EXEMPLO

/*

   HC-SR04 - Sensor Ultrassonico
   MCU: PIC18F4550
   CLOCK: HS + PLL, 48MHz
*/

#include "HC-SR04.h"

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

sbit HCSR04_Trigger at RD0_Bit;
sbit HCSR04_Echo at RD1_Bit;
sbit HCSR04_Trigger_Direction at TRISD0_Bit;
sbit HCSR04_Echo_Direction at TRISD1_Bit;

char text[8];
unsigned Distancia;
//factor = 1 / ( ( 4 * Prescaler ) / Clock )
const float factor = 1.5;

void main()
{
    ADCON1 = 0x0F;
    
    //0 - prescaler 1:1
    //1 - prescaler 1:2
    //2 - prescaler 1:4
    //3 - prescaler 1:8
    
HCSR04_Init(3);
    
    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);               // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  
    while(1)
    {
      Distancia = HCSR04_Read();
      WordToStrWithZeros( Distancia, text );
      Lcd_Out( 1, 1, "Dist.: " )
      Lcd_Out_CP( text );
      Lcd_Out_CP( "mm" );
      Delay_ms( 300 );

    }
}

ALSO FROM THIS AUTHOR

BMP085 Library

0

This is a library for use of the pressure sensor and temperature Bosch BMP085

[Learn More]