Giter Club home page Giter Club logo

raspberry-pi-4-stepping-motor-with-ultrasonic-sensor's Introduction

Control Stepping Motor Rotation with Ultrasonic Sensor Using C and a Raspberry Pi 4B

A project based on C that uses a Raspberry Pi 4B Rev. 1.2 board to make a stepping motor move counterclockwise or stop entirely depending on the distance calculated from the ultrasonic sensor. For GPIO pin mapping, I used WiringPi (Made by Gordon Henderson under GNU-LGPL) to simplify. Link: http://wiringpi.com/

WiringPi Note: The author has discontinued public releases of WiringPi. The last update was 2.52 for the Raspberry Pi 4B. Although WiringPi is preinstalled on Raspbian systems, the code for installation is as follows:

sudo apt-get install wiringpi

Use:

gpio -v

to check if your version is 2.52.

For more details visit http://wiringpi.com/download-and-install/

To upgrade, visit http://wiringpi.com/wiringpi-updated-to-2-52-for-the-raspberry-pi-4b/

Hardware components used:

  • (1) 4 pin Ultrasonic Sensor 5VDC (HC-SR04)
  • (1) Step Motor 28BYJ-48 5VDC
  • (1) ULN2003 Stepping motorDriver
  • (10) Female to Male Jumper Cable
  • (1) Male to Male Jumper Cable
  • (1) Breadboard powersupply
  • (1) Breadboard
  • (1) 12V 2.5A AC Adapter (Used for the breadboard power supply)
  • Raspberry Pi 4B Rev. 1.2

A 9V battery can also be used with the power supply board if an adapter is obtained.

For the ultrasonic sensor, I used the 5V pin from the Pi to VCC, GPIO 23 for Trig, GPIO 24 for Echo, and the GND pin on the Pi for GND.

About the pin usage in the code.

I used GPIO 23 for both components since in the code I have that pin as OUTPUT for both components to use.

When compiling the code, run the following commands in terminal at the location of the file:

sudo bash
gcc SteppingMotorWithUltrasonicSensor.c -o SteppingMotorWithUltrasonicSensor -lwiringPi 
./SteppingMotorWithUltrasonicSensor

This project was possible through an electronics kit I purchased from Freenove that provided me with all of the components I used. If interested, it is the "Freenove Ultrasonic Starter Kit for Raspberry Pi" (FNK0024).

raspberry-pi-4-stepping-motor-with-ultrasonic-sensor's People

Contributors

christophermilian avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.