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…

STM32 Nucleo-144 review

STM32 Nucleo-144 Review

1 Introducing new Nucleo-144

The STM32 Nucleo-144 is a new series of development board by STMicroelectronics. It is the third announced series titled Nucleo. Each Nucleo-144 share the same pin map for each board and features a new connector named ST ZIO which is compatible with Arduino Uno Rev3 connector.

This new series takes his name from the number of pads exhibit by its different MCUs which are all a LQFP144 package. Indeed, the STM32 Nucleo is currently available in 5 configurations we will discuss later. continue reading…

Reading a Joystick on STM32 using ChibiOS

Reading a Joystick on STM32 using ChibiOS

1 2-axis and a key button

The joystick proposed here is much known between makers. It provides two axis and a key button and every axis is actually a potentiometer: that means axis data is analogue and we need to use ADC to read its positioning.

Joystick schematic
Fig.1 – Internal schematic of a Joystick with key.

Potentiometers are provided of springs so, without forcing, wipers are approximately positioned in the centre of the two resistive elements. As this device is very simple to use, it is not easy find a related datasheet. Indeed, for the most of the applications, it would be useless. Anyway, joystick used in this demo is a very cheap one marked as “Keyes_SJoys” (See Fig.1).

2 Schematic and pin out

Our device has 5 pins:

  1. GND, connection to ground;
  2. +5V, should be meant as connection to VCC;
  3. VRx, X-axis wiper ;
  4. VRy, Y-axis wiper;
  5. SW, switch terminal.

Note that pins are almost the same for every 2-axis Joystick you can buy online. There are some variant which have two or no switch. continue reading…