smart parking system coding help needed

shubhamjain28:
The think is you should never jump to conclusions without knowing anything about a person.This project is a mixed group project my electrical part has already been completed by me and the part which i am asking in this forum was supposed to be done by the CS department student ,but clearly since he wasnt doing it ,I am trying my best so that i can complete it.

hence I wrote (not saying this is who you are)
I was just explaining what to expect here. very factual statement.

it's unfortunately clear that you don't have the right programing background for that task. My recommendation would be to get your CS team mate to do her/his part of the job and not try to become a CS expert in a couple days.

Team work is a skill to learn and stepping up to the plate, take the lead and project manage the team to deliver the result is also a skill you can learn in such a project. Gather the team, have the people being late face their responsibility and the consequence for the whole group. They are letting you down. This is not good in a team. They are failing everyone else. Agree on an action plan, demonstrate you are willing to help if you can, understand why they don't complete their work. Is that skills? laziness? other? Once the plan is built - document the commitments. Time is short? then action should be quick.

if you can't solve it that way - go to your teacher. Don't hesitate to present the project management work you've done and it's totally fine to ask for guidance on how to get the other party to do its part of the job. explain why they are failing.

If worse comes to worse, when it comes to presenting the failed result and to assessing the quality of the work of the team - the teachers will know where the blame will go to.

If you do the job of the lazy / incompetent CS person, you are not doing yourself or herself/himself a favor. You are actually shooting yourself in the foot because the project will likely fail, or you will look stupid when the teacher asks you to explain what the code does and you'll have to admit you copied it on the internet and you'll get a bad rating despite the fact you did your work.

If you are lucky and this goes through - you will have been helping someone get a diploma they should not have. This is bad karma.

Stand your ground, act as an adult. Have people face their responsibilities. The world does not need one more bad engineer. There are other jobs your CS mate should focus on if CS is not what they want to do.


a bit on code:

compare this code

if (dist[i]>8){slot[i]=false;}
else{slot[i]=true;}

with that one

if (dist[i]>8){slot[i]=true;}
else{slot[i]=false;}

what do you think ends up in the slot array in the first code and in the second one? (is that rocket science?)

Note that this is the same as doing slot[i] = dist[i] > 8; you assign in the array the truth value you get by evaluating the logic test which is on the right side of the equal sign.

Regarding str[5], i know array starts from 0 and stores value in each position , char array stores a characted in each position.

So you understand you created an array with 5 positions. if you want to write in this array "P1,P2,P4," (yes you have an extra comma at the end) how many characters will you be using? what if you have to write "P1,P2,P3,P4," ? if you don't have enough space to store the string, then your code will go write somewhere in memory and that will clash with your other variables and trash the program in the way you have seen.
--> to fix this assess how big the longest possible string will be and allocate enough memory for that one. (+1 char as strings in c end up with an invisible null character at the end that you need to plan for - for example "hello" uses up 6 bytes. 5 for the letters and 1 for the invisible 0 at the end.)

Fine means its working properly , since I have two seperate sensors and motors for the two gates, i can open them both simultaneously

This is technically accurate. 2 sensors, 2 motors with separate commands so those things are indeed independent.

But your micro-porcessor is doing only one task at a time. Imagine that your arduino is a person working in the parking. Let's call him John. John can work and run across the parking lot very fast but he is alone. Imagine now that your code is asking John to do different things (this is what your code does in the loop())

Ask John to run to the entry gate and check if a car is there
if a car is at the entry gate then

  • John needs to open the gate
  • John waits for 3 seconds DOING NOTHING ELSE
  • John closes the gate (regardless if the car is still under the barrier - John does what he is told)

then the code asks John to run to the exit gate and check if a car is there
if a car is at the exit gate then

  • John needs to open the gate
  • John waits for 3 seconds DOING NOTHING ELSE
  • John closes the gate (regardless if the car is still under the barrier - John does what he is told)

--> you can see that when John is waiting (doing nothing else) at the entry gate, he is not at the exit gate to operate it so if there is a car both at the entry gate AND at the exit gate, despite the fact that you have 2 sensors and 2 motors, the gate operations are not happening in parallel because John can't be at the two places at the same time (even if he could run super fast back and forth between the two gates, you did not tell him to do so - you actually told him to stay at the entry gate). You are seing this as two separate electrical system - but they are not independent. The operator is the bottleneck.

then the code asks John

  • to pick up a piece of paper that is half an inch long and a very large pencil...
  • to go to the 1st parking space and check if there is a car there and make a note of this on a piece of paper
  • to go to the 2nd parking space and check if there is a car there and make a note of this on a piece of paper
  • to go to the 3rd parking space and check if there is a car there and make a note of this on a piece of paper
  • to go to the 4th parking space and check if there is a car there and make a note of this on a piece of paper

(John will complain that the paper is too small to write the sentence)

see the problem?