what is a encoder motor

encoder pic



encoder motor



//The sample code for driving one way motor encoder
byte encoder0PinALast;
int duration;//the number of the pulses
boolean Direction;//the rotation direction 
void setup()
  Serial.begin(57600);//Initialize the serial port
  EncoderInit();//Initialize the module
void loop()
  duration = 0;
void EncoderInit()
  Direction = true;//default -> Forward  
  attachInterrupt(0, wheelSpeed, CHANGE);
void wheelSpeed()
  int Lstate = digitalRead(encoder0pinA);
    int val = digitalRead(encoder0pinB);
    if(val == LOW && Direction)
      Direction = false; //Reverse
    else if(val == HIGH && !Direction)
      Direction = true;  //Forward
  encoder0PinALast = Lstate;
  if(!Direction)  duration++;
  else  duration--;







Feedback Loops


New Doc 2018-02-19_1




PID Libary


experiment to make the motor act in conjunction with the rpm.





how could a hall magnetic field sensor be used?

using the hall effect sensor couldn’t be easier, as I’m using a cheaper sensor it is set in a binary configuration, so it is just the case of connecting it to a digital input on the Arduino.

i have set up an experiment to show how it could be used to activate an LED

Arduino Hall Magnetic Sensor Module is a switch that will turn on/off in the presence of a magnetic field.



int led = 13;//LED pin
int sensor = 3; //sensor pin
int val; //numeric variable

void setup()
	pinMode(led, OUTPUT); //set LED pin as output
	pinMode(sensor, INPUT); //set sensor pin as input

void loop()
	val = digitalRead(sensor); //Read the sensor
	if(val == HIGH) //when magnetic field is detected, turn led on
		digitalWrite(Led, HIGH);
		digitalWrite(Led, LOW);


fritzing HMFS

photo HMFS


the next step to this is to attach a set of magnets to a spinning disc and read how many reads per second when put into the serial monitor this can be given a feedback loop to then dictate a set speed. this method is used in encoder motors and some stepper motors.

what is a hall magnetic field sensor?

hall magnetic field sensor or hall effect sensor is a surprisingly common device found in a lot of applications.

the sensor works by having a thin layer of a semiconductor such as indium antimonide, which when placed in proximity to a magnetic source it polarises the semiconductor. this polarisation courses a small voltage difference, a high gain amplifier is used to increase the signal to be read properly.

low-quality high gain amps are most commonly used so a lot of these sensors are viewed ad binary, either on or off. high-quality amps can be used for an analog interface. as of how small these sensors can get and how cheap they are they can be used in quantity to read a digital set of variables.

the most common use cases of these sensors are for motors to calculate its rpm and therefore can be used in tandem with other sensor-motor modules to calculate direction and velocity of the system.