IR Remote Control Car (Comptek4)

Hello, I'm a teacher and I'm trying to help my 11yo. student with a project. I'm a beginner and we're doing learning virtually which also makes troubleshooting way more difficult. We've done a few little projects on the arduino uno and muddled through so the board and all the components are working. While we're waiting for responses, we'll try a simpler IR remote project to build our experience there. Please be patient with us, we're learning and we're not sure what to look up for specific questions because we're unsure on the point of failure. The code seems sound. I have a back up kit on the way where I'll be able to wire like he did and take clearer pictures. In the mean time, does anything look immediately wrong?

We're using L298N motor driver ( Driver / Dual controller for stepper and DC motors - L298N - ElectroYA RC - Racing Drones ), Arduino Uno board with prototyping shield, and generic remote (DFRobot kit: DFRobot Starter Kit for Arduino with 15 Arduino Projects Tutorial - DFRobot )

Here's his post:
I’m trying to make the ir remote car by [comptek4](http://"https://create.arduino.cc/projecthub/comptek4/ir-remote-control-car-updated-fcb8a5?ref=search&ref_id=ir remote control" car&offset=14). (https://create.arduino.cc/projecthub/comptek4/ir-remote-control-car-updated-fcb8a5?ref=search&ref_id=ir%20remote%20control%20car&offset=14)

I used a different motor driver. A different ir remote and sensor. I’m only using 2 motors and 6 batteries. Do you need to plug wires into the enb and ena slots if so what wires do I use and how do I connect them? Do I need more batteries? Do I need more motors?

I also tried wiring the batteries straight to the motor driver and the Arduino is powered with a USB port.

Screen Shot 2021-01-19 at 12.39.06 PM.png

Screen Shot 2021-01-19 at 12.39.06 PM.png

This one?

(Your link is broken - the code there is AWFUL - the code and the comments don't match, and the whole thing could be simplified and factored)

I used a different motor driver.

Link, please

For now, forget the IR control, and just use the serial interface to try controlling motors.

Before that even, maybe just a simple timed (say, 5 seconds each) forward/reverse.

I don't have the hardware, but I'll see if I can simplify the code.

EDIT: That code is worse than I thought - it does analogWrite to pins that aren't PWM pins.
I'm shocked this rubbish gets published.
I can't be bothered with Fritzing crayon scrawls, so I haven't checked that.

This code should compile, but obviously is untested.

#include <IRremote.h>

int statusled = 13;
// ENA and ENB pins should only be connected to pins 3, 5, 6, 9, 10 or 11 on a Uno or Nano
// (Check the reference page for "analogWrite" for your board)
const byte enA = 3;  //Make SURE this is a PWM pin and has a ~ next to it
const byte in1 = 12;
const byte in2 = 11;
// motor B
const byte enB = 5; //Make SURE this is a PWM pin and has a ~ next to it
const byte in3 = 10;
const byte in4 = 9;

const int A_SPEED = 200;
const int B_SPEED = 200;
const int DELAY_TIME = 5000;

void setup()
{
  Serial.begin(9600);

  pinMode(statusled,OUTPUT);
  digitalWrite(statusled,LOW);

  // set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}

void motorAcontrol (int in1State, int in2State, int speed)
{
  digitalWrite(in1, in1State);
  digitalWrite(in2, in2State);
  analogWrite(enA, speed);
}

void motorBcontrol (int in3State, int in4State, int speed)
{
  digitalWrite(in3, in3State);
  digitalWrite(in4, in4State);
  analogWrite(enB, speed);
}

void loop() 
{
  Serial.println(F("Both forward"));
  motorAcontrol (HIGH, LOW, A_SPEED);
  motorBcontrol (HIGH, LOW, B_SPEED);
  delay (DELAY_TIME);

  Serial.println(F("A forward, B stop"));
  motorAcontrol (HIGH, LOW, A_SPEED);
  motorBcontrol (LOW, LOW, B_SPEED);
  delay (DELAY_TIME);

  Serial.println(F("A forward, B reverse"));
  motorAcontrol (HIGH, LOW, A_SPEED);
  motorBcontrol (LOW, HIGH, B_SPEED);
  delay (DELAY_TIME);

  Serial.println(F("A stop, B forward"));
  motorAcontrol (LOW, LOW, A_SPEED);
  motorBcontrol (HIGH, LOW, B_SPEED);
  delay (DELAY_TIME);

  Serial.println(F("A reverse, B forward"));
  motorAcontrol (LOW, HIGH, A_SPEED);
  motorBcontrol (HIGH, LOW, B_SPEED);
  delay (DELAY_TIME);

  Serial.println(F("Both reverse"));
  motorAcontrol (LOW, HIGH, A_SPEED);
  motorBcontrol (LOW, HIGH, B_SPEED);
  delay (DELAY_TIME);
 
  Serial.println(F("Both Stop"));
  motorAcontrol (LOW, LOW, A_SPEED);
  motorBcontrol (LOW, LOW, B_SPEED);
  delay (DELAY_TIME);
}

A great gesture but I believe it is currently out of your range. Would you teach your student how to build a house without the basic tools, knowledges and skills. Electronics is the same way, you need to acquire the basic skills and build from that. If the student has to many failures it will discourage but some failures definitely help learning especially when solved. The internet is a fantastic tool with the proper guidance a lot will be learned. The remote car is a great target for the end but definitely not a starting point without experienced help. When you installed your IDE you found a lot of tried and true examples that came with it. Have you tried them? Start with them and spend a few bucks on some of the parts. You can get a nice shield assortment on Allexpress at:

and it is less then $15.00. You can also get a 8 channel analyzer for even less from the same source. USB Logic Analyzer 24M 8CH Microcontroller ARM FPGA Debug Tool 24MHz, 16MHz, 12MHz, 8MHz, 4MHz, 2MHz Logic Analyzer usb 24mhz|Oscilloscopes| - AliExpress
You have fun and let us know how you do!

Thank you both for your quick responses. Me and my student read them over just now. formerlyAWOL, We're going to upload your revised code and report back. Thank you for your time. I edited the link, sorry for the inconvenience. The motor driver we're using the l298n, I added the link in the OP Driver / Dual controller for stepper and DC motors - L298N - ElectroYA RC - Racing Drones.

gilshultz, you're right that a remote control car is way out of our depth. We have done the basic projects like single led, buzzer alarms, sweep, etc. He has created an error log and resolved most of the errors. This was his attempt at a final project. We figured we'd be able to work through it since everything is premade; we're not innovating. We chose the most stripped down IR car with similar components to our DFRobot kit. As a teacher, I could teach only what I'm familiar with, but then he would not have the opportunity to code at all. I've got to support my students on their own path and that requires learning with them, so here we are. Is there a simplified version of this you'd recommend to go with the kit you suggested? We're going to do some basic remote control projects to gain those "tools."

Again, thank you both for your support. We'll continue to update, but we only have 30min/day so it's slow going.

Some general advice:

Don't put together something completely new, program it, and expect good results.
You have to instill the expectation that you will fail, but do your best to arrange that the failures will be small (because they're incremental) and that you will learn by them.

Don't be afraid to add in code that you know won't be essential in the finished product - you don't want to see your house surrounded by scaffolding, but you wouldn't think of building a house without it.
Scatter prints around, even of each branch of an "if", if you're not sure why your code is doing what it is doing.

Hey AWOL, thanks for the advice. I always expect the worst so it's a pleasant surprise whenever they get something working. He's also failed on every first attempt of every project except blinking LED, so he reports also expecting failure despite his optimistic attitude. He's learned resiliency already. We did attempt to upload the code you provided, but were not able to resolve this error. We're typically only able to resolve syntax errors at our level. He did start a basic remote control project today to fold in more experience.

That's not really a syntax error, but is telling you that the sketch doesn't have a function called loop().

In future, please don't post pictures, post text.
Post your sketch (in code tags) and post the error message - the IDE even has a control to allow you to copy the whole error message.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.