12. Output devices

This week was about the output devices, where we have to control a device with the microcontroller to do something.

Group Assignment

Please find our group assignment here.

ATmega 328p

In this week I will use the ATmega 328p that I have fabricated in the input devices week to control a servo motor, below is the board design,

As you can see from the board design, there are free pins where I can attach any external output device which are, D9,D10,A2,A3,&A4.

So In this week I will try to control a servo motor by connecting it to D9 pin to provide the PWM signal .

Servo Motor MG90s

I will be using the MG90s servomotor which is a tiny and lightweight with high output power servo,

So, before I start controlling the servo motor, I have to go through the Specifications, one of the important things is to know the power requirements and the operating power of the servo motor,

As we can observe from the specification that the operating voltage is 4.8V - 6.0 V which sufficient to operate it using the microcontroller,

The second important thing is the pinout so that you know where each pin goes to in the microcontroller, from the datasheet,

there are three main pins in the servo:

The PWM pin: which should be connected to the pwm digital pin in microcontroller,

The VCC: should be connected to the power pin and should be in the range of 4.6V to 6.0V

The GND: this is the ground pin.

The Code

I will be using the example provided by the Arduino to test the servo motor :

#include <Servo.h> is used to call servo Library which allows an Arduino board to control RC (hobby) servo motors.

myservo.attach(pin) syntax is used to declare the pin number the servo motor is attached to.

myservo.write() syntax is used to control the shaft of the motor and set the angle.

Then I compiled and run the code:

Failure

The servo movement was not smooth and the servo stoped after just couple of seconds, due to the fact that I’m working from home I couldn’t troubleshoot to check where the problem is, where I do not have the tools needed, Thanks to Corona /:

Control Servomotor with Arduino

This time I tried the same code with arduino to make sure it is not the servo problem.

Download Files