hi "old man".
that's a cool project but you have 3 major modules to work together at the same time:
the I2C display;
the H-bridge motor;
the IR remote sensor.
the normal way when coding should be to test the module one by one in a dedicated code, and eventually export data to the serial monitor. Then, you should be able to understand your hardware and the way it interacts with the arduino board.
You code is obviously copied/paste from the net (no offense) so a very bad start for what I propose.
Here is the "coding course":
connect your LCD display to the board, make some "hello world" display on your pc with serial monitor and make some simple test (contrast settings, reboot in case of trouble, rotate the display etc...);
connect the H-Bridge to your board and make the motor turns in one direction, the other, then stop. You should also test "rotating function": opposite wheels are on but in the opposite direction.
if you feel brave enough, you may kept the display connected and export the H-bridge data to serial monitor (for example: current state applied to the bridge) so you can make logic links with what you expect, what the board understand, and how it acts accordingly.
almost finish: connect your IR sensor, and play with it as for the display: export every command received from the remote to serial monitor and observes the results.
If everything works fine there, you can consider yourself as a master of your harwdware (and normally, the different tests had showed up any circuitry issue), and it is time to:
code what you want by yourself, helping you with your brand new knowledge AND examples in the net (I find myself library impossible to use without at least a written example)
get back to the code you post, and use what you learnt to debug it and shift it to a running code.
Sorry to not be clear. It is wrong because I tryed to test rhe code and it didin't work.
The code was built to control a DC motor using a remote control.
Jut a last try: what do you exactly mean with "didn't work"? Something that don't work doesn't do anything, he's stopped, stone dead, passed on, he's no more, ceased to be, he's gone to meet 'is maker, he's off the twig, kicked the bucket! (cit.)
We need to know what you expect it does, and what you can say it does. without those information I personally can't say anything 'bout it.
PS: And no, a Norwegian blue plumage doesn't enter into it.
@GrandPete gives good advice. Break the task into chunks. Understand each chunk then put them all together.
You do not use a switch for each case. Use one switch and each case under that one switch.
void loop()
{
//decodificamos a entrada do receptor infravermelho
if (irrecv.decode(&results))
{
long int decCode = results.value;
Serial.println(results.value);
//SWITCH CASE para usar o botão pressionado do controle remoto
switch (results.value)
{
case 0xFF6897: //quando pressiono o botao 0 do meu controle remoto
motor.run(FORWARD);
motor.setSpeed(64);
lcd.clear();
lcd.print("FORWARD = 64");
delay(5000);
motor.run(RELEASE);
motor.setSpeed(0);
lcd.clear();
lcd.print("RELEASE = 0");
delay(5000);
motor.run(BACKWARD);
motor.setSpeed(64);
lcd.clear();
lcd.print("BACKWARD = 64");
delay(5000);
motor.run(RELEASE);
motor.setSpeed(0);
lcd.clear();
lcd.print("RELEASE = 0");
delay(5000);
break;
case 0xFF30CF: //quando pressiono o botao 1 do meu controle remoto
motor.run(FORWARD);
motor.setSpeed(127);
lcd.clear();
lcd.print("FORWARD = 127");
delay(3000);
motor.run(RELEASE);
motor.setSpeed(0);
lcd.clear();
lcd.print("RELEASE = 0");
delay(3000);
motor.run(BACKWARD);
motor.setSpeed(127);
lcd.clear();
lcd.print("BACKWARD = 127");
delay(3000);
motor.run(RELEASE);
motor.setSpeed(0);
lcd.clear();
lcd.print("RELEASE = 0");
delay(3000);
break;
case 0xFF18E7: //quando pressiono o botao 2 do meu controle remoto
motor.run(FORWARD);
motor.setSpeed(255);
lcd.clear();
lcd.print("FORWARD = 255");
delay(2000);
motor.run(RELEASE);
motor.setSpeed(0);
lcd.clear();
lcd.print("RELEASE = 0");
delay(2000);
motor.run(BACKWARD);
motor.setSpeed(255);
lcd.clear();
lcd.print("BACKWARD = 255");
delay(2000);
motor.run(RELEASE);
motor.setSpeed(0);
lcd.clear();
lcd.print("RELEASE = 0");
delay(2000);
break;
}
irrecv.resume(); // Recebe o próximo valor do botão que pressionamos
delay(20);
}
}
The serial print is your best debugging tool. Use serial prints to track progress of the code and variable values.
What version of the IRremote library do you have installed. That code is written for an older version of the library than current. See the IRremote library GitHub page.
And good job posting code properly in your first post. Most new users do not bother to read the guidelines and we have to waste time trying to get them to learn the rules. Thank you.
Thank you for your response. I would like to make a code to control a DC motor with a remote control. The code works well until the "void setup". The motor doesn't respond to remote commands.
Just a small note: please, don't call it "void setup", just "setup()" because "setup" is the function name, and "void" is just the data type returned (like any other possible data type).
Besides that, setup is the first function automatically called when the MCU starts, your setup function seems to perform some preliminary tests, and requires around 8 seconds to complete: what do you mean with "until setup"? Can you see the motor executing what you expect it'd do, or not?
And, talking about IR communications, as @groundFungus and @GrandPete said, other than using Serial.print() to get some debug information over SerialMonitor (set it up to higher speed like 115200, just to avoid delays due to debug serial printing), the best way for all projects involving new libraries and/or devices, is to make separate tests to learn how to correctly handle each one, instead of trying to mix them together, where often any problem with a single element/device prevents the program to correctly perform its tasks.
With IRremote, for instance, always run some of the example codes, and see how they work. Use IrRecvDump example to get the key codes to use on your program. I see you have some codes on "results.value" switch block, but always better check if the protocol received is the right one with "results.decode_type".
Then put the codes in the same switch block: as @groundFungus said, you have three unnecessary consecutive "switches", just mix them together (and for each "case" add a comment to remember what is the remote key corresponding to that code).
Apart from some other useless curly brackets around "irrecv.resume()" and final "delay(20)".
Do what we're suggesting you, then post here the "new" code, and describe exactly what you'll see (together with the corresponding Serial Monitor output), and we'll give it a try.