Advertisement
pleasedontcode

Ultrsonicsens1 rev_01

Dec 3rd, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Ultrsonicsens1
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-03 13:21:40
  15.     - Source Code generated by: Raghu
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20.  
  21. /****** SYSTEM REQUIREMENT 1 *****/
  22.     /* Turn on the buzzer when ultrasonic pulse is close to 30 */
  23.  
  24. /****** FUNCTION PROTOTYPES *****/
  25. void setup(void);
  26. void loop(void);
  27.  
  28. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  29. const uint8_t Ultrasonic_PIN_D2 = 2;
  30.  
  31. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  32. const uint8_t Buzzer_PIN_D3 = 3;
  33. const uint8_t Relay_PIN_D4 = 4;
  34.  
  35. void setup(void)
  36. {
  37.     // put your setup code here, to run once:
  38.     pinMode(Ultrasonic_PIN_D2, INPUT);
  39.     pinMode(Buzzer_PIN_D3, OUTPUT);
  40.     pinMode(Relay_PIN_D4, OUTPUT);
  41. }
  42.  
  43. void loop(void)
  44. {
  45.     // put your main code here, to run repeatedly:
  46.    
  47.     // Read the ultrasonic sensor value
  48.     int ultrasonicValue = digitalRead(Ultrasonic_PIN_D2);
  49.    
  50.     // Check if the ultrasonic value is close to 30
  51.     if (ultrasonicValue == HIGH)
  52.     {
  53.         // Turn on the buzzer and relay
  54.         digitalWrite(Buzzer_PIN_D3, HIGH);
  55.         digitalWrite(Relay_PIN_D4, HIGH);
  56.     }
  57.     else
  58.     {
  59.         // Turn off the buzzer and relay
  60.         digitalWrite(Buzzer_PIN_D3, LOW);
  61.         digitalWrite(Relay_PIN_D4, LOW);
  62.     }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement