please help me with the coding

Hello to whoever is reading,

I recently had a project where I had to make a car, now my car has a number things (2 LEDs, 2 DC motors, buzzer, IR remote, and ultrasonic). And I think I have a problem with the coding because so many of my classmates have the same problem.

(Sorry I don’t know how to post the coding properly)


#include “IRremote.h”
const int motorPin = 6;
const int motorPin1 = 9;
int speed;
int delayTime = 20;
int receiver = 11;
IRrecv irrecv(receiver);
decode_results results;
int buzzerPin = 10;
#include <NewPing.h>
NewPing sonar(3, 2, 400); //(trig,echo,max range)
int Distancecm;

void setup()
{
Serial.begin(9600);
Serial.println(“IR Receiver Button Decode”);
irrecv.enableIRIn();
pinMode (7, OUTPUT); //red led
pinMode (8, OUTPUT); //red led
pinMode (5, OUTPUT); //yellow led
pinMode (4, OUTPUT); //yellow led
pinMode (buzzerPin, OUTPUT);
pinMode (motorPin, OUTPUT);
pinMode (motorPin1, OUTPUT);
Serial.begin(9600);
Serial.println(“UltraSonic Distance Measurement”);

}

void loop()
{

delay(100);
Distancecm = sonar.ping_cm();
Serial.print(“Ping: “);
Serial.print(Distancecm);
Serial.println(” cm”);
delay(2000);
}

{if (irrecv.decode(&results))
{
translateIR();
irrecv.resume(); // receive the next value
}
}
}
void translateIR()
{
switch(results.value)
{

case 0xFF629D: Serial.println(" CH-");
for(speed = 255; speed >= 0; speed–);
{analogWrite(motorPin,speed);
analogWrite(motorPin1,speed);
delay(delayTime);}
break;

case 0xFF22DD: Serial.println(" CH");
digitalWrite (motorPin, LOW);
digitalWrite (motorPin1, LOW);
break;

case 0xFF02FD: Serial.println(" CH+");
for(speed = 0; speed <= 255; speed++)
{analogWrite(motorPin,speed);
analogWrite(motorPin1,speed);
delay(delayTime); }
break;

case 0xFFC23D: Serial.println(" EQ"); break;

case 0xFFA857: Serial.println(" vol+");
digitalWrite (buzzerPin, LOW);
delay (100);
digitalWrite (buzzerPin, HIGH);
delay (1000);
digitalWrite (buzzerPin, LOW);
break;

case 0xFF6897: Serial.println(" vol-"); break;
case 0xFF9867: Serial.println(" 100+"); break;
case 0xFFB04F: Serial.println(" 200+"); break;

case 0xFF30CF: Serial.println(" 1");

if (speed=0)
{digitalWrite (7, HIGH);
digitalWrite (8, HIGH);}

else {digitalWrite (7, LOW);
digitalWrite (8, LOW);}

break;

case 0xFF18E7: Serial.println(" 2"); break;
case 0xFF7A85: Serial.println(" 3"); break;
case 0xFF10EF: Serial.println(" 4"); break;
case 0xFF38C7: Serial.println(" 5"); break;
case 0xFF5AA5: Serial.println(" 6"); break;

case 0xFF42BD: Serial.println(" 7");
digitalWrite (7, HIGH);
digitalWrite (8, HIGH);
digitalWrite (5, HIGH);
digitalWrite (4, HIGH);
delay(1000);
digitalWrite (7, LOW );
digitalWrite (8, LOW);
digitalWrite (5, LOW);
digitalWrite (4, LOW);
break;

case 0xFF4AB5: Serial.println(" 8"); break;
case 0xFF52AD: Serial.println(" 9"); break;
case 0xFFFFFFFF: Serial.println(" REPEAT");break;
default:
Serial.println(" other button");

}
delay(500);
}


You didn't say what the problem is....

Sorry I don't know how to post the coding properly

There are three stickies at the top of the forum. The third one, in item #6, shows how. In fact, that topic is titled "Read this before posting a programming question ...".

So, the fact that you posted the code incorrectly shows that you are flaunting the forum, which is NOT a good way to start.

You might want to think about where the loop() function starts, and where it ends. Consider, too, that all code must be inside a function.

ardy_guy:
You didn't say what the problem is....

Totally sorry about that... My problem is that once I try to verify or send it to the arduino it would say "Error compiling for board Arduino/Genuino Uno." And I want to know why...

helpme09082000:
Totally sorry about that... My problem is that once I try to verify or send it to the arduino it would say "Error compiling for board Arduino/Genuino Uno." And I want to know why...

See reply #3.

Yes, post #3, plus learn what ";" is for. In fact, just take some time to learn C syntax at all.

boolrules:
Yes, post #3, plus learn what ";" is for. In fact, just take some time to learn C syntax at all.

Look I'll be honest with you, I have no idea what I am doing most of the time. Because in my high school I am required to take a course called Arduino (and we only learn the "basics"), so forgive me if I am not an expert. That's why I am here... I need to know where I went wrong so I can submit the project on the due date, and not be late.

I need to know where I went wrong

I did tell you that, in reply #3. To repeat, functions are blocks of code, starting with a { and ending with a }. Look at where loop() starts. That is, where is the { that opens the body of loop? Look at there loop() ends. That is, where is the } that matches the { that starts the function?

Look to see if there are error messages that refer to lines after the one that the } is on that marks the end of loop(). Hint: There is a LOT of code after that point.

All code must be in a function. loop() is a function. All the code that is after loop() ends must be moved into a function.

It really IS that simple.

If you properly indented your code as you typed it, you'd not make that mistake.

helpme09082000:
(and we only learn the "basics")

We're talking about the curly braces and semicolons. It doesn't get any more basic C code than that. That is literally the very first thing one should learn.

Perhaps it's your "educators" that have failed to provide you with the required prerequisites. Maybe they don't understand the parameters of the project. I wonder if they can execute the design you are working on.

helpme09082000:
Look I'll be honest with you, I have no idea what I am doing most of the time. Because in my high school I am required to take a course called Arduino (and we only learn the "basics"), so forgive me if I am not an expert. That's why I am here... I need to know where I went wrong so I can submit the project on the due date, and not be late.

As a retired educator and a newbie learning Arduino, perhaps I can offer a bit of advice to the OP.

First, I sense that you are not particularly interested in the Arduino course because you mention the fact that it is required. To which I can only tell you that the world is changing and evolving much more rapidly than it did in my day. The fact that your high school mandates a programming course in an object oriented language indicates to me that the educators recognize this fact and are trying to prepare you for what the future holds. I can say with confidence that unless you plan to push shopping carts around the WalMart parking lot, a knowledge of programming in the future will be essential.

The project upon which you are embarking consists only of "basics" as far as programming goes. If you have been following the classroom work and labs to this point you should have mastered the basics to complete this assignment.

The fact that you did not take the time to read the "stickies" at the beginning of this forum indicates to me that like so many young folks today you are looking for quick and dirty answers without putting in the required prelim work. The folks who provide answers on this forum are here to point you in the right direction to solve your problem. They are NOT here to solve your problem for you.

I also get the sense that the due date for the project is rapidly approaching and you are nearing the panic stage. I can only offer you the same counsel I gave to my students and work colleagues. "Failure to properly prepare on your part does not constitute an emergency on our part".

Now, directly addressing the problems encountered with your project:

  1. Break the sketch down by individual components, e.g. IR receiver, sonic device, motors, etc. Write a sketch how to control each one of them. Then integrate the parts into the whole. Come back here for advice on getting each snippet to work properly.

  2. Work in groups. A group working together finds ways to figure out how to attack and solve problems. If you are working with a group and they are knuckleheads - find another group.

  3. Learn about debugging. Do you know what all of those print statements in your code mean?

PaulS:
So, the fact that you posted the code incorrectly shows that you are flaunting the forum, which is NOT a good way to start.

Flouting.

BertZ:

  1. Break the sketch down by individual components, e.g. IR receiver, sonic device, motors, etc. Write a sketch how to control each one of them. Then integrate the parts into the whole. Come back here for advice on getting each snippet to work properly.

I did that already, my problem is when I include the ultrasonic there is a problem with the coding. But once I remove it the whole project miraculously works... Oh well it doesn't matter anymore.

Thanks for all the help and criticism that I received, it was lovely meeting y'all.