No title

 


#include <Servo.h>


const int hallPin = A0;   // Hall sensor analog input pin

const int servoPin = 9;   // Servo motor PWM control pin


Servo servoMotor;         // Create a servo object


void setup() {

  servoMotor.attach(servoPin);   // Attach the servo to the specified pin

  Serial.begin(9600);            // Start serial communication

}


void loop() {

  int hallValue = analogRead(hallPin); // Read the analog value from the Hall sensor

  int angle = map(hallValue, 0, 1023, 0, 180); // Map the sensor value to the servo angle range (0-180 degrees)

  servoMotor.write(angle);       // Set the servo position based on the Hall sensor reading

  delay(50);                     // Add a small delay to stabilize the servo

}


Post a Comment

Previous Post Next Post

Contact Form