А не хотите рассказать немного о машинке, показать ее фотку, код? Можете даже объяснить, в чем проявляется нестабильность.
Попробую сеанс телепатии. Одной из причин нестабильного поведения электрического устройства может быть плохой контакт, приводящий к периодическому разрыванию цепи в результате механических воздействий различного характера (вибрация, температурное расширение, ускорения при изменении вектора движения). Потому можно для начала проверить надежность всех соединений, особенно легко разъединяемых.
Дорогие коллеги, извините за мою краткость и спасибо за отзывчивость!!!Моя машинка должна ехать из одной комнаты в другую, для этого она должна через определенное расстояние поворачивать на 90 градусов. Дело в том, что в каждом цикле он поворачивает то на нужный угол, то слишком сильно, то слишком слабо. Все время мне приходится изменять в цикле время, заданное на поворот. для моторов я использовала 2 motor shield l98n
int IN3 = 5; // Input3 подключен к выводу 5 int IN4 = 4; int IN2 = 6; int IN1 = 7; int IN1a = 2; int IN2a = 3; int IN3a = 8; int IN4a = 9; int ENB = 11; int ENBa = 13; int ENA = 10; int ENAa = 12; boolean buttonPin = 1; boolean lastButton = LOW; boolean currentButton = LOW; int i; void setup() { pinMode(ENA, OUTPUT); pinMode(ENB, OUTPUT); pinMode (buttonPin,INPUT); pinMode (IN4, OUTPUT); pinMode (IN3, OUTPUT); pinMode (IN2, OUTPUT); pinMode (IN1, OUTPUT); pinMode (IN1a,OUTPUT); pinMode (IN2a,OUTPUT); pinMode (IN3a,OUTPUT); pinMode (IN4a,OUTPUT); } boolean debounce(boolean last) { boolean current = digitalRead(buttonPin); if (last != current) { delay (100); current = digitalRead(buttonPin); } return current; } void loop () { currentButton = debounce(lastButton); if (currentButton == HIGH && lastButton == LOW) { digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3,HIGH); digitalWrite (IN4,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); } delay(1270); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN3, LOW); digitalWrite (IN1, LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); digitalWrite (IN4, LOW);//первый поворот digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,HIGH); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(1345); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN4, LOW); digitalWrite (IN3, LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,LOW); delay (2000); digitalWrite (IN4, LOW); digitalWrite (IN3, HIGH); digitalWrite (IN1,HIGH); digitalWrite (IN2,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(2285); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN3, LOW); digitalWrite (IN1, LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); digitalWrite (IN4, LOW);//второй поворот digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,HIGH); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(1468); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN3, LOW); digitalWrite (IN1, LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3,HIGH); digitalWrite (IN4,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); } delay(3400); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN3, LOW); digitalWrite (IN1, LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); digitalWrite (IN4, LOW);//третий поворот digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,HIGH); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(1342); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN3, LOW); digitalWrite (IN1, LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3,HIGH); digitalWrite (IN4,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); } delay(1550); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN4, LOW); digitalWrite (IN3, LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,LOW); delay(5000); digitalWrite (IN4, LOW);//обратно digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,HIGH); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(2158); digitalWrite (IN1a,LOW); digitalWrite (IN4a,LOW); delay(2000); digitalWrite (IN1a,LOW); digitalWrite (IN4a,LOW); digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3,HIGH); digitalWrite (IN4,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); } delay(1580); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN4, LOW); digitalWrite (IN3, LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,LOW); delay(2000); digitalWrite (IN4, LOW);//первый поворот1 digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,HIGH); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(1557); analogWrite(ENA,0); analogWrite(ENB,0); analogWrite(ENAa,0); analogWrite (ENBa,0); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); delay(2000); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3,HIGH); digitalWrite (IN4,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); } delay(3430); analogWrite(ENA,0); analogWrite(ENB,0); analogWrite(ENAa,0); analogWrite (ENBa,0); digitalWrite (IN1,LOW); digitalWrite (IN3,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); digitalWrite (IN4, LOW);//второй поворот 1 digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,HIGH); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(1590); analogWrite(ENA,0); analogWrite(ENB,0); analogWrite(ENAa,0); analogWrite (ENBa,0); digitalWrite (IN1a,LOW); digitalWrite (IN4a,LOW); delay(2000); digitalWrite (IN4, LOW); digitalWrite (IN3, HIGH); digitalWrite (IN1,HIGH); digitalWrite (IN2,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(2220); analogWrite(ENA,0); analogWrite(ENB,0); analogWrite(ENAa,0); analogWrite (ENBa,0); digitalWrite (IN1,LOW); digitalWrite (IN3,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); digitalWrite (IN4, LOW);//третий поворот1 digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,HIGH); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(1558); digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3,HIGH); digitalWrite (IN4,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); } delay(1230); analogWrite(ENA,0); analogWrite(ENB,0); analogWrite(ENAa,0); analogWrite (ENBa,0); digitalWrite (IN1,LOW); digitalWrite (IN3,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); } else { digitalWrite (IN4, LOW); digitalWrite (IN3, LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,LOW); } currentButton = lastButton; }