How do I make an Ultrasonic sensor trigger a pager motor?

I am trying to create sort of a belt for the blind for a school project using ultrasonic sensors and pager motors. If the ultrasonic sensor detects an object the pager motor powers on. However, I am having issues with getting the pager motor and ultrasonic sensor to cooperate.

I namely have two problems

  1. When using an external power source of 14v (which I will need for multiple pager motors) the ultrasonic sensor outputs an incorrect distance value of 1 centimeter. What can I do to fix this?
  2. How do I set up the board so the ultrasonic sensor and pager motor cooperate? As of now, I have the pager motor in a circuit that a LED would be in ( a resistor to the ground and vcc to digital write). Is this incorrect? What would be appropriate?

Below is the code and an image of my board.

Any help would be appreciated, Thanks.

const int trigPin = 9;
const int echoPin = 10;
const int motorPin = 11; // Change this to the pin where your pager motor is connected

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motorPin, OUTPUT); // Set motor pin as output
}

void loop() {
  long duration, inches, cm;

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();

  // Check if object is within 15cm
  if (cm <= 15) {
    // Turn on the pager motor
    digitalWrite(motorPin, HIGH);
    delay(50); // Keep the motor on for 50 milliseconds
    digitalWrite(motorPin, LOW);
  } else {
    digitalWrite(motorPin, LOW); // Turn off the motor
  }

  delay(100);
}

long microsecondsToInches(long microseconds) {
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
  return microseconds / 29 / 2;
}

Here is my schematic. I apologize for it being so sloppy, I am not so good with drawing them.

And is there any other way I have the ultrasonic sensor trigger the motor without the motor driver or a transistor? I don't think I have them and I am under a little bit of a time crunch.

Thanks

Not a chance. Most pager motors run on 1.5-3V, and MUST NOT be powered from a port pin. Use a transistor (or an array of them, like the ULN2003 IC) to switch the individual motors.

General outline for a transistor switch. Most NPN transistors will work for pagers, with a 3V power supply. The inductive kick diode is required:
Capture

Here is an example of one motor switched by a ULN2xxx IC. Eight can be accommodated, and the inductive kick diodes are built in to the IC.

Capture

1 Like

would something like this suffice? I just found it looking through my kit.

Probably not. The SN74HC595 is intended for LEDs, not motors.

You can get ULN2003 motor drivers for next to nothing on Amazon and eBay

1 Like

I see. Thank you for your help.

No, not at all.
Splendid job.

1 Like

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