I have two DC motors and pots i need to make the second motor stops at the same place of first one
the code I did is as follows
#include <LiquidCrystal.h>
LiquidCrystal lcd(2 , 4 , 5 , 6 , 7 , 8);
// custom degree character
byte degree[8] = {
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
B00000,
};
int lcdrw=3;
const int pot1 = 8;
const int pot2 = 9;
const int pot3 = 10;
const int pot4 = 11;
int tube_deg = 0;
int butfw1 = 22 ;
int butbw1 = 24 ;
int rlyfw1 = 46 ;
int rlybw1 = 48 ;
int rlyfw2 = 50 ;
int rlybw2 = 52 ;
void setup ()
{
pinMode(pot1, INPUT);
pinMode(pot2, INPUT);
pinMode(pot3, INPUT);
pinMode(lcdrw,OUTPUT);
pinMode(butfw1,INPUT);
pinMode(butbw1,INPUT);
pinMode(rlyfw1,OUTPUT);
pinMode(rlybw1,OUTPUT);
pinMode(rlyfw2,OUTPUT);
pinMode(rlybw2,OUTPUT);
digitalWrite (lcdrw,LOW);
lcd.begin(20,4);
lcd.createChar(0,degree);
lcd.setCursor(1,0);
lcd.write("tube:");
lcd.setCursor(10,0);
lcd.write((byte)0);
lcd.setCursor(10,2);
lcd.write("Cm");
lcd.setCursor(10,3);
lcd.write("Cm");
lcd.setCursor(11,0);
lcd.write("DEG");
lcd.setCursor(15,3);
lcd.write("DRS");
lcd.setCursor(2,2);
lcd.write("FID:");
lcd.setCursor(0,3);
lcd.write("Akcir:");
}
void loop()
{
int f =analogRead(pot1);
int r =analogRead(pot2);
int s =analogRead(pot3);
int BS = analogRead(pot4);
long tube_deg = map(f, 500, 530, 0, 90);
long YuksekT = map(r,0,500,0,400);
long YuksekA = map(s,158,750,100,300);
long BS1=map(BS,145,745,100,300);
lcd.setCursor(6,0);
lcd.print(" ");
lcd.setCursor(6,0);
lcd.print(tube_deg,DEC);
lcd.setCursor(6,2);
lcd.print(" ");
lcd.setCursor(6,2);
lcd.print(BS1,DEC);
lcd.setCursor(6,4);
lcd.print(" ");
lcd.setCursor(6,4);
lcd.print(YuksekA);
if ( digitalRead(butfw1) == HIGH)
{
digitalWrite(rlyfw1,HIGH);
}
else if (digitalRead(butfw1) == LOW)
{
digitalWrite (rlyfw1,LOW);
}
if ( digitalRead(butbw1) == HIGH)
{
digitalWrite(rlybw1,HIGH);
}
else if (digitalRead(butbw1) == LOW)
{
digitalWrite(rlybw1,LOW);
}
if ((BS1) < (YuksekA) )
{
digitalWrite(rlyfw2,HIGH);
}
else if ((BS1) > (YuksekA))
{
digitalWrite (rlybw2,HIGH);
}
else {
digitalWrite (rlyfw2,LOW);
digitalWrite (rlybw2,LOW);
}
}
my problem is the motor just going up and down frequently
so it cannot reach the point of first one.
I tried to do average program but it was the same
best regards