Advertisement
Guest User

xd

a guest
May 20th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1.  
  2. /*Arduino parking lot(version 2)
  3. YouTube/Tech Build
  4. Code used in the production of the Youtube material.
  5. */
  6.  
  7. #include <Servo.h>
  8. #include<LiquidCrystal.h>
  9. LiquidCrystal lcd(12,11,5,4,3,2);//connected to RS,EN,D4,D5,D6,D7 of LCD display respectively
  10. Servo myservo; // create servo object to control a servo
  11.  
  12. #define ServoM 7 //Connected to the servo motor.
  13. #define Exit 9 //Pin connected to the EXIT sensor.
  14. #define In 8 //Pin connected to the IN sensor.
  15. #define Pwr 6 //Extra power pin for sensors(Don't connect servo's power to this!)
  16. #define Gnd 10 //Extra groung pin for sensors(Don't connect servo's power to this!)
  17. #define BarLow 90 //Low position of the barrier.
  18. #define BarUp 177 //Up position of the barrier.
  19. #define CAPACITY 7 //Capacity of the parking lot.
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. void setup(){
  27. myservo.attach(ServoM); // attaches the servo.
  28. lcd.begin(16,2);
  29. lcd.print("Space left for");
  30. pinMode(Gnd, OUTPUT);
  31. pinMode(Pwr, OUTPUT);
  32. pinMode(Exit, INPUT); // set "EXIT" sensor pin to input
  33. pinMode(In, INPUT); // set "IN" sensor pin to input
  34. digitalWrite(Gnd, LOW);
  35. digitalWrite(Pwr, HIGH);
  36. myservo.write(BarLow); //Barrier in the low position
  37. // delay(1000);
  38. }
  39.  
  40. int Available= 7 ; // Number of places available.
  41.  
  42. //================================================================
  43. void loop(){
  44. if (Available == 1){ //If only one place is available.
  45. lcd.clear(); //Clear the LCD screen.
  46. lcd.setCursor(1,0);
  47. lcd.print("Wolne miejsca:");//Display the text"Space left for.
  48. lcd.setCursor(0,1);
  49. lcd.print(Available); //Display the no. of spaces left for cars.
  50. lcd.print(" aut");
  51. }else{
  52. if (Available >= 1){
  53. lcd.clear();
  54. lcd.setCursor(1,0);
  55. lcd.print("Wolne miejsca:");
  56. lcd.setCursor(0,1);
  57. lcd.print(Available);
  58. lcd.print(" aut ");
  59. }else{
  60. lcd.clear();
  61. lcd.setCursor(1,0);
  62. lcd.print("Sorry!");
  63. lcd.setCursor(0,1);
  64. lcd.print("Brak Miejsc!");
  65. }
  66. }
  67.  
  68.  
  69. if(digitalRead(In)==1) //If the IN sensor detects a car at the entrance.
  70. {
  71. if(Available != 0){ //Checking if there is place in parking lot('!=' means 'not equal to').
  72. Available--; //Deduct a place from the lot in the memory.
  73. myservo.write(BarUp); //Lift the barrier up.
  74. delay(3000); //Wait for 3 seconds to let the car pass.
  75. myservo.write(BarLow);//Lower the barrier.
  76. }
  77. }
  78. if(digitalRead(Exit)==1) //If the EXIT sensor detects a car the exit.=
  79. {
  80. if(Available != CAPACITY){
  81. Available++;
  82. myservo.write(BarUp);
  83. delay(3000);
  84. myservo.write(BarLow);
  85. }
  86. }
  87. delay(20);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement