CCCPaste

Ultrsonicsens1 rev_01

/********* 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: Ultrsonicsens1
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-12-03 13:21:40
	- Source Code generated by: Raghu

********* Pleasedontcode.com **********/
/****** DEFINITION OF LIBRARIES *****/
#include 

/****** SYSTEM REQUIREMENT 1 *****/
	/* Turn on the buzzer when ultrasonic pulse is close to 30 */

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Ultrasonic_PIN_D2 = 2;

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t Buzzer_PIN_D3 = 3;
const uint8_t Relay_PIN_D4 = 4;

void setup(void)
{
	// put your setup code here, to run once:
	pinMode(Ultrasonic_PIN_D2, INPUT);
	pinMode(Buzzer_PIN_D3, OUTPUT);
	pinMode(Relay_PIN_D4, OUTPUT);
}

void loop(void)
{
	// put your main code here, to run repeatedly:
	
	// Read the ultrasonic sensor value
	int ultrasonicValue = digitalRead(Ultrasonic_PIN_D2);
	
	// Check if the ultrasonic value is close to 30
	if (ultrasonicValue == HIGH)
	{
		// Turn on the buzzer and relay
		digitalWrite(Buzzer_PIN_D3, HIGH);
		digitalWrite(Relay_PIN_D4, HIGH);
	}
	else
	{
		// Turn off the buzzer and relay
		digitalWrite(Buzzer_PIN_D3, LOW);
		digitalWrite(Relay_PIN_D4, LOW);
	}
}