NoTech:
Good news is i got the Hall Effect sensor to light up and acknowledge the magnetic field i waved past it but not a lot of movement on the servo hopefully the pictures are of some help to my dilemma
I looked at the pics above and conclude that the range of visor motion is perhaps ~ 60 deg. I also re-looked at the code and found a couple of mistakes. So I've corrected them and accounted for the Hall sensor and this version is now what you should try.
#include <Servo.h> //Library to be used for servo
//declare the constants to be used
const int LEDPIN = 13; //pin attached to led
const int servoPIN = 3; //Servo control line (orange) to be connected to this pin
const int sensorPIN = 2; //input from Hall effect sensor
const int posOpenCMD = 45; //command in deg to servo to open the visor
const int posCloseCMD = 15; //command in deg to servo to close the visor
const unsigned long slowDlay = 100; //delay btw 1 degree steps in position commands
//declare the variables used
boolean visorOPEN = true; //desired door state set to open
int posCMD; //servo position command in degrees
int halfWayCMD; //a position halfway btw open and closed
Servo myServo; //create a servo object
void setup() {
//set the pins to be ins or outs
pinMode(LEDPIN, OUTPUT);
digitalWrite(LEDPIN, LOW); //turn LED off
pinMode(servoPIN, OUTPUT);
pinMode(sensorPIN, INPUT);
myServo.attach(servoPIN); //Tell the servo library which pin to use
//compute a position halfway btw open and closed
halfWayCMD = abs(posOpenCMD - posCloseCMD) / 2 + min(posOpenCMD, posCloseCMD);
digitalWrite(LEDPIN, HIGH); //turn LED on when visor is in motion
//now send the visor to it's open position, slowly, starting from halfway
for (posCMD = halfWayCMD; posCMD < posOpenCMD; posCMD += 1) //goes from halfway to open
{
myServo.write(posCMD); //tell servo to go to position in variable 'posCMD'
delay(max(20, slowDlay)); //waits some ms for the servo to reach the position
}
digitalWrite(LEDPIN, LOW); //turn LED off
}
void loop() {
//read the switch if the door is not moving
if (digitalRead(sensorPIN) == LOW) { //see if magnet is being detected
digitalWrite(LEDPIN, HIGH); //turn LED on to indicate motion
//now compute servo command based on desired door state
if (visorOPEN == true) {
//visor is starting from open postion so close it, 1 deg at a time
for (posCMD = posOpenCMD; posCMD > posCloseCMD; posCMD -= 1) // goes from open to closed
{
myServo.write(posCMD); //tell servo to go to position in variable 'posCMD'
delay(max(20, slowDlay)); //waits min of 20 ms for the servo to go 1 degree
}
} else {
//visor is starting from closed postion so open it, 1 deg at a time
for (posCMD = posCloseCMD; posCMD < posOpenCMD; posCMD += 1) //goes from open to closed
{
myServo.write(posCMD); //tell servo to go to position in variable 'posCMD'
delay(max(20, slowDlay)); //waits some ms for the servo to reach the position
}
}
}
//motion is now completed
digitalWrite(LEDPIN, LOW); //turn LED off
visorOPEN = ~visorOPEN; //reverse visor state when motion is done
}
Meanwhile let me answer some questions. The final position commands, for open and close, are contained in these to constants.
const int posOpenCMD = 45; //command in deg to servo to open the visor
const int posCloseCMD = 15; //command in deg to servo to close the visor
My assumption in the above is that a fully closed position is 0 deg and a fully open one is ~60 deg. So I set them a bit inside of any hard mechanical stops so as to avoid hitting said stops and breaking something. IF I’ve got the “polarity” of open/close correct, I would advise you to increase one constant and then decrease the other until you’ve got the visor moving to fully open and to fully closed. Even better would be to disconnect the visor from the servo arm and verify it moves in the correct direction and at about to the right places before doing the above. Note that after power on or reset and before detecting any magnet, the visor is commanded to the open position. It should sit there until the Hall sensor indicates a magnet is present.
If I’ve got the “polarity” reversed then some changes will need to happen. You’ll need to change the constants and then the >, < and the -= and += in the for() loops. But first let’s see what happens w/the corrected code above. Alas I don’t know of anyway to tell you what the servo positions or polarity should be, other than by test.