How many sensors can a motor drive handle?

My school project is a solar powered automated disinfecting robot that will alarm every 5 minutes. It consists of Arduino UNO R3, 2 N20 DC motors, 3 unltrsonic sensors, 1 buzzer, and 8 UV LEDs, 1 L293D motor drive shield, and 2 IR proximity sensors. When I connected my ultrasonic sensor to my motor drive, I realized that I no longer have space for my other components and lights. Do I need to use a second microcontroller or is it possible to fit it in that one motor drive?

Hi, @skye4217
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

We need to see your code and a circuit diagram showing how you have the motor,motor driver, UNO and Ultrasonic connected.

What do you want the motors to do when the Ultrasonic detects anything?

Have you written any code to test ONE Ultrasonic unit on its own?
Have you written any code to test THREE Ultrasonic units as a group?
Have you written any code to test the motor driver and motors on their own?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

When you say "fit" do you mean physically or enough I/O pins wise?

When you say "is it possible to fit it in that one motor drive" its not clear what "that" is and what you mean "on one motor drive"?

Sorry for the late reply. The softwares that I use didn't have the motor drive shield I need. Therefore, I used photoshop to make my circuit diagram.

I want to include the IR sensors, buzzer module, and LED's but I no longer have enough pins.

Also, do you mind checking this code, I'm starting with ultrasonic sensors and motors first before I add the IR sensors

<#include <AFMotor.h> 
const int trigPin1 = A5;
const int echoPin1 = A4;
const int trigPin2 = A3;
const int echoPin2 = A2;
const int trigPin3 = A1;
const int echoPin3 = A0;

AF_DCMotor motor1(3);  
AF_DCMotor motor2(4);
long duration1;
long duration2;
long duration3;
int left;
int front;
int right;

void setup() {
  pinMode(trigPin1, OUTPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin1, INPUT); 
  pinMode(echoPin2, INPUT);
  pinMode(echoPin3, INPUT);
  Serial.begin(9600); 
  
  motor1.setSpeed(255);   
  motor2.setSpeed(255);

}
void loop() {
  
  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distanceleft = duration1 * 0.034 / 2;
  Serial.print("Distance1: ");
  Serial.println(left);
  
  digitalWrite(trigPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distancefront = duration2 * 0.034 / 2;
  Serial.print("Distance2: ");
  Serial.println(front);
  
  digitalWrite(trigPin3, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin3, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin3, LOW);
  duration3 = pulseIn(echoPin3, HIGH);
  distanceright = duration3 * 0.034 / 2;
  Serial.print("Distance3: ");
  Serial.println(distanceright);
  
  if ((distanceleft <= 15 && distancefront > 15 && distanceright <= 15) || (distanceleft > 15 && distancefront > 15 && distanceright > 15))
  {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
  }
  if ((distanceleft <= 15 && distancefront <= 15 && distanceright > 15) || (distanceleft <= 15 && distancefront > 15 && distanceright > 15))
  {
    motor1.run(RELEASE);         
    motor2.run(RELEASE);
    delay(1000);
    motor1.run(FORWARD);         
    motor2.run(BACKWARD);        
    delay(500); 
  }
  if ((distanceleft > 15 && distancefront <= 15 && distanceright <= 15) || (distanceleft > 15 && distancefront > 15 && distanceright <= 15) ||  (distanceleft > 15 && distancefront <= 15 && distanceright > 15) )
  {
    motor1.run(RELEASE);         
    motor2.run(RELEASE);
    delay(1000);
    motor1.run(BACKWARD);         
    motor2.run(FORWARD);        
    delay(500);
  } 
}

AT this point, how many of the devices have you tested, individually?

From what I'm understanding of this question, all 3 ultrasonic sensors work fine with the motor drive at the same time. i want to know if it's possible to add my extra parts

P.S.
Looking back at my code, I accidentally put "distance-" in front of some of the "left, right and front" becuase i thought about the distance between the designated ultrasonic sensor and the obstacle, but I fixed it now

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