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

Touchless Interaction Using Arduino and Ultrasonic Sensor

Touchless interaction is becoming increasingly important in today's world, especially in the context of hygiene and convenience. It allows users to interact with devices without physical contact, reducing the risk of contamination and wear on mechanical parts. This article will guide you through creating a touchless interaction system using an Arduino and an ultrasonic sensor. The project will be adjusted for the Arduino environment to ensure compatibility and ease of implementation.

Project: The objective of this project is to create a touchless interaction system that can detect the presence of an object (like a hand) within a certain range and trigger an action, such as turning on an LED. This can be used in various applications, such as touchless switches, automatic hand sanitizers, and more. The system will measure the distance to an object using an ultrasonic sensor and activate an LED when the object is within a specified range.

Components List:

  • Arduino Uno (1)
  • Ultrasonic Sensor (HC-SR04) (1)
  • LED (1)
  • Resistor (220 ohms) (1)
  • Breadboard (1)
  • Jumper wires (several)

Examples:

// Define pins for the ultrasonic sensor and LED
const int trigPin = 9;
const int echoPin = 10;
const int ledPin = 13;

// Variables to store the duration and distance
long duration;
int distance;

void setup() {
  // Initialize the serial monitor
  Serial.begin(9600);

  // Set the pin modes
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Clear the trigPin by setting it LOW
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  // Set the trigPin HIGH for 10 microseconds to send out the pulse
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Read the echoPin and calculate the duration of the pulse
  duration = pulseIn(echoPin, HIGH);

  // Calculate the distance in centimeters
  distance = duration * 0.034 / 2;

  // Print the distance to the serial monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Check if the distance is within the range (e.g., less than 10 cm)
  if (distance < 10) {
    digitalWrite(ledPin, HIGH); // Turn on the LED
  } else {
    digitalWrite(ledPin, LOW); // Turn off the LED
  }

  // Small delay to prevent spamming the serial monitor
  delay(500);
}

Explanation:

  1. Pin Definitions: The ultrasonic sensor's trigPin and echoPin are connected to pins 9 and 10, respectively. The LED is connected to pin 13.
  2. Setup Function: Initializes the serial monitor and sets the pin modes.
  3. Loop Function:
    • Clears the trigPin, sends a 10-microsecond pulse to trigger the sensor, and reads the echoPin to measure the duration of the pulse.
    • Calculates the distance based on the duration.
    • Prints the distance to the serial monitor.
    • Checks if the distance is less than 10 cm and turns the LED on or off accordingly.

Common Challenges:

  • Incorrect Pin Connections: Ensure that the trigPin and echoPin are correctly connected to the specified pins on the Arduino.
  • Noise and Interference: Ultrasonic sensors can be affected by noise and interference. Adding a small delay between measurements can help reduce this.
  • Power Supply Issues: Ensure that the Arduino and sensor are properly powered to avoid inconsistent readings.

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.