So I'm working on interfacing the sensor with the servo so that when a magnet is presented to the sensor it turn the servo and subsequently opens a door. Easy enough. However I keep getting an "expected declaration before '}' token" error. Not sure why. Here's code:
#include <Servo.h>
int inPin = 0; // select the input pin for the Hall Effect Sensor
int servoPin = 2; // select the output pin for the Servo
int val = 0; // variable to store the value coming from the sensor
int mean = 514; // Value coming from Hall sensor when no mag introduced
int sensitivity = 1;
int minPulse = 600; // minimum servo position
int maxPulse = 2400; // maximum servo position
int turnRate = 100; // servo turn rate increment (larger value, faster rate)
int refreshTime = 20; // time (ms) between pulses (50Hz)
int centerServo; // center servo position
int pulseWidth; // servo pulse width
long lastPulse = 0;
void setup() {
pinMode(servoPin, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(inPin, INPUT);
centerServo = maxPulse - ((maxPulse - minPulse)/2);
pulseWidth = centerServo;
}
void loop() {
val = analogRead(inPin); // read the Hall Effect Sensor
if (val == mean){
pulseWidth = centerServo;// If no signal from Hall Sensor, center the servo
}
if (val >= (mean + sensitivity) || val <= (mean - sensitivity)) {
pulseWidth = pulseWidth + turnRate;
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // start the pulse
delayMicroseconds(pulseWidth); // pulse width
digitalWrite(servoPin, LOW); // stop the pulse
lastPulse = millis(); // save the time of the last pulse
}
}
}
}
Thanks.