Avoidance sensor arduino

Содержание

Arduino Nano: Infrared Obstacle Avoidance Sensor With Visuino

Introduction: Arduino Nano: Infrared Obstacle Avoidance Sensor With Visuino

Infrared Obstacle Avoidance sensors are cheap, small sensors often used in robots, and Arduino project to detect objects near the sensor.

The Infrared sensors work by sending an infrared light with some frequency, and then detecting if some of the light has reflected back to the sensor. The most common ones have a digital output indicating if object has been detected. Many of them have the option to be enabled or disabled.

In this Instructable, I will show you how easy it is to connect and use such sensor with Arduino.

Some of the sensors have a brief false detection when they are enabled. In the Instructable, I will also show you how you can suppress this false detection with Visuino.

Step 1: Components

  1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
  2. One Infrared Obstacle Avoidance Sensor module I got from this cheap 37 sensors set
  3. 4 Female-Female jumper wires

Step 2: Understand the Infrared Obstacle Avoidance Sensor

The Obstacle Avoidance Sensors usually come in two types — with 3 and 4 pins. The 3 pin version does not have the ability to be enabled/disabled. The 4 pin version has optional Enable pin. Here I am describing the 4 pin version that I have. The information should also be relevant to other versions of the sensor.

The Infrared Obstacle Avoidance Sensor has Power, Ground, Signal, and Enable pins.

There are also 2 potentiometers, and one jumper on the board (See the Picture).

The top potentiometer on the picture is used to adjust how sensitive the sensor is. You can use it to adjust the distance from the object at which the sensor detects it.

The bottom potentiometer on the picture usually should not be changed. It controls the frequency of the infrared signal, and is preset with a good setting. You may need to use it if there is infrared interference with other infrared sources, but otherwise, avoid changing it.

If the Enable pin of the board is not connected, the jumper should be placed on the board as seen on the picture. The jumper permanently enables the board, and if the jumper is placed the Enable pin can’t be used to enable/disable the board.

If you want to use the Enable pin, you have to remove the jumper.

Step 3: Connect the Sensor to Arduino

  1. Make sure the green Enable Jumper is placed on the Infrared Obstacle Avoidance sensor(Picture 1)
  2. Connect Ground(Black wire), Power(Red wire), and Signal(Yellow wire) to the Infrared Obstacle Avoidance Sensor Module(Picture 1)
  3. Connect the other end of the Ground wire(Black wire) to the Ground pin of the Arduino board(Picture 2)
  4. Connect the other end of the Power wire(Red wire) to the 5V power pin of the Arduino board(Picture 2)
  5. Connect the other end of the Signal wire(Yellow wire) to the Digital pin 2 of the Arduino board(Picture 3)
  6. Picture 4 shows where are the Ground, 5V Power, and Digital 2 pins of the Arduino Nano

Step 4: Start Visuino, and Select the Arduino Board Type

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/ .

Make sure that you install 1.6.7 or higher, otherwise this Tutorial will not work!

  1. Start Visuino as shown in the first picture
  2. Click on the «Tools» button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select Arduino Nano as shown in Picture 2

Step 5: In Visuino: Connect the Digital 2 to Digital 13 Pin

Connect the «Out» pin of the Digital[ 2 ] channel of the Arduino component to the «Digital» input pin of the Digital[ 13 ] channel of the Arduino component as shown on the picture

Step 6: Generate, Compile, and Upload the Arduino Code

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 7: And Play.

On Picture 1 you can see the completed and running project. The LED on Pin 13 is On.

If you put object at front of the sensor the LED on Pin 13 will turn Off (Picture 2)

On Picture 3 you can see the complete Visuino diagram.

Step 8: Connect the Enable Line of the Sensor to Arduino

  1. Remove the Enable Jumper from the Obstacle Avoidance Sensor Module(Picture 1)
  2. Connect Enable(Green wire) to the Infrared Obstacle Avoidance Sensor Module(Picture 1)
  3. Connect the other end of the Enable wire(Green wire) to the Digital pin 3 of the Arduino board(Picture 2)
  4. Picture 3 shows with Red Arrow where is the Digital pin 3 of the Arduino Nano

Step 9: Simple Option: in Visuino: Add and Connect Pulse Generator to Enable the Sensor

To test the Enable functionality of the sensor we can use a Pulse generator and set it to enable and disable the sensor periodically.

  1. Type «puls» in the Filter box of the Component Toolbox then select the «Pulse Generator» component (Picture 1), and drop it in the design area
  2. In the Object Inspector, set the value of the «Frequency» property of the PulseGenerator1 component to 0.2 (Picture 2)
  3. Connect the «Out» pin of the PulseGenerator1 component to the «Digital» input pin of the Digital[ 3 ] channel of the Arduino component(Picture 3)

Press F9 to Generate the code, and open the Arduino IDE, then compile and Upload the Sketch as you did in Step 6.

The project will work, but as you can also see in the second part of the Video, the sensor (At least the type, that I have) has a brief false detection when it gets enabled. This may be fine in some cases, but usually is not desirable, so move to the next step to see how you can avoid the problem.

Step 10: Avoid Flase Detection: in Visuino: Add and Connect Infrared(IR) Obstacle Avoidance Sensor Component

  1. Start with a new project, and select Arduino Nano as board type as you did in Step 4
  2. Type «infra» in the Filter box of the Component Toolbox then select the «Infrared(IR) Obstacle Avoidance Sensor» component (Picture 1), and drop it in the design area
  3. Connect the «Out» pin of the Digital[ 2 ] channel of the Arduino component to the «In» pin of the ObstacleAvoidance1 component (Picture 2)
  4. Connect the «Out» pin of the ObstacleAvoidance1 component to the «Digital» input pin of the Digital[ 13 ] channel of the Arduino component(Picture 3)

Step 11: In Visuino: Add and Connect Pulse Generator to Enable the Sensor

  1. Type «pul» in the Filter box of the Component Toolbox then select the «Pulse Generator» component (Picture 1), and drop it in the design area
  2. In the Object Inspector, set the value of the «Frequency» property of the PulseGenerator1 component to 0.2 (Picture 2)
  3. Connect the «Out» pin of the PulseGenerator1 component to the «Enable» input pin of the ObstacleAvoidance1 component(Picture 3)
  4. Connect the «Enable» output pin of the ObstacleAvoidance1 component to the «Digital» input pin of the Digital[ 3 ] channel of the Arduino component(Picture 4)
  5. You can optionally specify a different delay for ignoring false detection when enabling the Sensor, by setting a different value for the EnableDelay property of the ObstacleAvoidance1 component in the Object Inspector (Picture 5)

Step 12: And Play.

On Picture 1 you can see the completed and powered up project, and the sensor with the disconnected Enable Jumper.

In the last part of the video you can see that when the sensor is enabled it has a brief false detection, but that detection is not shown in the LED on Pin 13. The «Infrared(IR) Obstacle Avoidance Sensor» component in Visuino suppresses the false detection when enabling the sensor.

Congratulations! You have mastered using Infrared Obstacle Avoidance Sensor module with Arduino, and Visuino.

On Picture 2 you can see the complete Visuino diagram.

Источник

Как подключить датчик препятствия к Ардуино

Оптический датчик препятствия (KY-032) — это один из самых распространенных датчиков, который прекрасно подойдет роботу или машинке на Ардуино для объезда препятствий. Датчик очень прост по принципу своей работы и способу подключения к плате Arduino Uno. Рассмотрим устройство датчика, схему его подключения и рассмотрим несколько примеров программ для работы с avoid sensor arduino.

Характеристики датчика препятствия (KY-032)

Схема работы ИК датчика препятствий довольно простая. На модуле расположен инфракрасный светодиод с линзой, который постоянно включен и излучает узкий пучок ИК излучения. Детектором отраженного сигнала от препятствия служит фотодиод или фототранзистор. Также на печатной плате расположен светодиод для индикации и два подстроечных резистора для настройки чувствительности датчика ky-032.

Устройство излучает инфракрасный луч с частотой 38 кГц, который принимается приемником на плате. При приближении предмета к сенсору (необходимое расстояние регулируется потенциометром на модуле) на выходе платы «OUT» появляется низкий уровень напряжения и включается встроенный светодиод. Дальность срабатывания (чувствительность) датчика препятствия регулируется от 2 до 40 сантиметров.

Подключение датчика препятствия к Arduino

Для этого занятия потребуется:

  • Arduino Uno / Arduino Nano / Arduino Mega;
  • датчик препятствия KY-032;
  • беспаечная макетная плата;
  • светодиод и резистор;
  • провода «папа-мама», «папа-папа».

Для подключения датчика обнаружения препятствий к Arduino имеется три или четыре контакта. Два контакта на модуле KY-032 служат для питания от 5V (схему подключения датчика смотри на картинке выше). Еще два контакта формируют импульсы для платы Arduino Mega или Arduino Uno. Для примера работы рассмотрим скетч, который будет включать светодиод при появлении препятствия.

Счетч для датчика препятствий (KY-032)

Пояснения к коду:

  1. для приема сигнала с датчика KY-032 используется порт A1, который можно поменять в программе на любой порт общего назначения;
  2. датчик отправляет сигнал «логическая единица» при появлении препятствия.

Заключение. Для создания шагающего робота или автономной машинки на Ардуино сенсор KY-032 отлично подойдет начинающему программисту. Датчик препятствия более прост в настройке и подключении, в отличии от дальномера HC-SR04. При этом сенсор хорошо справляется с распознаванием объектов перед ним и может использоваться в машинках для объезда препятствий или езде по лабиринту.

Источник

Infrared Sensor Module Interfacing with Arduino – Obstacle Detection

In this tutorial, we will learn about infrared sensor module and how to use it with Arduino. We will first introduce you to the IR sensor, its applications, working principle and then interface it with Arduino and program it for obstacle detection.

Before reading this article, make sure you are already familiar with Arduino UNO. If you haven’t used Arduino Uno R3 before, then check the following link.

Introduction to Infrared Obstacle Avoidance Sensor Module

Infrared sensor is an electronic device which is used to detect objects via heat. It works with the detection of infrared radiations and changes in heat in its surrounding. There are two types of infrared sensors available in the market.

  • Thermal infrared sensor: It works by the changes of heat in its surrounding or uses infrared radiations as a heat source.
  • Photo infrared sensor: It uses a photo diode to detect infrared radiations. We will focus on this type of IR sensor.

Several types of infrared obstacles avoidance sensor modules are available in the market but the one we will focus on in this article is the photo IR obstacle avoidance sensor module, FC-51.

The Infrared obstacle avoidance sensor module (FC-51) is the combination of two infrared sensors. First one is an infrared transmitter and the second one is an infrared receiver. The infrared transmitter emits the infrared light through the LED. This infrared light has a certain frequency and when it is reflected back after the collision of any obstacle or object then this light is received by the infrared receiver. Then this infrared obstacles avoidance sensor tells the system, that someone is present in this particular area.

It can easily detect the object from 2 to 30 cm area and its detection angle is 35 o .

This infrared obstacles avoidance sensor module has been currently used in so many applications such as in robotic industry, automobile industry and security purposes, etc. It is easily available in the market or online shop.

Pin Out

This infrared obstacle avoidance sensor module consists of three pins:

  1. VCC: This is the pin that supplies power to the IR sensor module. 3.3 to 5 Volts DC voltage is applied to turn on this sensor
  2. GND: This is the ground pin which is connected to the input ground.
  3. OUT: This is the output pin of this sensor which is connected with any type of controller. When an obstacle is in front of the sensor, this pin is in a LOW state.

The IR sensor module also consists of other components such as an IR emitter LED which emits the infrared light, an IR receiver LED which receives the light after the collision with any object, a power LED which turns on when this sensor is powered up, distance adjuster, through this, the user can easily adjust the range or distance of sensor by increasing or decreasing the potentiometer resistance. Lastly, the obstacle LED which turns ON whenever an obstacle is detected.

Working Principle of Infrared Obstacle Avoidance Sensor Module

The working principle of this infrared obstacles sensor module is very simple. As this sensor consists of one IR transmitter and one IR receiver, therefore, the main work is done by them.

When an IR transmitter emits the infrared light during the presence of an object, then some portion of this infrared light is reflected back to the IR transmitter after the collision with the object. So, the reflected portion of the infrared light is received by the IR receiver. This reflected portion has some light intensity and based on this intensity the output of this infrared obstacle avoidance sensor module is defined. In other words, this light intensity is inversely proportional to output voltages. This means that when the intensity is increased then the resistance of this module is increased therefore the output voltages are dropped. Similarly, when intensity is decreased then resistance is decreased so the output voltages are increased. These output voltages are received by the controller from OUT pin of this module. Hence when an obstacle is detected, the OUT pin goes LOW. otherwise it stays HIGH.

Circuit diagram of Infrared Obstacle Avoidance Sensor Module

Circuit diagram of infrared sensor is given below.

infrared circuit diagram

The IR Sensor Module consists of the following components:

  • IR receiver TSFF5210
  • Photodiode
  • 100 ohm resistor
  • 10k resistor
  • 10k variable resistor
  • LM358 IC

The infrared receiver Led and the photo diode constitute the main parts of this sensor module. The photo diode emits the infrared radiations which strike any object and reflect back with some angle. The IR receiver TSFF5210 detects these reflected radiations.

LM358 is used as a comparator. Whenever the IR receiver detects the infrared radiations, the output of LM358 goes high therefore the LED connected at the output turns ON. This output pin is used to interface with Arduino Uno R3.

Applications of Infrared sensor

Infrared sensors have many applications now a days from domestic use to industrial use. Some of the applications are mentioned below.

  • Object detection
  • Motion detection
  • Obstacle avoidance robot
  • Gas leakage detection
  • Smoke detection
  • Distance measurement
  • Robotics
  • Object counter and many others

Interface IR Obstacle Avoidance Sensor Module with Arduino

We will be requiring the following components.

  1. Arduino UNO
  2. Infrared Obstacle Avoidance Sensor Module (FC-51)
  3. Connecting Wires

Assemble the devices as shown in the schematic diagram below:

We will connect 3 pins of the sensor module with Arduino. These include the VCC, GND, and OUT pins. The VCC will be connected with the 5V pin from Arduino. GND of both the devices will be in common. We will connect Arduino digital pin 2 with the OUT pin of the sensor.

You can use appropriate digital pin of Arduino to connect with the sensor module’s OUT pin.

infrared sensor interfacing with arduino uno r3

Arduino Sketch for Infrared Obstacle Avoidance Sensor

Open your Arduino IDE and go to File > New to open a new file. Copy the code given below in that file.

The following sketch will turn the onboard LED of Arduino ON, when an obstacle is detected in front of the sensor.

How the Code Works?

The first step is to define the Arduino digital pin that we have connected with the IR sensor’s OUT pin. It is pin 2 in our case.

Inside the setup() function, we will configure the sensor pin as an input pin and the Arduino’s onboard LED pin as the output pin.

Inside the infinite loop() function, we will first find out the sensor output value using digitalRead(). We will pass the digital pin connected to the sensor as an argument inside it.

Then, we will check if the sensor output is HIGH or LOW. Remember the output will be HIGH when no obstacle is present and LOW when an obstacle is detected. If the output is HIGH then the onboard LED will stay OFF. However, if the output is LOW which means an obstacle is detected in front of the sensor, then the Arduino’s onboard LED will turn ON.

Источник

Adblock
detector