yusath

Sensor Lampu Jalan

Jul 4th, 2020
36
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial sim(2, 3);
  3. int led = 8;
  4. int sensorA1 = 13; //untuk membaca lampu A1
  5. int sensorA2 = 12; //untuk membaca lampu A2
  6. int sensorB1 = 11; //untuk membaca lampu B1
  7. int sensorB2 = 10; //untuk membaca lampu B2
  8.  
  9. void setup (){
  10.  
  11. Serial.begin(9600); // Inisialisasi Port serial
  12. sim.begin(115200); // Inisialisasi Port Sim
  13. pinMode(led, OUTPUT); // LED sebagai output
  14. pinMode(sensorA1, INPUT); //sensor ldr 1 input
  15. pinMode(sensorA2, INPUT); //sensor ldr 2 input
  16. pinMode(sensorB1, INPUT);
  17. pinMode(sensorB2, INPUT);
  18.  
  19. }
  20.  
  21. void loop(){
  22.  
  23. delay(2000);
  24.  
  25. int ldrA1 = digitalRead(sensorA1); //baca sensor A1
  26. int ldrA2 = digitalRead(sensorA2); // baca sensor A2
  27. int ldrB1 = digitalRead(sensorB1); // baca sensor B1
  28. int ldrB2 = digitalRead(sensorB2); // baca sensor B2
  29.  
  30. Serial.print("Lampu A1 = ");
  31. Serial.println(ldrA1);
  32. delay(500);
  33.  
  34. Serial.print("Lampu A2 = ");
  35. Serial.println(ldrA2);
  36. delay(500);
  37.  
  38. Serial.print("Lampu B1 = ");
  39. Serial.println(ldrB1);
  40. delay(500);
  41.  
  42. Serial.print("Lampu B2 = ");
  43. Serial.println(ldrB2);
  44. delay(500);
  45.  
  46. if (ldrA1 > 0)
  47. {
  48. digitalWrite(led, HIGH);
  49. delay(100);
  50. digitalWrite(led, LOW);
  51. delay(100);
  52. digitalWrite(led, HIGH);
  53. delay(100);
  54. digitalWrite(led, LOW);
  55. delay(100);
  56. }
  57. if (ldrA2 > 0)
  58. {
  59. digitalWrite(led, HIGH);
  60. delay(100);
  61. digitalWrite(led, LOW);
  62. delay(100);
  63. digitalWrite(led, HIGH);
  64. delay(100);
  65. digitalWrite(led, LOW);
  66. delay(100);
  67. }
  68. if (ldrB1 > 0)
  69. {
  70. digitalWrite(led, HIGH);
  71. delay(100);
  72. digitalWrite(led, LOW);
  73. delay(100);
  74. digitalWrite(led, HIGH);
  75. delay(100);
  76. digitalWrite(led, LOW);
  77. delay(100);
  78. }
  79. if (ldrB2 > 0)
  80. {
  81. digitalWrite(led, HIGH);
  82. delay(100);
  83. digitalWrite(led, LOW);
  84. delay(100);
  85. digitalWrite(led, HIGH);
  86. delay(100);
  87. digitalWrite(led, LOW);
  88. delay(100);
  89. }
  90. else
  91. {
  92. digitalWrite(led, LOW);
  93. }
  94.  
  95. }
RAW Paste Data