/********* 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: Human Detection - Source Code compiled for: Arduino Uno - Source Code created on: 2024-04-01 21:42:32 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* activates a relay when the presence of a human is */ /* detected */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include // Include the Ultrasonic library #include // Include the Wire library for relay control /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* activates a relay when the presence of a human is */ /* detected */ /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void activateRelay(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t ultrasonicEchoPin = 3; // Define the Echo pin /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t ultrasonicTriggerPin = 2; // Define the Trigger pin const uint8_t relayPin = 4; // Define the relay pin /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool ultrasonicTriggerPinRawData = 0; // Define variable to store raw data /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float ultrasonicTriggerPinPhyData = 0.0; // Define variable to store transformed data /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ Ultrasonic ultrasonic(ultrasonicTriggerPin, ultrasonicEchoPin); // Create an Ultrasonic object void setup(void) { // put your setup code here, to run once: pinMode(ultrasonicEchoPin, INPUT); // Set Echo pin as input pinMode(ultrasonicTriggerPin, OUTPUT); // Set Trigger pin as output pinMode(relayPin, OUTPUT); // Set relay pin as output Serial.begin(9600); // Start the serial communication } void loop(void) { // put your main code here, to run repeatedly: int distance = ultrasonic.read(); // Read the distance in centimeters Serial.print("Distance in CM: "); Serial.println(distance); if (distance < 50) // Check if the distance is less than 50cm { activateRelay(); // Call the function to activate the relay } else { digitalWrite(relayPin, LOW); // Turn off the relay } delay(1000); // Wait for 1 second } void activateRelay(void) { digitalWrite(relayPin, HIGH); // Turn on the relay }