Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Infrared Sensors

Infrared Sensors for Arduino Projects

Introduction: Infrared sensors are widely used in various applications, including robotics, automation, and security systems. These sensors can detect and measure infrared radiation, allowing for the detection of objects, motion, and temperature changes. In this article, we will explore the importance and utility of infrared sensors and provide examples of Arduino projects using these sensors.

Project: For this example project, we will create a simple object detection system using an infrared sensor and an Arduino board. The objective is to detect the presence of an object and trigger an action, such as turning on an LED or activating a motor. This project can be extended to various applications, such as automatic doors, obstacle avoidance robots, or motion-activated lighting systems.

Component List: To complete this project, you will need the following components:

  • Arduino board (e.g., Arduino Uno)
  • Infrared sensor module (e.g., KY-022)
  • Breadboard
  • Jumper wires
  • LED
  • Resistor (220 ohms)
  • Optional: Motor driver module or relay module (if you want to control motors or other high-power devices)

Examples: Example 1: Object Detection with LED

int infraredPin = 2; // Connect the sensor output pin to digital pin 2
int ledPin = 13; // Connect the LED to digital pin 13

void setup() {
  pinMode(infraredPin, INPUT); // Set the sensor pin as input
  pinMode(ledPin, OUTPUT); // Set the LED pin as output
}

void loop() {
  int objectDetected = digitalRead(infraredPin); // Read the sensor value

  if (objectDetected == HIGH) {
    digitalWrite(ledPin, HIGH); // Turn on the LED if an object is detected
  } else {
    digitalWrite(ledPin, LOW); // Turn off the LED if no object is detected
  }
}

Explanation: This code sets up the infrared sensor pin as an input and the LED pin as an output. It continuously reads the sensor value and checks if an object is detected. If an object is detected (sensor value is HIGH), it turns on the LED; otherwise, it turns off the LED.

Example 2: Object Detection with Motor Control

int infraredPin = 2; // Connect the sensor output pin to digital pin 2
int motorPin = 9; // Connect the motor control pin to digital pin 9

void setup() {
  pinMode(infraredPin, INPUT); // Set the sensor pin as input
  pinMode(motorPin, OUTPUT); // Set the motor control pin as output
}

void loop() {
  int objectDetected = digitalRead(infraredPin); // Read the sensor value

  if (objectDetected == HIGH) {
    digitalWrite(motorPin, HIGH); // Turn on the motor if an object is detected
  } else {
    digitalWrite(motorPin, LOW); // Turn off the motor if no object is detected
  }
}

Explanation: This code is similar to Example 1 but instead of controlling an LED, it controls a motor. Connect the motor to the motor control pin (e.g., using a motor driver module) and adjust the code accordingly.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.