Create Arduino projects with your students.

Potentiometers and servo motors

Potentiometers and servo motors
Potentiometers and servo motors. Arduino scheme

Hardware required

  • Arduino Board
  • Potentiometers
  • servo motor
  • Breadboard
  • Jumper wires

Theoretical concepts

A potentiometer is basically a resistor which can change its value. It is an element that has always been widely used in electronics.
Surely if you open an old radio you will find a potentiometer.

A servo motor is a special motor in which the rotation position can be controlled unlike a normal motor. These motors are special and highly appreciated in electronics for circuits where precision is needed.
Servo motors are very common in 3D printers (in these printers they are called stepper).
These motors have integrated electronics to control movement.

Code

#include <Servo.h> // Including the Servo library is mandatory

Servo Myservo;  // this will be our servo object.

int valor; // This variable will define the position of the servo

void setup() {

Myservo.attach(9);// We define the signal pin for the servo

}
void loop() {
valor = analogRead(A0); // leemos el valor del potenciometro (valor entre 0 y 1023)
if (valor <= 330){
Myservo.write(0);
}
if (valor > 300 && valor < 700){
Myservo.write(90);
}
if (valor>700){
Myservo.write(180);
}
/*
If the potentiometer value is in between 0 – 330 we’ll set to  0
if between 330 and 700 it will turn 90 degrees
if it is above 700 it will turn 180 degrees
*/
delay(10);  // waiting to start the loop again
}

 

 

The Demeter Project