So i’ve been messing around with my arduino and i’ve been trying to do something simple that will better help me understand to to eventually build the robot i want to build.
Right I have the Sharp GP2D120 mounted to a servo, in the program i thought i had it set so that the sharp would take a reading and then either turn the servo it is mounted on in one direction or another based on the reading. However no matter what i do it just goes back and forth between center and the side it’s supposed to go to when the reading wasn’t close enough.
Here is the code i used. Any help would be greatly appreciated.
#define IR 0
int distance = 0;
if (IR <= 18)
ps i realize that this is probably completely wrong, but it’s my first time. Be gentle