# How do you make an Arduino controlled vehicle move towards a magnetic object?

Hi I'm sort of new to programming and I have created a program for the movement of my vehicle and I have used the basic "magsensor" program by Adafruit to detect magnetic objects. However, the measurements taken by the magnetometer read in 3 axis (x, y, & z). So how exactly do I make the vehicle move towards the object? Like I understand I need to add an "if" clause but I don't exactly know what to put in there. The vehicle also uses a twin DC motor.

Any help would be greatly appreciated.

Not much of an Engg dude if you can't figure out that we need to know something about the sensor you are using, and the code you are running.

TheEnggDude:
However, the measurements taken by the magnetometer read in 3 axis (x, y, & z). So how exactly do I make the vehicle move towards the object?

How about writing a short program that prints the 3 values on the Serial Monitor and then move the magnet around and see how the values change?

...R

Robin2:
However, the measurements taken by the magnetometer read in 3 axis (x, y, & z).

The measurements are relative to? And they are direction or coordinates?

TheEnggDude:
Hi I’m sort of new to programming and I have created a program for the movement of my vehicle and I have used the basic “magsensor” program by Adafruit to detect magnetic objects. However, the measurements taken by the magnetometer read in 3 axis (x, y, & z). So how exactly do I make the vehicle move towards the object? Like I understand I need to add an “if” clause but I don’t exactly know what to put in there. The vehicle also uses a twin DC motor.

Any help would be greatly appreciated.

The magnetic field vector that the magnetometer measures doesn’t tell you anything about where the
magnet is, nor how far away. It cannot, it merely senses the local field.

The way to seek the magnet is to move and observe the field changing as you move. If the field gets
stronger (ie the vector magnitude gets larger) then you are getting closer. If it decreases try the opposite
direction. If it stays roughly constant, try a 90 degree turn…

Forget the if clause thing, you need to understand conceptually how to locate the magnet, and you need to
understand how to program the movement of the vehicle, and should that involve if-clauses I wouldn’t be
at all surprized, but you don’t start off thinking “what if clause do I need?”, that’s detail inside a subtask of
a subtask. Think about “what routines do I need and what shall I call them so their function is obvious?”