Advertisement
pleasedontcode

MySampleProject rev_02

Oct 22nd, 2023
126
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: MySampleProject
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-10-23 01:56:35
  15.     - Source Code generated by: Jhon
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20.  
  21. /****** SYSTEM REQUIREMENT 1 *****/
  22. /* Turn On and off LED using Relay Module */
  23.  
  24. /****** FUNCTION PROTOTYPES *****/
  25. void setup(void);
  26. void loop(void);
  27. void turnOnLED(void);
  28. void turnOffLED(void);
  29.  
  30. /***** DEFINITION OF ANALOG INPUT PINS *****/
  31. const uint8_t Led_PIN_A0 = A0;
  32. const uint8_t Relay_PIN = 2;
  33.  
  34. void setup(void)
  35. {
  36.   // put your setup code here, to run once:
  37.   pinMode(Led_PIN_A0, INPUT);
  38.   pinMode(Relay_PIN, OUTPUT);
  39. }
  40.  
  41. void loop(void)
  42. {
  43.   // put your main code here, to run repeatedly:
  44.   int sensorValue = analogRead(Led_PIN_A0);
  45.  
  46.   if (sensorValue > 500) {
  47.     turnOnLED();
  48.   } else {
  49.     turnOffLED();
  50.   }
  51. }
  52.  
  53. void turnOnLED(void)
  54. {
  55.   digitalWrite(Relay_PIN, HIGH);
  56. }
  57.  
  58. void turnOffLED(void)
  59. {
  60.   digitalWrite(Relay_PIN, LOW);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement