gidump
Published

Controlling_180°Motor

This project lets you control a 180° servo motor with a joystick and a potentiometer, is it useful by itself? No, but that's not my problem.

BeginnerProtip202
Controlling_180°Motor

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
You can use any controller board.
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Modulo Joystick
Modulo Joystick
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Story

Read more

Schematics

I just realized my circuit images are horrible.

In this circuit I show you the potentiometer version, you can replace it with the joystick just by connecting the red wire to 5v, the blue one to GND and the green one to the x or y axys pin; you could also use both the joystick and the potentiometer at the same time by connecting them both to A0.

Code

DaCode

C/C++
The map function converts 0-1023 to 0-180 because the joystick/potentiometer can input a value from 0 to 1023 while the motor can move from 0 to 180 degrees.
#include <Servo.h>
Servo s1;
int servalue;
int pot=A0;

void setup ()
{
s1.attach(9);
}


void loop()
{
servalue=analogRead(pot);
servalue= map(servalue, 0, 1023, 0, 180);
s1.write(servalue);
delay(15);
}

Credits

gidump
0 projects • 0 followers

Comments