Seeed
Published © MIT

Remote control car-based on Seeedruino XIAO expansion board

Remote control car based on Seeeduino XIAO, and the new product Seeeduino XIAO Expansion board!!

IntermediateFull instructions provided6 hours2,882

Things used in this project

Hardware components

Seeed Studio Seeeduino XIAO
×1
Seeed Studio Seeeduino XIAO expansion board
×1
Grove IR receiver
×1
Grove - I2C Mini Motor Driver
Seeed Studio Grove - I2C Mini Motor Driver
×1
21 key mini controller
×1
Mini motor
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Seeeduino XIAO expansion board - remote control car

C/C++
this code is for remote control car using Seeeduino XIAO expansion board
#include <Arduino.h>
#include <IRremote.h>
#include <SparkFunMiniMoto.h>  // Include the MiniMoto library
// Create two MiniMoto instances, with different address settings.
MiniMoto motor0(0xC4); // A1 = 1, A0 = clear
MiniMoto motor1(0xC0); // A1 = 1, A0 = 1 (default)

#define FAULTn  1     // Pin used for fault detection.

int RECV_PIN = 0; // set pin 2 as IR control
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  Serial.println("Enabling IRin");  // remind enabling IR
  irrecv.enableIRIn(); // Start the receiver
  pinMode(FAULTn, INPUT);
}

void loop() {
  if (irrecv.decode(&results)) { //checking IR signal
    if (results.value == 2155862055) {
      //Forward  2155862055
      motor0.drive(-600);
      motor1.drive(600);
      delayUntil(20);
    }
    if (results.value == 2155813095) {
      //Brake   2155813095
      motor0.brake();
      motor1.brake();
      delay(100);
    }
    if (results.value == 2155823295) {
      //backward  2155823295
      motor0.drive(600);
      motor1.drive(-600);
      delayUntil(20);
    }
    if (results.value == 2155829415) {
      //Stop  2155829415
      motor0.stop();
      motor1.stop();
      delay(100);
    }
    if (results.value == 2155821255) {
      //turn right   2155821255
      motor0.drive(600);
      motor1.drive(600);
      delayUntil(20);
    }
    if (results.value == 2155837575) {
      //turn left    2155837575
      motor0.drive(-600);
      motor1.drive(-600);
      delayUntil(20);
    }
    irrecv.resume();                    //recive next intrustion

  }
  delay(100);
}

void delayUntil(unsigned long elapsedTime) {
  unsigned long startTime = millis();
  while (startTime + elapsedTime > millis()) {
    if (digitalRead(FAULTn) == LOW) {
      byte result = motor0.getFault();
      result = motor1.getFault();
    }
  }
}

Credits

Seeed

Seeed

102 projects • 168 followers
Seeed R&D Team

Comments