# 13 - Motor DC + Sensor IR Sharp GP2Y0A21

> **Arduino IDE**
>
> [**UNO / MEGA / NANO**](https://docs.microside.com/practicas/arduino-ide)

<figure><img src="/files/C0BkpeIPVlNFpcOqGl4k" alt="" width="389"><figcaption></figcaption></figure>

## **Introducción**

En esta práctica se implementa el control de un motor de corriente directa, usando los módulos PWM y ADC a través de un sensor SHARP para variar la velocidad. La velocidad del motor, depende de la distancia que haya entre un objeto y el sensor infrarrojo.

## **Descripción**

En esta práctica se realiza el control de velocidad de un motor DC, usando los módulos internos ADC y PWM por medio de un sensor Sharp conectado a las tarjetas **UNO,  MEGA** o **NANO**.

#### **Materiales:**

1 x Tarjeta **UNO**, **MEGA** o **NANO.**.&#x20;

1 x Sensor IR Sharp GP2Y0A21.

1 x Diodo 1N4001.

1 x Transistor NPN 2N3904.

1 x Motor DC 9 a 12 volts.

1 x Juego de cable Dupont.

1 x Protoboard de 830 puntos.

1 x Cable micro USB.

#### **Software:**

Windows 8.1 o posterior.

Arduino® IDE. [**Descarga**](https://www.arduino.cc/en/Main/Software)

## &#x20;**Procedimiento**

1. En el apartado de “[**Diagrama Esquemático**](#diagrama-esquematico)” selecciona el modelo de tu tarjeta, realiza las conexiones que se muestran en la imagen y conéctala a la computadora.
2. Ejecuta el software **Arduino® IDE**, crea un nuevo proyecto con el código fuente que se encuentra en el apartado "[**Código**](#codigo)" y compila el programa.

{% hint style="success" %}
Si tienes dudas de cómo realizar los pasos anteriores puedes encontrar un manual de **Arduino® IDE** a través del siguiente [**link**](https://docs.microside.com/practicas/ides/arduino-r-ide).
{% endhint %}

3. Al terminar de programar, el módulo se reiniciará y el programa de esta práctica se ejecutará.

## Diagrama esquemático

{% tabs %}
{% tab title="UNO" %}

<figure><img src="/files/MUiZ71n2tuusWs6DTy1A" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="MEGA" %}

<figure><img src="/files/mbcsr0Ma2ZxynQjlLqJF" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="NANO" %}

<figure><img src="/files/ACI4bmE2ux8N5um4TyHx" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## Código

{% tabs %}
{% tab title="Proyecto Arduino" %}
{% embed url="<https://gist.github.com/microside-mx/be656209c00750bee7f570e26fb3f516#file-13-motordcinfrarrojo-arduino-ino>" %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.microside.com/practicas/arduino-ide/13-motor-dc-+-sensor-ir-sharp-gp2y0a21.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
