Go Down

### Topic: Using hall effect sensor to calculate the rpm of 2 continuous servos (Read 430 times)previous topic - next topic

#### gaminyx ##### Apr 22, 2017, 11:28 pm
Hi everyone,

I have a question for using Hall Effect sensor to calculate the rpm of 2 continuous servos. The purpose of doing it is collect the data of rpm to match the speed of servos in a very close range. We have a basic setting and have detected the threshold value when the magnet is close to the sensor.

Here in the attached file is our circuit board and basic setup of the code.
Thank you so much for your time!

"
#include <Servo.h>
const int sensorPin = A0;    // pin that the sensor is attached to
const int servoPin = 9;        // pin that the Servo is attached to
const int sensorPin1 = A1;    // pin that the sensor is attached to
const int servoPin1 = 10;
// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
int sensorValue1 = 0;         // the sensor value
int sensorMin1 = 1023;        // minimum sensor value
int sensorMax1 = 0;
//Create Servo object
Servo myServo;
Servo myServo1;

void setup() {

Serial.begin(9600);

myServo.attach(servoPin);
myServo.write(95);

myServo1.attach(servoPin1);
myServo1.write(85);

while (millis() < 4000)
{

if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}

// record the minimum sensor value
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}

if (sensorValue1 > sensorMax1) {
sensorMax1 = sensorValue1;
}

if (sensorValue1 < sensorMin1) {
sensorMin1 = sensorValue1;
}
}

myServo.write(90);
myServo1.write(90);
delay(2000);

}

void loop() {

myServo.write(95);
myServo1.write(85);

if (sensorValue <= sensorMin+30&& sensorValue >= sensorMin-10 )
{
myServo.write(90);
delay(3000);

myServo.write(95);

}

if (sensorValue1 <= sensorMin1+30&& sensorValue1 >= sensorMin1-10 )
{
myServo.write(90);
myServo1.write(90);
delay(2000);
}

} #1
##### Apr 23, 2017, 07:41 am

Do not cross-post.  Other thread removed. 