claranadal
Published © CC BY-NC

Clap Controlled Car

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

IntermediateShowcase (no instructions)5,042
Clap Controlled Car

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Stepper Motor
Digilent Stepper Motor
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Microphone Amplifier Breakout
Adafruit Microphone Amplifier Breakout
×1
Arduino Vibration Shock Switch Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Schematics

Code

Code

Arduino
#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;
  }*/

Credits

claranadal

claranadal

0 projects • 1 follower

Comments