How to display on my number of free parking on 4 digit 7segment using IR obstacl

Hello,
i have 10 IR Obstacle sensor to sense car in each of my parking slot. My prototype can hold 10 cars only. I want to display them on a 4 digit 7 segment the number of free parking. I’m not being able to program the counter when no car in parking slot the count of free parking should increase . Can someone help me?

find my code below

Sketch_1.ino (10.4 KB)

Can someone help me?

I polished up my crystal ball to look at your code. All I got was last year's Superbowl running in reverse. Not much help, I'm afraid.

Of course, start by posting your code and all details. Pro tip, read How to use the forum before you respond :wink:

What happened to my pro tip?! :o

  delay(0);

My crystal ball just barfed. I'm sending you the bill to get it cleaned.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What 4digit 7seg display are you using?

Thanks.. Tom.. :slight_smile:

Hi.
What model Arduino are you using?

Looking at your code you are trying to multiplex your digit display with code.
You will have major flicker problems due to your code having to do other things while trying to control your segments.

Have you written this code in stages?

Does your car detection system work?
Do you have code written just prove the detection works?

Do you have code just to make your display count?

If you haven't, then stop and develop your code in stages, get each stage working before going to the next.
When you have each feature of your code working separately then combine them, one at a time, getting the combination to work before adding the next.

I know this sounds laborious but it means you will be making code that YOU understand and that has fewer bugs and faults.

Tom.... :slight_smile:

TomGeorge:
Do you have code just to make your display count?

Too bad he has 10 parking spots. If instead he had only 9, then he would not need to multiplex anything.

Hello ,

I’m having problems to write a program for my Parking prototype to show the number of free parking available;

  1. There are 10 IR Obstacle sensors, 10 RG LEDs and a 4 digit 7 segment display

2.The sensors are positions at each parking slot (10 parking) see in picture attached

3.As a car enters the slot the LEDs turn from GREEN to RED indicating parking slot is not available. As a car leave the slot the LED turn from RED to GREEN indicating it is available.

  1. Using : Arduino MEGA : sensor : IR Obstacle sensor FC-51 LED : RG LEDs

My problem is that i want to generate a program that indicate number of free parking slots available on a 4 digit segment. That is when parking is empty completely it display 10 and when full completely it displays 0. and when there is two car in the parking it display 8 that is parking available.

Note: LED are working fine when there is presence of a car and when no car.

In attachment : circuit connection for (sensors only) , parking design and programming file.

Can someone help me out for this programming. Thank you

Sketch_1.ino (10.3 KB)

@evanmars: Instead of posting a link to the other thread, use the Report To Moderator link, and get the threads merged. The moderators will deal with the people that crosspost.

Note: LED are working fine when there is presence of a car and when no car.

So, you can turn an LED on when needed, and off when needed.

You know how many are on initially. They don't come on or go off randomly. So, increment a counter when you turn one on and decrement the counter when you turn one off. Now, you KNOW the value to display. So, do it. What is the problem? Aside from the fact that your wiring diagram doesn't show that you have a seven segment display.

And where should i start initializing my count? in the setup or before?

shaandilesh:
And where should i start initializing my count? in the setup or before?

Either place could work.

byte parkingSpacesOccupied = 0;

void setup()
{
}

or

byte parkingSpacesOccupied;

void setup()
{
   parkingSpacesOccupied = 45;
}

is it the right way i've inserted the count?

isObstacle = digitalRead(sensorA1);
if (isObstacle == LOW)
{
Serial.println("OBSTACLE!!, OBSTACLE!!");
digitalWrite(LEDA11, HIGH);
count--;
}
else
{
Serial.println("clear");
digitalWrite(LEDA11,LOW);
count++ ;
}
if (isObstacle == LOW)
{
Serial.println("OBSTACLE!!, OBSTACLE!!");
digitalWrite(LEDA12, LOW);
count--;
;
}
else
{
Serial.println("clear");
digitalWrite(LEDA12,HIGH);
count++;
}

is it the right way i've inserted the count?

I suggested a meaningful name for the variable. You've used a stupid name that gives NO clue what is being counted. As far as I'm concerned, you can complete the project without any more help from me.

So here it is , for the meanwhile i've considered only 3 sensors. so Number of free parking initially should be 3 and decrement as car is sense in each slot.

int LEDA11 = 50;
int LEDA12 = 51;

int LEDA21 = 52;
int LEDA22 = 53;

int LEDA31 = 42;
int LEDA32 = 32;

int pinA = 2;  //For displaying segment "a"
int pinB = 3;  //For displaying segment "b"
int pinC = 4;  //For displaying segment "c"
int pinD = 5;  //For displaying segment "d"
int pinE = 6;  //For displaying segment "e"
int pinF = 8;  //For displaying segment "f"
int pinG = 9;  //For displaying segment "g"

int sensorA1 = 10; 
int sensorA2 = 11 ;
int sensorA3 = 12 ;

int isObstacle = HIGH;  // HIGH MEANS NO VEHICLE
byte parkingSpacesFree;

void setup() {
  // put your setup code here, to run once:

parkingSpacesFree = 3;

 pinMode(pinA, OUTPUT);  //A
  pinMode(pinB, OUTPUT);  //B
  pinMode(pinC, OUTPUT);  //C
  pinMode(pinD, OUTPUT);  //D
  pinMode(pinE, OUTPUT);  //E
  pinMode(pinF, OUTPUT);  //F
  pinMode(pinG, OUTPUT);  //G

  pinMode(sensorA1, INPUT);
  pinMode(sensorA2, INPUT);
  pinMode(sensorA3, INPUT);

  pinMode(LEDA11, OUTPUT); //RED LED indicating No car in parking slot
  pinMode(LEDA12, OUTPUT); //GREEN LED indicating Car in parking slot

  pinMode(LEDA21, OUTPUT);
  pinMode(LEDA22, OUTPUT);

  pinMode(LEDA31, OUTPUT);
  pinMode(LEDA32, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
isObstacle = digitalRead(sensorA1);
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LEDA11, HIGH);
    parkingSpacesFree --;
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LEDA11,LOW);
    parkingSpacesFree ++;
  }
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LEDA12, LOW);
   parkingSpacesFree --;
  ;
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LEDA12,HIGH);
    parkingSpacesFree ++;
  }


/////////////////////////////////////

 isObstacle = digitalRead(sensorA2);
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LEDA21, HIGH);
    parkingSpacesFree --;
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LEDA21,LOW);
    parkingSpacesFree ++;
  }
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LEDA22, LOW);
   parkingSpacesFree --;
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LEDA22,HIGH);
   parkingSpacesFree ++;
  }


/////////////////////////////////////
 isObstacle = digitalRead(sensorA3);
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LEDA31, HIGH);
    parkingSpacesFree --;
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LEDA31,LOW);
    parkingSpacesFree ++;
  }
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LEDA32, LOW);
    parkingSpacesFree --;
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LEDA32,HIGH);
  parkingSpacesFree --;
  }
 if ( parkingSpacesFree ==3)
 { 
   digitalWrite(pinA, HIGH);   
  digitalWrite(pinB, HIGH);   
  digitalWrite(pinC, HIGH);   
  digitalWrite(pinD, HIGH);   
  digitalWrite(pinE, LOW);   
  digitalWrite(pinF, LOW);   
  digitalWrite(pinG, HIGH);
  }
else if (parkingSpacesFree == 0)

{
   digitalWrite(pinA, HIGH);   
  digitalWrite(pinB, HIGH);   
  digitalWrite(pinC, HIGH);   
  digitalWrite(pinD, HIGH);   
  digitalWrite(pinE, HIGH);   
  digitalWrite(pinF, HIGH);   
  digitalWrite(pinG, LOW); 

}
else if (parkingSpacesFree == 1)
{
   digitalWrite(pinA, LOW);   
  digitalWrite(pinB, LOW);   
  digitalWrite(pinC, LOW);   
  digitalWrite(pinD, LOW);   
  digitalWrite(pinE, HIGH);   
  digitalWrite(pinF, HIGH);   
  digitalWrite(pinG, LOW);
}
else if (parkingSpacesFree ==2)
{
  digitalWrite(pinA, HIGH);   
  digitalWrite(pinB, HIGH);   
  digitalWrite(pinC, LOW);   
  digitalWrite(pinD, HIGH);   
  digitalWrite(pinE, HIGH);   
  digitalWrite(pinF, LOW);   
  digitalWrite(pinG, HIGH); 
}


}

Copy/paste fiasco strikes again. ANY time you feel the need to copy/paste code, STOP. THINK.

Can I create a function, instead. The answer, in your case, is YES. So get rid of 2/3rds of your code. Write a function to determine if a parking space is available, or not. Call that function INSTEAD of replicating the code.

I'll leave it to you to determine what you did wrong with the copy/paste fail.

Just correct the mistake and give me the final solution please..