Go Down

Topic: How to make the DC motors in my project run?? (Read 60 times) previous topic - next topic

swastik100

I am building a project where I segregate different types of wastes (Metal, glass and plastic). I do this by using sensors to detect the type of the waste and then rotating the appropriate bin to collect the waste. There are three types of wastes and hence there are 3 bins; namely: Metal, Plastic and Glass. The problem I am facing is that the motors are not rotating. The detection part is fine; just the motors refuse to rotate. I rotated the motor with a simple code and hence I am sure the motor is fine. I am using an Adafruit Motor Shield to work with Arduino. Below is my code:

Code: [Select]

/* Basically, there is an incline on which the waste rolls down
before falling into a bin. In the code, m is Metal, g is Glass
and p is Plastic. I have assumed that the system always starts off
with the glass bin under the incline. Also, Pins 3 & 5 are used for
detecting glass, pin 4 is used to detect Metal and if none of the
sensors are actuated then the waste is plastic. There is an IR sensor
at the end of the incline to detect the arrival of waste. Therefore
when the IR sensor activates without any other sensor being activated,
the waste is plastic. The sensors follow inverse logic, so when
the sensors are actuated, they actually sens a LOW signal. LED connections
can be ignored. The Metal sensor is attached first followed by the sensors
for detecting glass.
*/
#include <AFMotor.h>
AF_DCMotor motor_plate(4);
int val;
char prev_state;
char current_state = 'g';
void setup() {

  Serial.begin(9600);
  motor_plate.setSpeed(100);
  motor_plate.run(RELEASE);
  pinMode(7,INPUT); //IR Sensor
  pinMode(5, INPUT_PULLUP); //Proximity Sensor for glass detection
  pinMode(3,INPUT_PULLUP);  // Proximity Sensor for glass detection
  pinMode(4,INPUT_PULLUP);  // Proximity Sensor for metal detection
  pinMode(10, OUTPUT);  // LED COnnection for Glass
  pinMode(12, OUTPUT);  // LED COnnection for Metal
  pinMode(11, OUTPUT);  // LED COnnection for Plastic
}
void loop(){
  Serial.println('Current State');
  Serial.println(current_state);
  Serial.println('Previous State=');
  Serial.println(prev_state);

  if (digitalRead(4) == HIGH){
    digitalWrite(12,LOW);
    if (digitalRead(5) == LOW || digitalRead(3) == LOW){
      digitalWrite(10,HIGH);
      delay(3000);
      digitalWrite(10,LOW);
      prev_state = current_state;
      current_state = 'g';
      if (prev_state == 'p'){
        motor_plate.run(FORWARD);
        delay(200);
        motor_plate.run(RELEASE);
      }
      else if (prev_state == 'm'){
        motor_plate.run(BACKWARD);
        delay(200);
        motor_plate.run(RELEASE);
      }
      else{
        motor_plate.run(RELEASE);
      }
    }
    else{
      digitalWrite(10,LOW);
      if (digitalRead(7) == HIGH){
        digitalWrite(11,HIGH);
       delay(3000);
        digitalWrite(11,LOW);
        prev_state = current_state;
        current_state = 'p';
        if (prev_state == 'm'){
          motor_plate.run(FORWARD);
          delay(200);
          motor_plate.run(RELEASE);
        }
        else if (prev_state =='g'){
          motor_plate.run(BACKWARD);
          delay(200);
          motor_plate.run(RELEASE);
        }
        else{
          motor_plate.run(RELEASE);
        } 
      }
    }
  }
  else{
    digitalWrite(12, HIGH);
   delay(3000);
    digitalWrite(12,LOW);
    prev_state = current_state;
    current_state = 'm';
    if (prev_state == 'g'){
      motor_plate.run(FORWARD);
      delay(200);
      motor_plate.run(RELEASE);
    }
    else if (prev_state == 'p'){
      motor_plate.run(BACKWARD);
      delay(200);
      motor_plate.run(RELEASE);
    }
    else{
      motor_plate.run(RELEASE);
    }
  }
}

jremington

For informed help, please post links to the data sheets for the motors and the motor power supply. Also post a hand-drawn wiring diagram (not Fritzing).

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy