Project showcase
Clap Controlled Car

Clap Controlled Car © CC BY-NC

We have created a car controlled by claps with Arduino. It also stops when it impacts with something.

  • 1,746 views
  • 0 comments
  • 3 respects

Components and supplies

Necessary tools and machines

Lasercutter
Laser cutter (generic)
Hy gluegun
Hot glue gun (generic)

Apps and online services

About this project

We decided to make a clap controlled car using three stepper motors (two for the back wheels and one for an impact arm).

  • When you clap once, the car goes straight.
  • When you clap twice, the car turns slightly to the right.
  • When you clap three times, the car turns slightly to the left.

At the same time, if the car is functioning and it impacts with an object, it moves it with an arm connected to the third stepper motor.

Code

CodeArduino
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64/2
Stepper small_stepper1(STEPS_PER_MOTOR_REVOLUTION, 10, 12 , 11, 13);
Stepper small_stepper2(STEPS_PER_MOTOR_REVOLUTION, 6, 8, 7, 9);
Stepper small_stepper3(STEPS_PER_MOTOR_REVOLUTION, 1, 4, 3, 5);

int sensorPin = A2;
int pushButton = 2;
int vib_pin = 2;
int  Steps2Take;
int cont;
long st;
int StepRod1;
int StepRod2;
int StepRod3;

boolean choque = false;

void setup() {
  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
  pinMode(vib_pin, INPUT);
  pinMode(StepRod3, OUTPUT);
  cont = 0;

  attachInterrupt(digitalPinToInterrupt(2), choca, FALLING);
}

void loop() {

  if (digitalRead(sensorPin) == HIGH) {
    delay(10);
    if (cont == 0)
      st = millis();
    cont = cont + 1;
    while (digitalRead(sensorPin) != LOW) {
      if (millis() - st > 2000) {
        Serial.print(cont);
        Serial.println(" aplausos");

        doOrders(cont);
        cont = 0;
      }
    }
  }
  if (millis() - st > 2000 && cont != 0) {
    Serial.print(cont);
    Serial.println(" aplausos");
    doOrders(cont);
    cont = 0;
  }
}


void doOrders(int apl) {


  if (cont == 1) {
    StepRod1 = HIGH;
    Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn
    small_stepper1.setSpeed(1000);
    small_stepper2.setSpeed(1000);

    Serial.println("Adelante");

    StepRod2 = HIGH;

    for (int i = 0; i < Steps2Take; i++) {
      small_stepper1.step(-1);
      small_stepper2.step(1);

      if (choque) {
        brazo();
        choque = false;
        return;
      }
    }

    StepRod3 = LOW;
  }


  if (cont == 2) {
    StepRod2 = HIGH;
    Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn
    small_stepper2.setSpeed(1000);

    Serial.println("Giro 1");
    for (int i = 0; i < Steps2Take; i++) {
      small_stepper2.step(1);

      if (choque) {
        brazo();
        choque = false;
        return;
      }
    }

    StepRod1 = LOW;
    StepRod3 = LOW;

  }


  if (cont == 3) {
    StepRod1 = HIGH;
    Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn
    small_stepper1.setSpeed(1000);

    Serial.println("Giro 2");

    for (int i = 0; i < Steps2Take; i++) {
      small_stepper1.step(-1);

      if (choque) {
        brazo();
        choque = false;
        return;
      }
    }

    StepRod2 = LOW;
    StepRod3 = LOW;
  }

}

void choca() {
  choque = true;
}


void brazo() {

  //digitalWrite(StepRod3, HIGH);
  //delay(500);

  Serial.println("Brazo");

  Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn
  small_stepper3.setSpeed(1000);
  small_stepper3.step(Steps2Take);

}

/*
  if (moviPin = HIGH) {
    StepRod1 = HIGH;
    Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn
    small_stepper1.setSpeed(1000);
    small_stepper1.step(Steps2Take);

    StepRod2 = LOW;
    StepRod3 = LOW;
  }*/

Schematics

Schematics
Joneonepinipotone bb ptmf3n6vxc

Comments

Similar projects you might like

RC Car to BT Car Controlled with Blynk

Project tutorial by Team Daxes Hacks

  • 3,602 views
  • 2 comments
  • 6 respects

Voice Controlled K'nex Car

Project tutorial by Austin Wilson

  • 9,819 views
  • 4 comments
  • 52 respects

Arduino Controlled Car with HC-SR04

Project showcase by VASILEIOS MOUGIOS

  • 7,741 views
  • 0 comments
  • 11 respects

Voice Controlled Car

Project tutorial by Yug_Ajmera

  • 5,091 views
  • 0 comments
  • 9 respects

PlayStation Remote Controlled Wireless Car

Project showcase by Jasmeet Singh

  • 2,606 views
  • 1 comment
  • 6 respects
Add projectSign up / Login