Devices & Components
Arduino Uno Rev3
Breadboard (generic)
SG90 Micro-servo motor
Rotary potentiometer (generic)
Jumper wires (generic)
Software & Tools
Arduino IDE
Project description
Code
Code
arduino
Look here for the code!
1#include <Servo.h> //library for controlling a servo 2const byte potMeter=A3; //potentiometer attached to analog port A3 3int potMeterValue=0; 4byte rotation=0; 5Servo myServo; //name your servo 6 7void setup() { 8 myServo.attach(2); //servo attached to digital port 2 9 pinMode(potMeter,INPUT); //potentiometer is an input=>it sends information to the computer 10 Serial.begin(9600); //start serial communication at 9600 baud 11} 12 13void loop() { 14 potMeterValue=analogRead(potMeter); 15 rotation=map(potMeterValue,0,1023,0,180); 16 myServo.write(rotation); 17 delay(1000); //you can delete the delay, but on the serial monitor there will be too much information 18 Serial.print("Potmetervalue: "); 19 Serial.print(potMeterValue); 20 Serial.print("\ "); 21 Serial.print("rotation: "); 22 Serial.println(rotation); 23 Serial.println(); 24} 25
Downloadable files
Schematic
This is how to connect all the components to the arduino or genuino UNO board
Schematic
Schematic
This is how to connect all the components to the arduino or genuino UNO board
Schematic
Comments
Only logged in users can leave comments