Detecting obstacles using an ultrasonic sensor HC-SR04

Detecting obstacles using an ultrasonic sensor HC-SR04

1 HC-SR04: a cheap ultrasonic sensor

1.1 Description

HC-SR04 front view
Fig.1 – An HC-SR04 seen from front side.

HC-SR04 is a commonly used ultrasonic sensor which is capable to detect obstacles in a range of 2-300cm. The sensor looks like a small PCB having two metal cylinders on the front-side and a small circuit on the back-side (see Fig.1).

1.2 Documentation

In this article we will provide a simple demo to use HC-SR04. This requires a preliminary read of the sensor user manual:
HC-SR04 User Manual

1.3 Pinmap description

The sensor has 4 PIN:

  1. VCC, which must be connected to 5V;
  2. Trig, which is an input PIN to trigger the measurement;
  3. Echo, which is an output PIN which sent out a square wave;
  4. GND, which must be connected to ground.

Note that user manual specifies which GND must be connected first since a floating 5V could permanently damage the sensor.

2 How it works

The two cylinders are actually an ultrasonic receiver (R) and an ultrasonic transmitter (T) which are driven by the circuitry. The working principle is quite simple: when triggered the transmitter shoots some pulses. When sound encounters an obstacle it is echoed back and detected by the receiver. continue reading…

Mikroe Clicker 2 for STM32 and STLink v2

Mikroe Clicker 2 for STM32 and STLink v2

1 Introduction

In this tutorial we are going to see how to connect a STLink v2 debugger to a Clicker 2 for STM32 enabling users to do debugging which could be very useful in development phases. A debugger is a computer program which is used to test and debug another program usually named Target.

In embedded things are slightly different since the code is executed on an external MCU and it is required an interface Computer-MCU. In this case the Target is the MCU and a debugger is composed by the ensemble of a hardware and a software tool. Nonetheless, when the majority of people is talking about debugger,they are referring only to the hardware part.

A debugger allows the connection to a Target enabling the Host to load a firmware on it managing its code execution, allowing the inspection of its registers and much more. To do this, it uses some specific commands that usually depend on the MCU architecture: this means that there are specific debuggers for specific MCUs. The STLink v2 is a low cost debugger supporting both STM32 and STM8. In what follows we are going to use OpenOCD, an open source debugging software largely used in ChibiStudio since it is a reliable solution for debugging. continue reading…