Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Line Follower - Motors not working
(@gabi420)
New Member
Joined: 4 years ago
Posts: 2
Topic starter
October 19, 2020 2:05 AM
I have a line follower and the motors are not working. I have recived this robot for getting top 500 in a contest and I need to code it, already built. The whole robot lights up but the motors wouldn't move.I am sure the motors work as I have tested them so it must be wiring or code. Here is the code (senzorDreapta= sensorRight; senzorStanga=sensorLeft; stare=state; inceput= begin/start; inainte=forward; inapoi=backwards;)
volatile byte inceput;
volatile byte inainte;
volatile byte inapoi;
volatile int stare;
volatile int senzorStanga;
volatile int senzorDreapta;
void setup(){
inceput = 254;
inainte = 240;
inapoi = 186;
stare = 0;
senzorStanga = 0;
senzorDreapta = 0;
pinMode(3, INPUT);
pinMode(9, INPUT);
Serial.begin(9600);
}
void loop(){
senzorStanga = digitalRead(3);
senzorDreapta = digitalRead(9);
if (senzorStanga == 1) {
if (senzorDreapta == 1) {
stare = 0;
} else {
stare = 1;
}
} else if (senzorDreapta == 1) {
stare = -1;
}
switch (stare) {
case -1:
Serial.write(inceput);
Serial.write(1);
Serial.write(inainte);
Serial.write(50);
Serial.write(inceput);
Serial.write(2);
Serial.write(inainte);
Serial.write(0);
break;
case 1:
Serial.write(inceput);
Serial.write(1);
Serial.write(inainte);
Serial.write(0);
Serial.write(inceput);
Serial.write(2);
Serial.write(inainte);
Serial.write(50);
break;
default:
Serial.write(inceput);
Serial.write(1);
Serial.write(inainte);
Serial.write(50);
Serial.write(inceput);
Serial.write(2);
Serial.write(inainte);
Serial.write(50);
break;
}
}
Perhaps it's wiring or the code?
I'm not very good at coding so if someone can give me a simple code that just makes him go forward it would be great :)
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
October 19, 2020 3:16 AM
Hi Gabi420,
looking at your code (keep in mind: I have not experimented with motors on the Arduino yet), I do not see any signals going out to the motor.
Also: are you using a stepper motor or a normal motor?
If I look at your loop() function then I only see serial monitor output, but no commands to do something with the motor?
From what I could find here:
A Stepper motor seems to be controlled by pulses like so:
digitalWrite(motorPin, HIGH);
A regular motor like so:
analogWrite(motorPin, speed);
(again: not an expert on motors with the Arduino)
Hope this helps 😊
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
October 19, 2020 3:19 AM
Note: I also see you declared the variables as "volatile" - I'm not sure if this is needed in your application.
It probably will not do any harm either though.
(@gabi420)
New Member
Joined: 4 years ago
Posts: 2
Topic starter
October 19, 2020 5:58 AM
@hans
Thanks for the help,will consider! Also it's not a stepping motor,here is a photo of the robot:
https://imgur.com/rrZMfts
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796