Running a Micro Servo and Sonar with Arduino Uno

 Week 5, 25th October


Things you need:

An Arduino Uno connected with computer,

Three wires black, red and yellow,

And a micro servo.


How to connect wires:

- Connect red wire also known as power wire to 5V of Arduino.

- Connect black wire to ground pin (Gnd) of Arduino.

- And connect yellow wire to digital pin 9 of Arduino.

The code to run a micro servo
# include <Servo.h>
Servo myservo; //create servo object to control a servo
// twelve servo objects can be created on most boards

int pos=0; //variable to store the servo position

void setup() {
myservo.attach(9); //attaches the servo on pin 9 to the servo object
}
void loop () {
for (pos=0; pos <=90; pos+=1) {//goes from 0 degree to 180 degree
// in steps of 1 degree
myservo.write(pos); //tell servo to go to position in variable 'pos'
delay(15);     // wait 15 ms for servo to reach the position
}
for(pos=180; pos>=0; pos-=1) {// goes frm 180 to 0 degree
myservo.write(pos);   //tell servo to go to position in variable 'pos'
delay(15);      // wait 15 ms for servo to reach the position
}
}


Things you need:

Micro Servo

Arduino

Ultrasonic (HC-SR04)

Connecting wires






Overall, a small motor and ultra sonic sensor were used together with arduino uno to achieve a 90 degree rotation on the motor which is being activated based on how close something is to it. Ultrasonic sensors can be used in conjunction with AI to do tasks like detecting obstacles for autonomous vehicles, precisely detecting gestures to enable hard free movement control of equipment, an managing energy in smart appliances. This is because the sensor provides information of the environment.




Comments

Popular posts from this blog

Building a MIDI Instrument

Introduction to Arduino Uno

Running MPU-92/65 sensor with Arduino to Measure Real time Temperature