code doesnt work need help! (done)

Hi I'm doing a smart parking which has 6 parking spots due to my Arduino Uno lack of place in analog pins.
the smart park shows me where is the closest park on the LiquidCrystal LCD (16,2).
when the park is full the Servo motor closes (goes to 90degrees) and my RGB turns red.
I wrote the code and it doesn't has compilation problems but it just don't do anything and I cant find out why. I would like you guys to take a look and help me figure out what the problem is.
components : 6 IR_LEDs, 6 Photodiodes, 6 220Ω resistors, 6 10kΩ resistors, Arduino Uno, LiquidCrystal LCD(16,2), servo motor.
also my connections is ok I tested everything separately and all worked.
here is the code:
thanks again for helping!
Edit: in the first line of code i changed to int i=0, counter, val
it says on the LCD bunch of times go to park 7 and some weird signs and i only have 6 parks.
anyone help?

  for (i = 0; i < 6; i++);
  {
    .....
    if (counter == 6)

Not going to happen, is it?

AWOL:

  for (i = 0; i < 6; i++);

{
    .....
    if (counter == 6)


Not going to happen, is it?

thanks I fixed it but it still doesn't do anything, I mean the RGB doesn't turns on/servo don't move/nothing on the LCD
edit: i cant English properly i wanted to say i fixed the i<6 to i<7 but it doesn't solve my problem

alonkvetny1:
thanks I fixed it

I guess we'll just have to take your word for that.

AWOL:
I guess we'll just have to take your word for that.

what do you mean?

You didn't show the fix. What did you fix? How did you fix it? Does that break anything else?

MorganS:
You didn't show the fix. What did you fix? How did you fix it? Does that break anything else?

i edited the comment. excuse me for my poor English :frowning: .
also i edited the post and i got another problem, maybe do you know how to print on the lcd only once instead of printing endlessly?

LCD displays usually don't understand carriage return or newline; try to replace println by print.

alonkvetny1:
also i edited the post

Edited what Post?

...R

You aren't going to get very far with this:

  for (i = 0; i < 7; i++);

The semicolon terminates the for statement with a null statement. It will do nothing eight times and then proceed - actually the compiler will recognize that it does nothing and remove it.

Get rid of the semicolon.

DON'T CROSSPOST You've already been told about the semicolon.

Pete

Robin2:
Edited what Post?

...R

my post

sterretje:
LCD displays usually don't understand carriage return or newline; try to replace println by print.

i don't know how i put an integer in lcd.print together with some text
i tried lcd.print("go to ",i) but it doesn't allow that, can you help me with this command?

Print the string and the integer separately.

AND DON'T CROSSPOST

Simple test for the display.

void loop()
{
  int i = 3;
  lcd.print("go to ");
  lcd.print(i);
  delay(1000);
}

Without the delay, will have a scrolling scrolling text.

And please do not modify code once you have had replies that comment on that code; just add a new post.

alonkvetny1:
my post

Do us a favour and tell us the Reply number. You had 5 Posts before I asked which one you had edited.

...R

sterretje:
Simple test for the display.

void loop()

{
 int i = 3;
 lcd.print("go to ");
 lcd.print(i);
 delay(1000);
}



Without the delay, will have a scrolling scrolling text.

And please do not modify code once you have had replies that comment on that code; just add a new post.

oh ok it fixed the screen I didn't know you can do lcd.print 2 times for 1 line.
anyway now it loops between the parks 0 4 5 instead of 0 1 2 3 4 5 (because all is empty) and how can I make it show the closest park ( to 0) ?

Show your updated code (in a new post).

You can use a break statement to break out of your for loop when you detect a free parking.

sterretje:
Show your updated code (in a new post).

You can use a break statement to break out of your for loop when you detect a free parking.

I posted a new post with updated code
https://forum.arduino.cc/index.php?topic=465939.0

Hi,

components : 6 IR_LEDs, 6 Photodiodes, 6 220Ω resistors, 6 10kΩ resistors, Arduino Uno, LiquidCrystal LCD(16,2), servo motor.
also my connections is ok I tested everything separately and all worked.

Okay so show us the circuit diagram, so we can use it as a reference to what the input and output signals are.
What is the value of the input signal when the space is occupied and unoccupied.
Post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Hi,
First thing I can see is you do not reset "counter" to zero each time, before doing your analogRead for loop.
So there is nothing to stop counter increasing over 6.

Tom... :slight_smile: