Page 1 of 1
Forum

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 most likely no translated for the post!





Line Follower - Mot...
 
Share:
Notifications
Clear all

Line Follower - Motors not working


(@gabi420)
New Member
Joined: 4 months ago
Posts: 2
Topic starter  

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 :)


ReplyQuote
Topic Tags
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1758
 

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 😊 


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1758
 

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.


ReplyQuote
(@gabi420)
New Member
Joined: 4 months ago
Posts: 2
Topic starter  

@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


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1758
 

Cooool! 😊 


ReplyQuote



Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: