Monthly Archives: November 2017

Arduino Tutorial: IR Distance / Line Tracing / Line Tracking Sensor (MH Sensor Series/KY-033/TCRT5000)

IR distance sensor (MH Sensor Series, KY-033, TCRT5000).

IR distance sensor (MH Sensor Series, KY-033, TCRT5000).

In this tutorial, it is shown how to use an IR distance sensor with an Arduino Uno. The todays sensor comes in many names: MH Sensor Series, KY-033 (variant with 3 pins), TCRT5000, etc. Moreover, it is often advertised as IR distance sensor, line tracing sensor or line tracking sensor.
In addition to the IR distance sensor, this tutorial makes use of an LCD module called “LCM1602 IIC V1” which is utilized to show sensor values. The main advantage of the LCM1602 IIC V1 is that it is very easy-to-use. For example, it can be controlled by setting up an I2C connection.

List of materials:
– Arduino Uno [Search on Aliexpress | Amazon]
– Jumper wires [Search on Aliexpress | Amazon]
– Mini breadboard [Search on Aliexpress | Amazon]
– MH Sensor Series [Search on Aliexpress | Amazon]
– LCM1602 IIC V1 (LCD) [Search on Aliexpress | Amazon]

Remark: Some variants of the module type, such as the KY-033, have only three pins. Typically, the A0 pin is missing. Moreover, the D0 pin is often labeled as S. If you own such a variant, this tutorial is still of use to you. Just ignore the part related to the A0 pin.

Pin layout:

The scheme shows how to wire the MH Sensor Series and the LCM1602 IIC V1 to an Arduino Uno.

The IR sensor and the LCM1602 module have only four pins. The GND pins of both modules must be connected to the Arduino’s GND pins. The same applies to the VCC pins which must be connected to the Arduino’s 5V pin. As the Arduino Uno has only a single 5V pin, a mini breadboard is used to “split” the 5V pin. Next, the A0 and D0 pin of the IR sensor must be connected to the Arduino. The A0 pin is the raw analog value (0-1023) of the measured distance between the sensor and an obstacle. In this tutorial, A0 is connected to the Arduino’s A0 pin. The D0 pin is a digital pin that goes to HIGH state if the analog value is greater than or equal to a specific threshold. The threshold can be adjusted by the blue trimpot of the IR distance sensor. Here, D0 is connected to the Arduino’s pin 8.
As a last step, the LCM1602 module’s SDA and SCL pins must be connected to the corresponding SDA and SCL pins of the Arduino Uno.

Example source code

// (c) Michael Schoeffler 2017, http://www.mschoeffler.de
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // initializes the LCM1602 IIC V1 (LCD module)
// 0x27 is the I2C address. This address might be different.

const int IN_A0 = A0; // analog input
const int IN_D0 = 8; // digital input

void setup() {
  pinMode (IN_A0, INPUT);
  pinMode (IN_D0, INPUT);
  lcd.begin(16, 2); // begins connection to the LCD module
  lcd.backlight(); // turns on the backlight
}

int value_A0;
bool value_D0;

void loop() {

  value_A0 = analogRead(IN_A0); // reads the analog input from the IR distance sensor
  value_D0 = digitalRead(IN_D0);// reads the digital input from the IR distance sensor
  
  lcd.setCursor(0, 0); // sets the cursor of the LCD module to the first line
  lcd.print("A0:");
  lcd.setCursor(3, 0); // sets the cursor of the LCD module to the fourth character
  lcd.print(value_A0); // prints analog value on the LCD module
  
  lcd.setCursor(0, 1); // sets the cursor of the LCD module to the first line
  lcd.print("D0:");
  lcd.setCursor(3, 1); // sets the cursor of the LCD module to the fourth character
  lcd.print(value_D0); // prints digital value on the LCD module
  
  delay(1000);
}

 

If the code has been compiled and transmitted to the Arduino Uno, the LCD module should show the distance between the IR distance sensor and an obstacle. Keep in mind that the distance is indicated by a analog value between 0 and 1023. Unfortunately, it is very challenging to convert the analog value to a metric unit of length, such as meter or centimeter. The reason is that the measured analog value is strongly influenced by the obstacle’s material. For example, black surface does reflect far less light than white surface. As a consequence, the measured analog value will differ. Interestingly, this characteristic can be used in order to use the IR distance sensor as a “black or white” detector. This application can often be found in “car assembly kits” where multiple IR sensors are mounted on the undercar. As a result, the car is capable of following a black line that is drawn on white ground.

The following pictures show distance measurements with black and white material. Although the distance is about the same, the measured analog value (A0) differs strongly:

The IR distance sensor measures black material. The analog sensor value is much higher than when measuring white material (A0 = 949).

The IR distance sensor measures white material. The analog sensor value is much lower than when measuring black material (A0 = 525).

Video tutorial

Seven Ways To Supply Power to a Breadboard

When doing prototype work with breadboards for a project, the question comes up “how to power the breadboard?” at the very start. Therefore, a power supply must be chosen that fulfills the requirements of the specific project. There exist a wide range of different alternatives to provide power to a breadboard. Each alternative has different characteristics. In this article, seven alternatives are presented ranging from low-cost USB-based power supplies to AC/DC power supply units.

Alternative 1 (cheap): Microcontroller [Search on Aliexpress | Amazon]

It seems natural to use a microcontroller to power the other components on the breadboard, if you utilize a microcontroller anyway. The advantage is that you require only a single USB cable (or DC plug) to provide power to the microcontroller and all the other components on the breadboard. However, this alternative has at least two drawbacks: First, a typical microcontroller features only very few voltage options. For example, an Arduino Uno has pins for 3.3V and 5V. Second, the current is often limited. For example, when utilizing an Arduino Uno, you can safely draw about 400mA from the 5V pin. In case your microcontroller does not have any output pins to provide power, this alternative is off the table.

 

Alternative 2 (cheap): Breadboard power supply [Search on Aliexpress | Amazon]

Breadboard power supplies are specifically designed for applications involving a breadboard. As a result, they fit perfectly on a breadboard in order to supply power to the “plus and minus lines”.
Moreover, most breadboard supplies have multiple convenience features: For example, the possibility to plug in different power connectors, such as USB or DC plugs. Furthermore, a switch to ‘switch on’ or ‘switch off’ the power as well as an LED to show whether the power supply is enabled or disabled. In addition, you often can choose whether to supply 3.3V or 5V to the “plus and minus” lines.
In comparison to using microcontrollers for powering,  breadboard power supplies often allow you to draw more current than microcontrollers. Unfortunately, most of them are also limited to outpout only 3.3V or 5V. If you require higher voltages, this alternative might not be an option for you.

 

Alternative 3 (cheap): Batteries [Search on Aliexpress | Amazon]
+ battery holder [Search on Aliexpress | Amazon]
+ PCB terminal [Search on Aliexpress | Amazon]

If you already own a pack of batteries, you can also use them for powering. Especially if you own multiple batteries, you can chain them in order to obtain, e.g., a voltage supply having more than 5V. This alternative becomes even better, if you also own a battery holder and a PCB terminal. Then, it becomes very easy to connect the batteries to a breadboard.
For example, if you require more than 5V, you can connect two 3.7V Li-Ion batteries in series to obtain about 7.4V. A major downside of this alternative is that the provided voltage of batteries is dependent on their charging level. As a consequence, this alternative is not suited if a constant voltage is required to power the components. Nonetheless, if you plan to use batteries as power supply for the final version of your project, it might makes sense to use this type of power supply also in the prototype phase.

 

Alternative 4 (cheap): USB DC-DC Step-up Cables [Search on Aliexpress | Amazon]

Compared to connecting batteries in series, utilizing USB DC-DC Step-Up cables is a more convenient alternative to obtain higher voltages. The principle is very simple, these cables have a USB connector on the one end, a DC connector on the other end, and in-between a Step-up module. The Step-up modules transform the 5V coming from the USB connector to a higher voltage, such as 9V or 12V. With the help of a female power jack connector, it is quite simple to bring 9V or 12V to the breadboard. Due to their compact construction, the current you can draw from these Step-up cables is often limited to 750mA or 1000mA.

 

Alternative 5 (reasonably priced): DC Transformer [Search on Aliexpress | Amazon]

In order to draw more power from a 9V or a 12V power supply, a DC transformer can be used. DC transformers are quite common for providing 12V LEDs with power. Alternatively, they can also be used to supply power to breadboards. In comparison to USB DC-DC Step-up cables, they are much more bulky. However, mainly due to their size, they can provide much more power to a breadboard. There exist many different variants, such as 10W DC transformers or 100W DC transformers. Typically when working with breadboards, very high power values are not required. Nonetheless, if, for example, an external power-hungry device has also to be provided by the same power supply as the breadboard, a dc transformer might be a good choice.

 

Alternative 6 (cheap): DC-DC Adjustable Boost Module [Search on Aliexpress | Amazon]

The previous alternatives share the same disadvantage that the provided voltage is typically not adjustable. So-called DC-DC adjustable boost modules overcome this drawback by featuring a potentiometer that can be adjusted by a screwdriver. In particular, the potentiometer controls the provided output voltage. Moreover, many of these modules feature also a USB input. The disadvantage of such module is that they are often limited to 1 or 2 Amperes that can be drawn. Therefore, there range of applications is limited.

 

Alternative 7 (reasonably priced to expensive): DC power supply unit [Search on Aliexpress | Amazon]

The highest degree of flexibility is offered by DC power supply units. In comparison to the other alternatives, this is the most bulkiest and also most expensive alternative. Though, size and prices can differ a lot between different types of DC supply units. The main advantage of DC power supplies is that the provided voltage can be adjusted very precisely. Moreover, they often provide more power than DC-DC Adjustable Boost Modules. If a DC supply unit is chosen as power supply for a breadboard, you should not forget to look out for a plug that connects the DC supply to the breadboard (e.g. “Banana-to-DuPont-connector”).

 

Related video:

Tutorial: How to crimp DuPont/Mini-PV connectors [Engineer PA-09 connector pliers]

This tutorial is about crimping Mini-PV connectors with a generic crimp tool (Engineer PA-09). Mini-PV connectors are also known as DuPont connectors, especially in the context of “breadboard prototyping” where the corresponding wires are often referred to as “DuPont jumper wires”.

You might ask yourself why do people use two different names for the same type of connectors? To put it simple: Mini-PV/DuPont connectors were originally made by a company called Berg Electronics which was part of DuPont Connector Systems. Later, Dupont Connector Systems sold Berg Electronics to Hicks, Muse, Tate, and Furst (private equity company). In 1998, Berg Electronics Corporation was acquired by FCI (Framatome Connectors International, Inc.). Then, FCI was aquired by Amphenol Corporation in 2016. Today, Amphenol Corporation lists the connectors under the name “Mini-PV Basics”.

Mini-PV can be considered a as proprietary connector type. Therefore, there exist also an official tool to crimp Mini-PV connectors. Originally, only female Mini-PV connectors were available. The original crimp tool for these female Mini-PVs is called HT-0095 (HT-95). This tool was sold since the beginning and therefore, you can also find used ones also with a DuPont branding. Today, there exists also an official crimp tool for male connectors: the HT-102. Unfortunately, both tools are very expensive and cost far more than 1000$. Depending on the country you are in, you can find used tools much cheaper on eBay. In this tutorial, I make use of the Japanese PA-09 “generic” connector pliers. Compared to the original HT-95 and HT-102, the PA-09 can be considered as cheap (30-50$). Nonetheless, the crimps made with the PA-09 turn out very suitable for most applications. One more remark: Engineer, the manufacturer of the PA-09 pliers, does not advertise the PA-09 to be compatible with Mini-PV/DuPont connectors. Still, you can find many video, articles and pictures, in which people are using them to crimp Mini-PV and seem also satisfied with the quality.
Of course, the PA-09 is not required for this tutorial, any generic crimp tool that provides sufficient quality can be used. Moreover, it is only shown how to crimp female connectors. Fortunately, you can apply the same procedure in order to crimp male connectors.

List of Materials:
– Wire (e.g., 28AWG/0.5mm²) [Search on Aliexpress | Amazon]
– DuPont connector [Search on Aliexpress | Amazon]
– DuPont connector shell [Search on Aliexpress | Amazon]

Materials required for this tutorial: some wire, DuPont/Mini-PV connectors, and connector shells.

Materials required for this tutorial: some wire, DuPont/Mini-PV connectors, and connector shells.

List of tools that I use in this tutorial:
– Engineer NS-04 Micro nippers [Search on Aliexpress | Amazon]
– Engineer PA-14 Wire Stripper [Search on Aliexpress | Amazon]
– Engineer PA-09 connector pliers [Search on Aliexpress | Amazon]

Tools that I use in this tutorial: NS-04 Micro Nippers, PA-14 Wire Stripper, and PA-09 Connector Pliers (any other set of suitable tools can be used).

Tools that I use in this tutorial: NS-04 Micro Nippers, PA-14 Wire Stripper, and PA-09 Connector Pliers (any other set of suitable tools can be used).

1) The first step is to cut off some wire. The length is totally up to you.

2) Next, the wire must be stripped.

If you are not sure how many insulation you should strip off, then have a look at the next picture. The picture shows were you have to make the crimps. If you use also the PA-09, then you have to make two crimps: the “insulation crimp” and the “wire crimp”. As you can see on the picture, only a small part of the wire has to be stripped off.

3) Then, the first crimp has to made. It is totally up to you, whether to start with the insulation or the wire crimp. I personally prefer to start with the insulation crimp:

4) If the first crimp was successful, the other crimp has to be made. As I started with the insulation crimp, I have to do the wire crimp next.

If you did both crimps, your connector should now look like this:

As you can see, the wire crimp looks fine but the insulation crimp looks a bit sloppy. In particular, the connector has been “drilled” through the insulation. If an original crimp tool was used, the insulation would be coated by the lower part of connector. The “damaged” insulation cannot be avoided if such generic crimp tools are used. The crimp mechanism of the original tools is more complex, e.g., two coils are used to perfectly coat the insulation by the lower part of the connector. Nonetheless, the achieved crimping quality should be sufficient for many applications.

5) The final step is to add a shell to the connector:

6) The same steps have to be applied to the other end of the wire. If everything is executed correctly, the final result should look like this:

Video Tutorial:

 

Another related video about red and black jumper wires: