safwan092

project-19-steps-us1-us2

Apr 11th, 2021
655
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int t1 = 500;
  2. int t2 = 100;
  3.  
  4. #define r1    2
  5. #define r2    3
  6. #define r3    4
  7. #define r4    5
  8. #define r5    6
  9. #define r6    7
  10. #define r7    8
  11. #define r8    9
  12. #define r9    31
  13. #define r10   33
  14. #define r11   35
  15. #define r12   37
  16. #define r13   39
  17. #define r14   41
  18. #define r15   43
  19. #define r16   45
  20. #define r17   30
  21. #define r18   32
  22. #define r19   34
  23.  
  24. #define trigPin1 22
  25. #define echoPin1 24
  26.  
  27. #define trigPin2 26
  28. #define echoPin2 28
  29.  
  30. long duration1;
  31. int distance1;
  32.  
  33. long duration2;
  34. int distance2;
  35.  
  36. void setup() {
  37.   // put your setup code here, to run once:
  38.   initSensors();
  39.   initRelay();
  40.   allOFF();
  41. }
  42.  
  43. void loop() {
  44.   //allON();
  45.   //allOFF();
  46.   //lowToHigh();
  47.   //highToLow();
  48.   //lowToHighON();
  49.   //highToLowON();
  50.   //delay(1000);
  51.   us1();
  52.   us2();
  53.   if (distance1 < 150) {
  54.     lowToHigh();
  55.     delay(10000);
  56.   }
  57.   else if (distance2 < 150) {
  58.     highToLow();
  59.     delay(10000);
  60.   }
  61.   else {
  62.     allOFF();
  63.   }
  64.   delay(100);
  65. }//end of LOOP.
  66.  
  67.  
  68. void initSensors() {
  69.   pinMode(trigPin1, OUTPUT);
  70.   pinMode(echoPin1, INPUT);
  71.   pinMode(trigPin2, OUTPUT);
  72.   pinMode(echoPin2, INPUT);
  73. }
  74.  
  75. void us1() {
  76.   digitalWrite(trigPin1, LOW);
  77.   delayMicroseconds(5);
  78.   digitalWrite(trigPin1, HIGH);
  79.   delayMicroseconds(10);
  80.   digitalWrite(trigPin1, LOW);
  81.   duration1 = pulseIn(echoPin1, HIGH);
  82.   distance1 = duration1 * 0.034 / 2;
  83.   Serial.print("Distance = ");
  84.   Serial.print(distance1);
  85.   Serial.println(" cm");
  86.   delay(100);
  87. }
  88. void us2() {
  89.   digitalWrite(trigPin2, LOW);
  90.   delayMicroseconds(5);
  91.   digitalWrite(trigPin2, HIGH);
  92.   delayMicroseconds(10);
  93.   digitalWrite(trigPin2, LOW);
  94.   duration2 = pulseIn(echoPin2, HIGH);
  95.   distance2 = duration2 * 0.034 / 2;
  96.   Serial.print("Distance = ");
  97.   Serial.print(distance2);
  98.   Serial.println(" cm");
  99.   delay(100);
  100. }
  101.  
  102. void allOFF() {
  103.   digitalWrite(r1, HIGH);
  104.   digitalWrite(r2, HIGH);
  105.   digitalWrite(r3, HIGH);
  106.   digitalWrite(r4, HIGH);
  107.   digitalWrite(r5, HIGH);
  108.   digitalWrite(r6, HIGH);
  109.   digitalWrite(r7, HIGH);
  110.   digitalWrite(r8, HIGH);
  111.   digitalWrite(r9, HIGH);
  112.   digitalWrite(r10, HIGH);
  113.   digitalWrite(r11, HIGH);
  114.   digitalWrite(r12, HIGH);
  115.   digitalWrite(r13, HIGH);
  116.   digitalWrite(r14, HIGH);
  117.   digitalWrite(r15, HIGH);
  118.   digitalWrite(r16, HIGH);
  119.   digitalWrite(r17, HIGH);
  120.   digitalWrite(r18, HIGH);
  121.   digitalWrite(r19, HIGH);
  122. }
  123.  
  124. void allON() {
  125.   digitalWrite(r1, LOW);
  126.   digitalWrite(r2, LOW);
  127.   digitalWrite(r3, LOW);
  128.   digitalWrite(r4, LOW);
  129.   digitalWrite(r5, LOW);
  130.   digitalWrite(r6, LOW);
  131.   digitalWrite(r7, LOW);
  132.   digitalWrite(r8, LOW);
  133.   digitalWrite(r9, LOW);
  134.   digitalWrite(r10, LOW);
  135.   digitalWrite(r11, LOW);
  136.   digitalWrite(r12, LOW);
  137.   digitalWrite(r13, LOW);
  138.   digitalWrite(r14, LOW);
  139.   digitalWrite(r15, LOW);
  140.   digitalWrite(r16, LOW);
  141.   digitalWrite(r17, LOW);
  142.   digitalWrite(r18, LOW);
  143.   digitalWrite(r19, LOW);
  144. }
  145.  
  146. void initRelay() {
  147.   pinMode(r1, OUTPUT);
  148.   pinMode(r2, OUTPUT);
  149.   pinMode(r3, OUTPUT);
  150.   pinMode(r4, OUTPUT);
  151.   pinMode(r5, OUTPUT);
  152.   pinMode(r6, OUTPUT);
  153.   pinMode(r7, OUTPUT);
  154.   pinMode(r8, OUTPUT);
  155.   pinMode(r9, OUTPUT);
  156.   pinMode(r10, OUTPUT);
  157.   pinMode(r11, OUTPUT);
  158.   pinMode(r12, OUTPUT);
  159.   pinMode(r13, OUTPUT);
  160.   pinMode(r14, OUTPUT);
  161.   pinMode(r15, OUTPUT);
  162.   pinMode(r16, OUTPUT);
  163.   pinMode(r17, OUTPUT);
  164.   pinMode(r18, OUTPUT);
  165.   pinMode(r19, OUTPUT);
  166. }
  167.  
  168. void lowToHigh() {//trun off 1 to 19
  169.   allON();
  170.   digitalWrite(r1, HIGH);
  171.   delay(t1);
  172.   digitalWrite(r2, HIGH);
  173.   delay(t1);
  174.   digitalWrite(r3, HIGH);
  175.   delay(t1);
  176.   digitalWrite(r4, HIGH);
  177.   delay(t1);
  178.   digitalWrite(r5, HIGH);
  179.   delay(t1);
  180.   digitalWrite(r6, HIGH);
  181.   delay(t1);
  182.   digitalWrite(r7, HIGH);
  183.   delay(t1);
  184.   digitalWrite(r8, HIGH);
  185.   delay(t1);
  186.   digitalWrite(r9, HIGH);
  187.   delay(t1);
  188.   digitalWrite(r10, HIGH);
  189.   delay(t1);
  190.   digitalWrite(r11, HIGH);
  191.   delay(t1);
  192.   digitalWrite(r12, HIGH);
  193.   delay(t1);
  194.   digitalWrite(r13, HIGH);
  195.   delay(t1);
  196.   digitalWrite(r14, HIGH);
  197.   delay(t1);
  198.   digitalWrite(r15, HIGH);
  199.   delay(t1);
  200.   digitalWrite(r16, HIGH);
  201.   delay(t1);
  202.   digitalWrite(r17, HIGH);
  203.   delay(t1);
  204.   digitalWrite(r18, HIGH);
  205.   delay(t1);
  206.   digitalWrite(r19, HIGH);
  207.   delay(t1);
  208. }
  209.  
  210. void lowToHighON() {//trun on 1 to 19
  211.   allOFF();
  212.   digitalWrite(r1, 0);
  213.   delay(t1);
  214.   digitalWrite(r2, 0);
  215.   delay(t1);
  216.   digitalWrite(r3, 0);
  217.   delay(t1);
  218.   digitalWrite(r4, 0);
  219.   delay(t1);
  220.   digitalWrite(r5, 0);
  221.   delay(t1);
  222.   digitalWrite(r6, 0);
  223.   delay(t1);
  224.   digitalWrite(r7, 0);
  225.   delay(t1);
  226.   digitalWrite(r8, 0);
  227.   delay(t1);
  228.   digitalWrite(r9, 0);
  229.   delay(t1);
  230.   digitalWrite(r10, 0);
  231.   delay(t1);
  232.   digitalWrite(r11, 0);
  233.   delay(t1);
  234.   digitalWrite(r12, 0);
  235.   delay(t1);
  236.   digitalWrite(r13, 0);
  237.   delay(t1);
  238.   digitalWrite(r14, 0);
  239.   delay(t1);
  240.   digitalWrite(r15, 0);
  241.   delay(t1);
  242.   digitalWrite(r16, 0);
  243.   delay(t1);
  244.   digitalWrite(r17, 0);
  245.   delay(t1);
  246.   digitalWrite(r18, 0);
  247.   delay(t1);
  248.   digitalWrite(r19, 0);
  249.   delay(t1);
  250. }
  251.  
  252. void highToLow() {//trun off 19 to 1
  253.   allON();
  254.   digitalWrite(r19, HIGH);
  255.   delay(t2);
  256.   digitalWrite(r18, HIGH);
  257.   delay(t2);
  258.   digitalWrite(r17, HIGH);
  259.   delay(t2);
  260.   digitalWrite(r16, HIGH);
  261.   delay(t2);
  262.   digitalWrite(r15, HIGH);
  263.   delay(t2);
  264.   digitalWrite(r14, HIGH);
  265.   delay(t2);
  266.   digitalWrite(r13, HIGH);
  267.   delay(t2);
  268.   digitalWrite(r12, HIGH);
  269.   delay(t2);
  270.   digitalWrite(r11, HIGH);
  271.   delay(t2);
  272.   digitalWrite(r10, HIGH);
  273.   delay(t2);
  274.   digitalWrite(r9, HIGH);
  275.   delay(t2);
  276.   digitalWrite(r8, HIGH);
  277.   delay(t2);
  278.   digitalWrite(r7, HIGH);
  279.   delay(t2);
  280.   digitalWrite(r6, HIGH);
  281.   delay(t2);
  282.   digitalWrite(r5, HIGH);
  283.   delay(t2);
  284.   digitalWrite(r4, HIGH);
  285.   delay(t2);
  286.   digitalWrite(r3, HIGH);
  287.   delay(t2);
  288.   digitalWrite(r2, HIGH);
  289.   delay(t2);
  290.   digitalWrite(r1, HIGH);
  291.   delay(t2);
  292. }
  293.  
  294. void highToLowON() {//trun on 19 to 1
  295.   allOFF();
  296.   digitalWrite(r19, 0);
  297.   delay(t2);
  298.   digitalWrite(r18, 0);
  299.   delay(t2);
  300.   digitalWrite(r17, 0);
  301.   delay(t2);
  302.   digitalWrite(r16, 0);
  303.   delay(t2);
  304.   digitalWrite(r15, 0);
  305.   delay(t2);
  306.   digitalWrite(r14, 0);
  307.   delay(t2);
  308.   digitalWrite(r13, 0);
  309.   delay(t2);
  310.   digitalWrite(r12, 0);
  311.   delay(t2);
  312.   digitalWrite(r11, 0);
  313.   delay(t2);
  314.   digitalWrite(r10, 0);
  315.   delay(t2);
  316.   digitalWrite(r9, 0);
  317.   delay(t2);
  318.   digitalWrite(r8, 0);
  319.   delay(t2);
  320.   digitalWrite(r7, 0);
  321.   delay(t2);
  322.   digitalWrite(r6, 0);
  323.   delay(t2);
  324.   digitalWrite(r5, 0);
  325.   delay(t2);
  326.   digitalWrite(r4, 0);
  327.   delay(t2);
  328.   digitalWrite(r3, 0);
  329.   delay(t2);
  330.   digitalWrite(r2, 0);
  331.   delay(t2);
  332.   digitalWrite(r1, 0);
  333.   delay(t2);
  334. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×