HCSR04 and STM32 using Input Capture || Pulse width || CubeIDE

preview_player
Показать описание
________________________________________________________________________________________

Interface HCSR04 with STM32 using the Timer Input Capture Mode.
This method overcomes the errors that you were getting with the older method

________________________________________________________________________________________

******* SUPPORT US BY DONATING******

*******Join the Membership*******

Рекомендации по теме
Комментарии
Автор

The pin A9 is connected to the Trig but in the main you define the A8 as Trig pin, I think it was a little confusion.
Great video!!

kennygomez
Автор

Hello!
I have STM32 Nucleo L476RG. If you have problem like me that sensor doesn't measure anything or LCD is bombarded by random numbers here is solution, which worked for me.
1. Change these lines in your code to this:
#define TRIG_PIN GPIO_PIN_9
#define TRIG_PORT GPIOA

According to this video, TRIG should be connected do PA9 and ECHO to PA8. Remember that TRIG should be as GPIO_Output. On pin PA8 (to which is connected ECHO) you should make TIMER and enable option Input Capture mode.

2. Make sure that sensor is connected to 5 V DC.

3. Add this function to properly display values on your LCD:

void lcd_display_distance(uint8_t distance) {
char buffer[16];
sprintf(buffer, "Distance: %d cm", distance);
lcd_clear();
lcd_put_cur(0, 0);
lcd_send_string(buffer);
}

4. Make sure you add these lines in main:
MX_TIM1_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
lcd_init();
HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1);
lcd_send_string ("Dist= ");

5. In while make sure you have:
HCSR04_Read();
HAL_Delay(200);

And add this line too:


That's all worked for me. I hope that this comment will help you.
Greetings!

mateusz
Автор

Excellent as always. I like the way you converted decimal to ascii. Thank you.

noweare
Автор

Excellent video!! I tried this with my STM, the data is captured once and can only be updated when reset button is pressed, what to do?

shreyakaria
Автор

Hello! I like this video, to easy for learn. I make universal lib for any STM microcontroller. Big thanks!

tupoy_ytub_uberi_psevdonim
Автор

if i want to set a random number of the lcd, like push a button and save that value to calculate other values... You have a video to do that thing?

PD: Great video :3

misterjacqwelll
Автор

Hi, Grt. Pls share tutorial on EEPROM Emulation on STM32F103C8T6 flash memory (Ref cd00165693) HAL Lib is there. thx

theraja
Автор

how to multiple input capture channels

minhcongho
Автор

hey, there are two problems:
1. When the LCD reaches number more than 9 it shows A, how can I fix it?
2. The ultrasonic sensor fakes the distance measurement by 3 or 4 centimeters, do you have a solution for this?

dorstern
Автор

If the distance if greater than 127 it Distance variable becomes negative number. How should I fix this?

siurpussiurpuliukas
Автор

hi, thanks for this code
But I think this code has problem
you define PA8 as trig pin but put it on wrong way to use I try this code on my micro and change PA8 to PA9 as trig and coxe work it as well

self-studyelectronicengine
Автор

Hi Sir,

Can you please make video on Timer Tigger source and usage of it

nsanandkumarak
Автор

Hello, i have some problem with TCS3200, can you make a project about it. Thanks very much. I'm from Vietnam

viethuynhquoc
Автор

is the header file of i2c is same for STM32F466RE? and i can't find your i2c header file. please help me...

jhuqjbv
Автор

Good video. I have a question. If I have a signal coming at 65 Hz, at what speed should I set the timer2 to read that signal in input capture mode. Thanks.

lorenefields
Автор

I dont use lcd, how can i show distance on watch1

DuyNguyen-tyuk
Автор

Distance is jumping rarely. I take an object 2 m away from the sensor, but it shows rarely bad value. What is the mistake?

davidbalog
Автор

WHERE should i use the file lcd_userConf?

aniketsubudhi
Автор

Great job! But why would it not be possible to use HAL_delay() instead of delay() in HCSR04_Read() ?

monsieurovni
Автор

I have a question, if we apply to real life, what is the purpose of this project/

Levi.