Arduino CNC Shield-Based Ultrasonic Distance Measurement with Buzzer Alert
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit integrates an Arduino CNC shield with an HC-SR04 Ultrasonic Sensor and a Buzzer, controlled by embedded code. The purpose of the circuit is to measure distances using the ultrasonic sensor and potentially provide feedback or alerts through the buzzer. A Rotary Potentiometer is also included, which may be used to adjust settings or thresholds within the system.
Component List
Arduino CNC Shield
- Description: A shield that plugs into an Arduino board and allows for the control of CNC machines and stepper motors.
- Pins: AREF, GND3, SpinDir, SpinEnable, Z-Endstop, Y-Endstop, X-Endstop, and many others for controlling stepper motors and interfacing with other devices.
HC-SR04 Ultrasonic Sensor
- Description: A sensor that measures distance by emitting ultrasonic waves and measuring the time taken for the echo to return.
- Pins: VCC, TRIG, ECHO, GND.
Buzzer
- Description: An electromechanical component that emits sound when an electrical signal is applied.
- Pins: POSITIVE, NEGATIVE.
Rotary Potentiometer
- Description: A three-terminal resistor with a rotating contact that forms an adjustable voltage divider.
- Pins: leg1, wiper, leg2.
- Properties: Resistance - 10,000 Ohms.
Wiring Details
Arduino CNC Shield
- 5V connected to Rotary Potentiometer leg1 and HC-SR04 VCC.
- GND connected to Rotary Potentiometer leg2, HC-SR04 GND, and Buzzer NEGATIVE.
- Y-STEP (3) connected to HC-SR04 TRIG.
- X-STEP (2) connected to HC-SR04 ECHO.
HC-SR04 Ultrasonic Sensor
- VCC connected to Arduino CNC Shield 5V.
- TRIG connected to Arduino CNC Shield Y-STEP (3).
- ECHO connected to Arduino CNC Shield X-STEP (2).
- GND connected to Arduino CNC Shield GND.
Buzzer
- POSITIVE connected to Rotary Potentiometer wiper.
- NEGATIVE connected to Arduino CNC Shield GND.
Rotary Potentiometer
- leg1 connected to Arduino CNC Shield 5V.
- wiper connected to Buzzer POSITIVE.
- leg2 connected to Arduino CNC Shield GND.
Documented Code
Code for Arduino CNC Shield
/*
* This Arduino Sketch reads distance from an HC-SR04 ultrasonic sensor
* connected to a Wemos D1 R32 (ESP32-based board). The TRIG pin of the
* sensor is connected to IO14, and the ECHO pin is connected to IO27.
* The measured distance is printed to the console.
*/
// Pin definitions
const int trigPin = 27; // IO27 on Wemos D1 R32
const int echoPin = 14; // IO14 on Wemos D1 R32
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Set pin modes
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Read distance from ultrasonic sensor
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2; // Convert to cm
// Print distance to console
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100); // Short delay for stability
}
Filename: sketch.ino
Code for Buzzer
The code for the buzzer is not provided with specific functionality. It appears to be a placeholder for future development.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Filename: sketch.ino
Additional Documentation
No additional documentation is provided for the buzzer.
Filename: documentation.txt