SURYATEJA
Published © Apache-2.0

Amazing Games Using Hall Effect Sensors

There are many things you can doo with a Hall sensor and magnetism.

BeginnerFull instructions provided4 hours12,484
Amazing Games Using Hall Effect Sensors

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Hall Effect Sensor
Hall Effect Sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

CONTROLLING VIA HALL EFFECT SENSOR

Schematics

CONTROLLING VIA HALL EFFECT SENSOR

Code

CODE-1- FOR CONTROLLING A MOTOR

Arduino
int potPin = A0;
int motorPin = 9;
int potValue = 0;
int motorValue = 0;
void setup() {
 Serial.begin(9600);
}
void loop() {
 potValue = analogRead(potPin);  
 motorValue = map(potValue, 0, 1023, 0, 255);
 analogWrite(motorPin, motorValue);  
 Serial.print("potentiometer = " );     
 Serial.print(potValue);
 Serial.print("\t motor = ");
 Serial.println(motorValue);
 delay(2);    
}

CODE-2- FOR INTERACTIVE CAR

Arduino
const int hallPin = 12;
const int hallPin2 = 13;
const int hallPin3 = 11;
const int hallPin4 = 10;// the number of the hall effect sensor pin
const int ledPin =  9; 
const int ledPin2 = 6;
const int ledPin3 = 5;
const int ledPin4 = 3;// the number of the LED pin
// variables will change:
int hallState = 0; 
// variable for reading the hall sensor status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  // initialize the hall effect sensor pin as an input:
  pinMode(hallPin, INPUT);
  pinMode(hallPin2, INPUT);
  pinMode(hallPin3, INPUT);
  pinMode(hallPin4, INPUT);
}

void loop(){
  // read the state of the hall effect sensor:
  hallState = digitalRead(hallPin);

  if (hallState == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
  if (digitalRead(hallPin2) == LOW) {
    digitalWrite(ledPin2, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin2, LOW);
  }
    if (digitalRead(hallPin3) == LOW) {
    digitalWrite(ledPin3, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin3, LOW);
  }
    if (digitalRead(hallPin4) == LOW) {
    digitalWrite(ledPin4, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin4, LOW);
  } 
  
}

CODE-3- FOR SPINNING WHEEL

Arduino
int potPin = A0;
int motorPin = 9;
int potValue = 0;
int motorValue = 0;
const int hallPin = 12;     // the number of the hall effect sensor pin
const int ledPin =  13;     // the number of the LED pin
// variables will change:
int hallState = 0;          // variable for reading the hall sensor status

void setup() {
 Serial.begin(9600);
  pinMode(ledPin, OUTPUT);      
  // initialize the hall effect sensor pin as an input:
  pinMode(hallPin, INPUT); 
}
void loop() {
 potValue = analogRead(potPin);  
 motorValue = map(potValue, 0, 1023, 0, 255);
 analogWrite(motorPin, motorValue);  
 Serial.print("potentiometer = " );     
 Serial.print(potValue);
 Serial.print("\t motor = ");
 Serial.println(motorValue);
 delay(2);
  hallState = digitalRead(hallPin);

  if (hallState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, LOW);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, HIGH); 
 
}
}

CODE-4- FOR HOURGLASS BLINK

Arduino
const int hallPin = 12;
const int hallPin2 = 13;
const int hallPin3 = 11;

const int ledPin =  9; 
const int ledPin2 = 6;
const int ledPin3 = 5;

// variables will change:
int hallState = 0; 
// variable for reading the hall sensor status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);

  // initialize the hall effect sensor pin as an input:
  pinMode(hallPin, INPUT);
  pinMode(hallPin2, INPUT);
  pinMode(hallPin3, INPUT);

}

void loop(){
  // read the state of the hall effect sensor:
  hallState = digitalRead(hallPin);

  if (hallState == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
  if (digitalRead(hallPin2) == LOW) {
    digitalWrite(ledPin2, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin2, LOW);
  }
    if (digitalRead(hallPin3) == LOW) {
    digitalWrite(ledPin3, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin3, LOW);
  }
   
  
}

Credits

SURYATEJA

SURYATEJA

18 projects • 59 followers

Comments