This Repository Contains some of the basic codings related to some sensors and motors. It is divided into two parts: codings and schematics
This part contains the codings of different sensors and motors to be interfaced with arduino:
This Arduino program controls the rotation of a DC motor based on readings from an ultrasonic sensor. The program defines three cases of motion: FORWARD, BACKWARD, and STOP, depending on the distance measured by the ultrasonic sensor. The motor direction is changed based on these distance measurements.
- Arduino board
- DC motor
- Ultrasonic sensor
- Jumper wires
- Motor control pins: Connect to pins
c1
andc2
on the Arduino board. - Ultrasonic sensor: Connect the trigger pin to the
trig
pin and the echo pin to theecho
pin on the Arduino board.
- Upload the code to your Arduino board using the Arduino IDE.
- Power up the Arduino board.
- Open the Arduino IDE Serial Monitor to observe the motor's behavior based on the ultrasonic sensor readings.
This Arduino program governs the motion of a DC motor using two control pins for each motor. The motor control is based on a specified pattern for control pins A and B, where different combinations result in various motions such as forward, backward, left-turn, and right-turn.
The control logic for the DC motor is as follows:
i1 | i2 | i3 | i4 | Motion |
---|---|---|---|---|
LOW | HIGH | LOW | HIGH | Forward |
HIGH | LOW | HIGH | LOW | Backward |
LOW | LOW | LOW | HIGH | Left-turn |
LOW | HIGH | LOW | LOW | Right-turn |
i1
andi2
: Control pins for one motor.i3
andi4
: Control pins for another motor.
- Upload the code to your Arduino board using the Arduino IDE.
- Power up the Arduino board.
- Observe the DC motor's behavior as it goes through forward, backward, left-turn, and right-turn motions.
This Arduino program uses the Servo library to control a servo motor. The code gradually moves the servo from 0 to 180 degrees and then back from 180 to 0 degrees. The servo position is printed to the Serial Monitor for debugging purposes.
This project utilizes the in-built Servo library to control the servo motor. The Servo library provides easy-to-use functions for controlling servo motors.
- Connect the servo motor to the Arduino board.
- Define the pin to which the servo is attached using
servo.attach(pin)
. - Ensure the Arduino board is properly powered.
- Upload the code to your Arduino board using the Arduino IDE.
- Power up the Arduino board.
- Observe the servo motor gradually moving from 0 to 180 degrees and then back.
This Arduino program controls the motion of a servo motor based on the direction detected by an ultrasonic sensor within a specified range. The servo motor moves towards the maximum right or left based on the ultrasonic sensor reading and returns to the idle position.
The program utilizes an ultrasonic sensor to detect distances. The servo motor's direction is controlled based on the detected distance within predefined ranges.
Mid
: Middle distance range.Max
: Maximum distance range (right movement).Min
: Minimum distance range (left movement).
- Connect the ultrasonic sensor to the trigger (
trig
) and echo (echo
) pins. - Connect the servo motor to the signal pin (
motor.attach(9)
). - Ensure the Arduino board is properly powered.
- Upload the code to your Arduino board using the Arduino IDE.
- Power up the Arduino board.
- Observe the servo motor's motion based on the direction detected by the ultrasonic sensor.
This Arduino program measures the distance using an ultrasonic sensor and prints the result to the Serial Monitor. It includes the ability to set maximum (Max
) and minimum (Min
) detection ranges to limit the reported distance.
Max
: Maximum distance range for the sensor to detect.Min
: Minimum distance range for the sensor to detect.
- Connect the ultrasonic sensor to the trigger (
trig
) and echo (echo
) pins. - Ensure the Arduino board is properly powered.
- Upload the code to your Arduino board using the Arduino IDE.
- Power up the Arduino board.
- Open the Arduino IDE Serial Monitor to observe the distance measurements.
This Arduino program uses the NewPing
library to measure distance using an ultrasonic sensor and prints the results to the Serial Monitor. The NewPing
library simplifies distance measurements by providing convenient functions.
This project utilizes the NewPing
library, which offers functions such as ping_cm()
, ping_in()
, and ping_median(i)
to simplify distance measurements with an ultrasonic sensor.
- Connect the ultrasonic sensor to the trigger (
trig
) and echo (echo
) pins. - Ensure the Arduino board is properly powered.
- Upload the code to your Arduino board using the Arduino IDE.
- Power up the Arduino board.
- Open the Arduino IDE Serial Monitor to observe the distance measurements and the time taken for each ping.
This part contains the schematic representations of the connections that are being implemented on the basis of the codes in the coding sections.
- DC motor connections
- dc_motor_by_ur
- servo_control_by_ur
This project is licensed under the MIT License.