Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: "Distance Measurement" - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-07-06 10:33:59 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Develop an Arduino project using the Ultrasonic */ /* library to measure distance with the HC-SR04 */ /* sensor. The Echo pin is connected to D3 and the */ /* Trigger pin to D2. Implement functions to read */ /* sensor data and update output variables. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
//https://github.com/ErickSimoes/Ultrasonic /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void updateOutputs(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t HC_SR04_Echo_PIN_D3 = 3; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t HC_SR04_Trigger_PIN_D2 = 2; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool HC_SR04_Trigger_PIN_D2_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float HC_SR04_Trigger_PIN_D2_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ Ultrasonic ultrasonic(HC_SR04_Trigger_PIN_D2, HC_SR04_Echo_PIN_D3); // Initialize Ultrasonic object void setup(void) { // put your setup code here, to run once: Serial.begin(9600); // Initialize serial communication pinMode(HC_SR04_Echo_PIN_D3, INPUT); pinMode(HC_SR04_Trigger_PIN_D2, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: updateOutputs(); // Refresh output data delay(1000); // Delay to avoid flooding the serial monitor } void updateOutputs() { HC_SR04_Trigger_PIN_D2_phyData = ultrasonic.read(); // Read distance from ultrasonic sensor Serial.print("Distance in CM: "); Serial.println(HC_SR04_Trigger_PIN_D2_phyData); // Print distance to serial monitor }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)