Search Code

Kokamba ya Servo na Potentiomètre mpe LCD1602 na kosalela Arduino

Kokamba ya Servo na Potentiomètre mpe LCD1602 na kosalela Arduino

void setup() {
  lcd.begin(16, 2);
  myservo.attach(9);  // abɔti servo na pin 9 na objet servo
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Robojax Servo Knob");
  delay(2000);
}
void loop() {
  val = analogRead(potpin);            // esengaka motu ya potentiomètre
  angle = map(val, 0, 1023, 0, 180);     // komeka yango mpo na kosalela na servo
  myservo.write(angle);                  // esengaka esika ya servo kolanda na motu oyo esili komekama
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Motu ya Pot.:");
  lcd.setCursor(11, 0);
  lcd.print(val);
  lcd.setCursor(0, 1);
  lcd.print("Angle     :");
  lcd.setCursor(11, 1);
  lcd.print(angle);
  delay(500);
}

Loop oyo esengaka motu ya potentiomètre, akomisi yango na angle oyo ekokani mpo na servo, mpe abongisaka eloko ya LCD na motu ya potentiomètre mpe angle ya servo. delay(500) na suka ya loop epekisaka ete eloko ya LCD ebongisama na lombangu mingi te.

Elakiseli / Nini Okokanela

Ntango okotisa nguya na système, LCD ekolakisa "Robojax Servo Knob" mpo na secondes 2, mpe sima motu ya potentiomètre mpe angle ya servo. Ntango okobalola potentiomètre, angle ya servo ekobongwana kolanda yango, mpe motu ya sika ya potentiomètre ekomonana na LCD. Soki omoni likambo oyo esengeli te, lokola servo kotambola na nzela ya mabe, tala ba connexions ya potentiomètre mpe servo (na vidéo na 10:00).

Images

SG90_servo_motor-1
SG90_servo_motor-1
SG90_servo_motor-0
SG90_servo_motor-0
Arduino wiring for LCD1602 12wires servo and pot
Arduino wiring for LCD1602 12wires servo and pot
97-This is the Arduino code for controlling a servo with a potentiometer and an LCD1602.
Langue: C++
/*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

 modified on 8 November 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob

*/


// May 20, 2018 20:08
// Written by Ahmad S. for Robojax.com at Ajax, Ontario, Canada
// Watch the video for this code at https://youtu.be/DN1LPMSZtNA
// This code is taken from http://robojax.com/learn/arduino


#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


// start of servo settings *******
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int potpin = A0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int angle;    // the angle servo is sent to
// END of servo settings *******

void setup() {
  // Robojax Servo knob with LCD1602 Test 
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
   myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  // Robojax Servo knob with LCD1602 Test  
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Robojax Servo Knob");
    delay(2000);
}

void loop() {
  // Robojax Servo knob with LCD1602 Test 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  angle = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(angle);                  // sets the servo position according to the scaled value
  
    
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Pot. Value:");
  // set the cursor to column 0, line 1
    lcd.setCursor(11, 0);
    lcd.print(val);
  // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
  // print the number of seconds since reset:
    lcd.print("Angle     :");
    lcd.setCursor(11, 1);
    lcd.print(angle);


  delay(500);
  // Robojax Servo knob with LCD1602 Test  
}

Mokili na bisika

Fichiers📁

Aucun fichier disponible.