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 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:
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:
Common Challenges: