Home > Driving Displays, Driving Motors, Uncategorized > Arduino Parking Lot ( Filled )

Arduino Parking Lot ( Filled )

Wiring diagram:

Here is the code:

/*ParkingL02.pde
Arduining.com 08 JUL 2012
Code used in the production of the Youtube material.
*/

#include <Servo.h>
Servo myservo;  // create servo object to control a servo

#define ServoM    12        //Connected to the servo motor.
#define Bright    11        //servo library disable PWM on pins 9 and 10.
#define Exit      9         //Pin connected to the EXIT button.
#define In        8         //Pin connected to the IN button.

#define BarLow    177       //Low position of the barrier.
#define BarUp     95        //Up position of the barrier.
#define CAPACITY  8         //Capacity of the parking lot.
#define INTEN     80        //Display intensity %

//Pins conections to segments (cathodes).
#define  segA  0
#define  segB  1
#define  segC  2
#define  segD  3
#define  segE  4
#define  segF  5
#define  segG  6

//Array with the segments to represent the decimal numbers (0-9).
byte segments[10] = {
// pgfedcba  <--- segments
  B00111111, // number 0
  B00000110, // number 1
  B01011011, // number 2
  B01001111, // number 3
  B01100110, // number 4
  B01101101, // number 5
  B01111101, // number 6
  B00000111, // number 7
  B01111111, // number 8
  B01101111  // number 9
};

void setup(){
  myservo.attach(ServoM);          // attaches the servo.

  pinMode(Exit, INPUT);           // set "EXIT" button pin to input
  pinMode(In, INPUT);             // set "IN" button pin to input
  digitalWrite(Exit, HIGH);       // Connect Pull-Up resistor.
  digitalWrite(In, HIGH);         // Connect Pull-Up resistor.
  pinMode(segA,OUTPUT);
  pinMode(segB,OUTPUT);
  pinMode(segC,OUTPUT);
  pinMode(segD,OUTPUT);
  pinMode(segE,OUTPUT);
  pinMode(segF,OUTPUT);
  pinMode(segG,OUTPUT);
  pinMode(Bright,OUTPUT);
  analogWrite(Bright,255*INTEN/100);
  myservo.write(BarLow);          //Barrier in the low position
//  delay(1000);
}

int  Available= 9;                    // Number of places available.

//================================================================
void loop(){
Display(Available);
if(digitalRead(In)==0)
{
  if(Available != 0){
    Available--;
    myservo.write(BarUp);
    delay(3000);
    myservo.write(BarLow);
    }
  }
if(digitalRead(Exit)==0)
{
  if(Available != CAPACITY){
    Available++;
    myservo.write(BarUp);
    delay(3000);
    myservo.write(BarLow);
    }
  }
}

/*-------------------------------------------------------------------
Put the segments according to the number.
--------------------------------------------------------------------*/
void Display(int number){
byte segs =  ~segments[number];        //"~" is used for commom anode.

digitalWrite(segA, bitRead(segs, 0) );
digitalWrite(segB, bitRead(segs, 1) );
digitalWrite(segC, bitRead(segs, 2) );
digitalWrite(segD, bitRead(segs, 3) );
digitalWrite(segE, bitRead(segs, 4) );
digitalWrite(segF, bitRead(segs, 5) );
digitalWrite(segG, bitRead(segs, 6) );
}

See it in Youtube:

and how was done:

About these ads
  1. Kim
    October 16, 2012 at 3:10 PM | #1

    Nice! Why not use cap sense Library and use a small metallic plate at the entrance?
    Cheers Kim

    • October 16, 2012 at 9:35 PM | #2

      Thanks, I’ll do some experiments using your idea.

  2. ghit86
    October 16, 2012 at 5:10 PM | #3

    Goo job!

  3. Line96
    November 22, 2012 at 11:41 PM | #4

    nice project. wanna ask, what material used to build the switch pad?

    • December 12, 2012 at 11:10 AM | #5

      Aluminium foil, you can find it at the supermarket. Check the second video.

  4. December 19, 2012 at 6:26 PM | #6

    Awesome project.

    Where did you get the servo rotor?

    • December 22, 2012 at 10:27 AM | #7

      Amazon, Sparkfun, Robotshop, dealextreme, adafruit, Plolu, eBay,
      I have used all of them sucessfully…

  5. Maze1
    March 29, 2013 at 8:35 PM | #8

    Nice Job!!! What kind of sensor did you use and how was it connected?

  6. March 31, 2013 at 7:25 AM | #9

    hello can you email me the full program for your project im doing a similar project and I need some help

  7. April 16, 2013 at 1:26 PM | #10

    Would it be possible to use two touch sensor for the entrance and exit?

  8. Márcia VR
    June 9, 2013 at 3:10 PM | #11

    Gostei do seu projeto, mas fiquei com algumas duvidas… o material que vocẽ usou para colocar no piso do estacionamento é papel cartão?
    Estou iniciando meeessssmmmmoooo na área da robótica e preciso saber o nome dos pinos que você usou para plugar no clips…
    Obrigada!!!!

    • June 9, 2013 at 4:14 PM | #12

      Não falo muito portugués.
      -Yes is cardboard.
      -Look for “minigrabbers” in google images…
      Obrigado Márcia por visitar meu blog.

  9. Mc
    September 12, 2013 at 12:37 AM | #13

    I don’t understand these lines…

    B00111111, // number 0
    B00000110, // number 1
    B01011011, // number 2
    B01001111, // number 3
    B01100110, // number 4
    B01101101, // number 5
    B01111101, // number 6
    B00000111, // number 7
    B01111111, // number 8
    B01101111 // number 9

    How to identify those “B00111111″???

    and this one” analogWrite(Bright,255*INTEN/100);”

    I hope you can somehow explain some lines on the code… I’m a newbie.

  10. September 12, 2013 at 2:58 PM | #14

    An array of 10 bytes was declared and the name of the array is segments.
    byte segments[10] = { ….
    Then the array is filled with bytes in binary format (8 bits).
    The bit values correspond to the state of the segments a,b,c,d,e,f and g of the display to represent numbers from 0 to 9. Note that bit 7 is always 0 because the decimal point (p) is not used in this application.
    To change the intensity of the display, a PWM signal is used in the common of the display.
    analogWrite(Bright,255*INTEN/100);
    “Bright” is the pin of the display where all the leds are connected (the common).
    when I said:
    #define Bright 11
    at the beginning of the code, it means that every time you see the word “Bright” in the code,
    it will be replacer by “11″ before the code compilation.
    Also:
    #define INTEN 80
    is used to change the display intensity.
    With this in mind:
    analogWrite(Bright,255*INTEN/100);
    is the same as:
    analogWrite(11,204);
    The expression 255*INTEN/100 was used to specify INTEN as percentage.

    Hope it helps…

  11. October 28, 2013 at 4:15 PM | #15

    hi there, could you do an example using a wireless RF remote

  12. October 28, 2013 at 4:16 PM | #16

    love this project…so cool

  13. December 2, 2013 at 1:31 AM | #17

    sir can we use a 16 segment led display in this project?

    • December 2, 2013 at 3:50 PM | #18

      I see no problem with it. You’ll need the analog pins as digital outputs to drive all the segments.

      • December 3, 2013 at 8:12 PM | #19

        how are we going to use that sir? sir can you give us the code that decreases the number of vehicle in the display everytime they exit?thank you sir more power

  14. December 9, 2013 at 6:29 AM | #20

    sir can you please give us the materials and circuit diagram that you use in that project?thank you very much sir

  15. Denden
    January 15, 2014 at 1:42 AM | #21

    hello, i have a problem with this part

    void loop(){
    Display(Available);
    if(digitalRead(In)==0)

    it says ‘Display’ was not declared in this scope. what should i do?
    i just started using arduino TIA

  16. nex
    February 4, 2014 at 5:11 AM | #22

    Sir, i want to know the type of servo?

  1. October 15, 2012 at 1:45 AM | #1
  2. October 15, 2012 at 2:34 PM | #2
  3. October 15, 2012 at 3:14 PM | #3
  4. October 16, 2012 at 12:35 AM | #4
  5. October 17, 2012 at 1:08 AM | #5
  6. January 20, 2013 at 7:08 AM | #6

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: