Devices & Components
Arduino Nano
Rotary potentiometer (generic)
Jumper wires (generic)
Breadboard (generic)
Modulo Joystick
SG90 Micro-servo motor
Project description
Code
DaCode
c_cpp
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.
1#include <Servo.h> 2Servo s1; 3int servalue; 4int pot=A0; 5 6void setup () 7{ 8s1.attach(9); 9} 10 11 12void loop() 13{ 14servalue=analogRead(pot); 15servalue= map(servalue, 0, 1023, 0, 180); 16s1.write(servalue); 17delay(15); 18}
Downloadable files
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.
I just realized my circuit images are horrible.

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.
I just realized my circuit images are horrible.

Comments
Only logged in users can leave comments