1. Goal/Purpose
I do mobile robot, ultrasonic or infrared ranging alarm is sure, a small experiment, the purpose is to ultrasonic ranging, OLED display the distance from the front obstacle, distance over the hour, buzzer alarm, and the smaller the alarm frequency of the more rapid beep.
2. Hardware
(1) stm32f1
(2) Ultrasonic Hc-sro4
(3) OLED12864
(4) BEEP
3. Hardware parameters
(1) Single chip microcomputer STM32F1
(2) Ultrasonic module Hc-sro4
1: Use voltage: dc5v
2: quiescent current: Less than 2mA
3: Level output: 5V high
4: Level output: Bottom 0V
5: Induction angle: No more than 15 degrees
6: Detection range: 2cm-450cm
7: High accuracy: up to 0.3cm
On-board connection, VCC---+ trig (control side)--pa8, Echo (receiver)--pa7, out (empty foot), gnd--ground
Note: The trip pin is an internal pull-up 10K resistor that pulls the low trip pin with the IO port of the microcontroller and then gives a pulse signal of more than 10US.
Out foot for this module as an anti-theft module when the switch output foot, ranging module does not use this foot.
Using the IO port trig to trigger ranging, to give a minimum of 10us high-level signal. The module automatically sends 8 40khz square waves, detects if there is a signal to return, a signal is returned, through the IO port echo output a high level, while the timer timer, when this port becomes low, it can read the value of the timer, high-level continuous time is the ultrasonic from the launch to the return time. Test distance = (340m/s)/2us/58= cm or us/148= inch, (US for Echo high signal duration) The recommended measurement period is above 60ms to prevent the impact of the transmitting signal on the echo signal.
(3) OLED12864
IIC communication as shown in figure. SCL---PB6,SCL---PB7
(4) BEEP (Passive)
The passive buzzer means that an audio drive signal is required to make it sound, as opposed to an active buzzer. The active buzzer only needs to pass the direct current electricity to emit the beep sound, the active buzzer inside comes with the oscillator.
+ pa11,-connected GND, timer PWM Pulse drive.
4. Procedures
Attached procedure