hi all, i am newbie.
I'm learning how to make a robot, and this time I have a problem to make my robot move .
How to control servo with magnetic sensor??
#include <Servo.h>
Servo servo;
const int pinmagnet =13; // magnet pin
const int pinservo = 9 ; // servo pin
int right = 180; // servo move 180 degrees
int left = 0; // servo move 0 degrees
int magnetvalue = 0 ;
void setup (){
pinMode ( pinservo, OUTPUT);
pinMode ( pinmagnet, INPUT);
Serial.begin(9600);
}
void loop ()
{
magnetvalue= analogRead(pinmagnet);
if ( magnetvalue >= 180 )
{
servo.write (right);
}
else {
servo.write(left);
}
}
when magnetic sensor work, servo will move 180 degrees, and when magnetic sensor not work , servo will move to 0 degrees..
please help me..