hwthinker

DemoSimpleIO

Oct 16th, 2021 (edited)
216
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Cara koneksi ESP32R4 - USB TTL
  3.  * Pastikan         RXD - RXD
  4.  *                  TXD - TXD
  5.  *                  GND - GND
  6.  *            ESP32_PIN  - No Connection ( ikut 3.3V dari Alat). Alat dari Power supply
  7.  *            ESP32_PIN  - 3.3V - Cabut Penguhubung 3.3V ke ESP32_PIN. Power Supply mati
  8.  */                
  9.  
  10.  /* Cara Download
  11.   *  1. Klik Tombol Download di Arduino IDE
  12.   *  2. Bersamaan Itu Tekan dan Tahan tombol Rst dan Prog di alat
  13.   *  3. Lepas Tombol Reset dan tetap tekan tombol prog sampai Proses Download dimulai
  14.   *  4. Setelah Proses download dimulai lepas tombol Prog
  15.   *  5. Klik RST agar ESP32 berubah dalam mode Programming ke Mode running,
  16.   *  6. PENTING : Pastikan Ikuti Langkah 5, jika tidak Program yang diupload tidak akan dijalankan
  17.   */
  18.  
  19. #define RLY1  25
  20. #define RLY2  26
  21. #define RLY3  32
  22. #define RLY4  33
  23. #define BTN1 34
  24. #define BTN2 35
  25. #define BTN3 36
  26. #define BTN4 39
  27. void setup() {
  28.   pinMode(RLY1, OUTPUT);
  29.   pinMode(RLY2, OUTPUT);
  30.   pinMode(RLY3, OUTPUT);
  31.   pinMode(RLY4, OUTPUT);
  32.   pinMode(BTN1, INPUT_PULLUP);
  33.   pinMode(BTN2, INPUT_PULLUP);
  34.   pinMode(BTN3, INPUT_PULLUP);
  35.   pinMode(BTN4, INPUT_PULLUP);
  36.   Serial.begin(9600);
  37. }
  38.  
  39. void loop() {
  40.   if (digitalRead(BTN1) == LOW) {
  41.     digitalWrite(RLY1, HIGH);   // turn the RLY1 on (HIGH is the voltage level)
  42.     Serial.println("RLY1 ON");
  43.   } else {
  44.     digitalWrite(RLY1, LOW);    // turn the RLY1 off by making the voltage LOW
  45.     Serial.println("RLY1 OFF");
  46.   }
  47.  
  48.   if (digitalRead(BTN2) == LOW) {
  49.     digitalWrite(RLY2, HIGH);   // turn the RLY1 on (HIGH is the voltage level)
  50.     Serial.println("RLY2 ON");
  51.   } else {
  52.     digitalWrite(RLY2, LOW);    // turn the RLY1 off by making the voltage LOW
  53.     Serial.println("RLY2 OFF");
  54.   }
  55.  
  56.   if (digitalRead(BTN3) == LOW) {
  57.     digitalWrite(RLY3, HIGH);   // turn the RLY1 on (HIGH is the voltage level)
  58.     Serial.println("RLY3 ON");
  59.   } else {
  60.     digitalWrite(RLY3, LOW);    // turn the RLY1 off by making the voltage LOW
  61.     Serial.println("RLY3 OFF");
  62.   }
  63.  
  64.   if (digitalRead(BTN4) == LOW) {
  65.     digitalWrite(RLY4, HIGH);   // turn the RLY1 on (HIGH is the voltage level)
  66.     Serial.println("RLY4 ON");
  67.   } else {
  68.     digitalWrite(RLY4, LOW);    // turn the RLY1 off by making the voltage LOW
  69.     Serial.println("RLY4 OFF");
  70.   }
  71.  
  72.   delay(50);                       // wait for a second
  73.  
  74. }
RAW Paste Data