Project tutorial

The Magnetic Field and RGB Tester © GPL3+

Observe the magnetic field integrity and polarity in the air with the 3144E Hall effect sensor. Also, adjust the RGB LED colours easily.

  • 2,494 views
  • 0 comments
  • 11 respects

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)
09507 01
Soldering iron (generic)

Apps and online services

About this project

Description

I have needed a device to detect the magnetic field in the air when I was working with the magnets and DC motors so I created a basic device which shows the magnetic field integrity and the polarity in the air with the 3144 Hall Effect Sensor. After that, I decided to add an RGB LED test system into the project because I had been getting bored with setting up the circuit for Arduino every time.

The Magnetic Field Integrity and Polarity Test

Sometimes you might want to detect the polarity of the magnet or sometimes you might want to know whether your DC motor works or not without making a circuit for it. And you must have a device that can detect the magnetic field integrity and polarity for the jobs like these.

The Magnetic Field and RGB Tester which is a basic magnetic field detector allows you to make all these jobs basically.

By clicking the second button, the magnetic field integrity is revealed as a pointer and the polarity can be detected by observing the movements of the pointer.

RGB LED Test

Three different potentiometers so you can adjust each LED in an RGB (Red, Green, Blue) which allows you to test your RGB LED easily.

Also, you can see the results on LCD screen when you adjust the number from 0 to 255 by clicking the first button. Moreover, you can use the device as an RGB picker and create special colours.

It is the easiest way to test an RGB LED.

Connections:

Arduino UNO----------------------LCD Screen

  • Pin 2 ------------------------- rs
  • Pin 3 ------------------------- en
  • Pin 4 ------------------------- d4
  • Pin 5 ------------------------- d5
  • Pin 6 ------------------------- d6
  • Pin 7 ------------------------- d7
  • Pin 8 ------------------------- Buzzer

Arduino UNO-----------------------RGB

  • Pin 9 -------------------------
  • Pin 10 -------------------------
  • Pin 11 -------------------------
  • Pin 12 ------------------------- Button(1)
  • Pin 13 ------------------------- Button(2)
  • Pin A1 ------------------------- Potentiometer(1)
  • Pin A2 ------------------------- Potentiometer(2)
  • Pin A3 ------------------------- Potentiometer(3)
  • Pin A4 ------------------------- 3144E Hall Effect Sensor
  • After making all the connections correctly, I stuck the Arduino Uno to the top of the first breadboard with a silicon gun and connected an old single turn potentiometer to the LCD screen by using a soldering iron.

Schematics

Fritzing Diagram
The magnetic field and rgb tester bb ayqy2wglot

Code

TheMagneticFieldAndRGBTester.inoArduino
    /////////////////////////////////
   // The Magnetic Field and RGB  //
  //           Tester            //
 //       by Kutluhan Aktar     //
/////////////////////////////////



// You can observe the magnetic field in the air with the project easily.
// Thus, the project allows you to adjust and test RGB Led.
//
// Connections:
//
// Arduino UNO
//                                 LCD Screen
// Pin 2  -------------------------rs
// Pin 3  -------------------------en
// Pin 4  -------------------------d4
// Pin 5  -------------------------d5
// Pin 6  -------------------------d6
// Pin 7  -------------------------d7
//                                 Buzzer
// Pin 8  -------------------------
//                                 RGB
// Pin 9  -------------------------
// Pin 10 -------------------------
// Pin 11 -------------------------
//                                 Button(1)
// Pin 12 -------------------------
//                                 Button(2)
// Pin 13 -------------------------
//                                 Potentiometer(1)
// Pin A1 -------------------------
//                                 Potentiometer(2)
// Pin A2 -------------------------
//                                 Potentiometer(3)
// Pin A3 -------------------------
//                                 3144E Hall Effect Sensor
// Pin A4 -------------------------



#include <LiquidCrystal.h> // Include the library code:

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7; // Initialize the library by associating any needed LCD interface pin with the arduino pin number it is connected to:
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int Potentiometer1 = A1; // Define the potentiometers' pins to get the value from them.
int Potentiometer2 = A2;
int Potentiometer3 = A3;

int MagneticSensor = A4; // Define the Magnetic Hall Effect Sensor's analog pin.

int redPin = 9;  // PWM pins for the RGB Led.
int greenPin = 10;
int bluePin = 11;

int buzzerPin = 8; // Buzzer pin.


int button = 12; // Buttoms.
int button2 = 13;

int redValue; // Determine the global values to use them in diffrent functions.
int greenValue;
int blueValue;
int Magnetic;
int buttonValue;
int button2Value;

volatile boolean menu1 = false; // Booleans allow you to switch between the tasks permanently.
volatile boolean menu2 = false;

byte mark[8] = { // The characters as bytes( basically (8x5)).
  0b00100,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b01010,
  0b00100,
};
byte magnet[8] = {
  0b11111,
  0b01110,
  0b00100,
  0b01110,
  0b11111,
  0b01110,
  0b00100,
  0b00000,
};
byte empty[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
};


void setup() {

  Serial.begin(9600);

  lcd.begin(16, 2);
  lcd.createChar(1, mark); // Create LCD characters as numbers.
  lcd.createChar(2, magnet);
  lcd.createChar(3, empty);

  lcd.setCursor(0, 0); // The initializing screen.
  lcd.print("TheMagneticField");
  lcd.setCursor(0, 1);
  lcd.print("And RGB Tester!");

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  pinMode(button, INPUT);
  pinMode(button2, INPUT);

}

void loop() {
  readSensor();

  colorChange(redValue, greenValue, blueValue);

  alarmMagnetic();

  if (buttonValue == 1) { // Manage the buttons' tasks.
    lcd.clear();

    menu1 = true;
    menu2 = false;
  }
  else if (button2Value == 1) {
    lcd.clear();

    menu1 = false;
    menu2 = true;
  }

  if (menu1 == true) {
    LCD(1);
  }
  if (menu2 == true) {
    LCD(2);
  }

}

void readSensor() { // Get the data of sensors and define them.
  int Pot1Value = analogRead(Potentiometer1);
  int Pot2Value = analogRead(Potentiometer2);
  int Pot3Value = analogRead(Potentiometer3);

  redValue = map(Pot1Value, 0, 1023, 0, 255);
  greenValue = map(Pot2Value, 0, 1023, 0, 255);
  blueValue = map(Pot3Value, 0, 1023, 0, 255);

  Magnetic = analogRead(MagneticSensor);

  buttonValue = digitalRead(button);
  button2Value = digitalRead(button2);


}

void colorChange(int x, int y, int i) { // Adjust the colour of RGB Led by changing values from 0 to 255.
  x = 255 - x;
  y = 255 - y;
  i = 255 - i;
  analogWrite(redPin, i);
  analogWrite(greenPin, y);
  analogWrite(bluePin, x);
}

void LCD(int i) { // Program the LCD Screen.
  switch (i) {

    case 1:

      lcd.setCursor(0, 0);
      lcd.print("Red:");
      lcd.setCursor(0, 1);
      lcd.println(redValue);
      lcd.setCursor(5, 0);
      lcd.print("Green:");
      lcd.setCursor(5, 1);
      lcd.println(greenValue);
      lcd.setCursor(11, 0);
      lcd.print("Blue:");
      lcd.setCursor(11, 1);
      lcd.println(blueValue);
      break;
    case 2:
      MagneticField();
      break;
  }
}

void MagneticField() { // Observe the magnetic field integrity with LCD Screen.

  lcd.setCursor(0, 0);
  lcd.write(1);
  lcd.setCursor(7, 0);
  lcd.write(1);
  lcd.setCursor(15, 0);
  lcd.write(1);

  lcd.setCursor(0, 1);
  lcd.print("-");
  lcd.setCursor(15, 1);
  lcd.print("+");

  Serial.println(Magnetic); // Test the value of Magnetic Field Sensor
  if (Magnetic > 20 && Magnetic < 320) {
    lcdWrite(1, 1);
    lcdWrite(2, 1);
    lcdWrite(3, 1);
    lcdWrite(4, 1);
    lcdWrite(5, 1);
    lcdWrite(6, 1);
    lcdWrite(7, 1);
    lcdWrite(8, 0);
    lcdWrite(9, 0);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 320 && Magnetic < 360) {
    lcdWrite(1, 0);
    lcdWrite(2, 1);
    lcdWrite(3, 1);
    lcdWrite(4, 1);
    lcdWrite(5, 1);
    lcdWrite(6, 1);
    lcdWrite(7, 1);
    lcdWrite(8, 0);
    lcdWrite(9, 0);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 360 && Magnetic < 380) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 1);
    lcdWrite(4, 1);
    lcdWrite(5, 1);
    lcdWrite(6, 1);
    lcdWrite(7, 1);
    lcdWrite(8, 0);
    lcdWrite(9, 0);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 380 && Magnetic < 400) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 1);
    lcdWrite(5, 1);
    lcdWrite(6, 1);
    lcdWrite(7, 1);
    lcdWrite(8, 0);
    lcdWrite(9, 0);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 400 && Magnetic < 450) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 1);
    lcdWrite(6, 1);
    lcdWrite(7, 1);
    lcdWrite(8, 0);
    lcdWrite(9, 0);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 450 && Magnetic < 490) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 1);
    lcdWrite(7, 1);
    lcdWrite(8, 0);
    lcdWrite(9, 0);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 490 && Magnetic < 519) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 0);
    lcdWrite(7, 1);
    lcdWrite(8, 0);
    lcdWrite(9, 0);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }

  else if (Magnetic > 519 && Magnetic < 520) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 0);
    lcdWrite(7, 1);
    lcdWrite(8, 1);
    lcdWrite(9, 0);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 520 && Magnetic < 530) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 0);
    lcdWrite(7, 1);
    lcdWrite(8, 1);
    lcdWrite(9, 1);
    lcdWrite(10, 0);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 530 && Magnetic < 540) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 0);
    lcdWrite(7, 1);
    lcdWrite(8, 1);
    lcdWrite(9, 1);
    lcdWrite(10, 1);
    lcdWrite(11, 0);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 540 && Magnetic < 590) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 0);
    lcdWrite(7, 1);
    lcdWrite(8, 1);
    lcdWrite(9, 1);
    lcdWrite(10, 1);
    lcdWrite(11, 1);
    lcdWrite(12, 0);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 590 && Magnetic < 620) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 0);
    lcdWrite(7, 1);
    lcdWrite(8, 1);
    lcdWrite(9, 1);
    lcdWrite(10, 1);
    lcdWrite(11, 1);
    lcdWrite(12, 1);
    lcdWrite(13, 0);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 620 && Magnetic < 650) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 0);
    lcdWrite(7, 1);
    lcdWrite(8, 1);
    lcdWrite(9, 1);
    lcdWrite(10, 1);
    lcdWrite(11, 1);
    lcdWrite(12, 1);
    lcdWrite(13, 1);
    lcdWrite(14, 0);
  }
  else if (Magnetic > 620 && Magnetic < 800) {
    lcdWrite(1, 0);
    lcdWrite(2, 0);
    lcdWrite(3, 0);
    lcdWrite(4, 0);
    lcdWrite(5, 0);
    lcdWrite(6, 0);
    lcdWrite(7, 1);
    lcdWrite(8, 1);
    lcdWrite(9, 1);
    lcdWrite(10, 1);
    lcdWrite(11, 1);
    lcdWrite(12, 1);
    lcdWrite(13, 1);
    lcdWrite(14, 1);
  }
}
void lcdWrite(int x, int y) { // Choose to display which character and which column. 
  switch (y) {
    case 0:
      lcd.setCursor(x, 1);
      lcd.write(3);
      break;
    case 1:
      lcd.setCursor(x, 1);
      lcd.write(2);
      break;

  }
}

void alarmMagnetic() { // Make notifications with buzzer.
  if (Magnetic > 650 || Magnetic < 320) {
    tone(buzzerPin, 500);
  }
  else {
    noTone(buzzerPin);
  }
}

Comments

Similar projects you might like

Magic Lamp

by Nekhil ravi

  • 1,087 views
  • 3 comments
  • 12 respects

PuzzleBox

Project tutorial by Arduino

  • 311 views
  • 0 comments
  • 1 respect

Arduino MKR GSM 1400 and DTMF

by Arduino_Genuino

  • 4,087 views
  • 0 comments
  • 9 respects

Love You Pillow

Project tutorial by Arduino

  • 2,672 views
  • 0 comments
  • 5 respects

Arduino Yun Controller

Project showcase by TATCO Inc

  • 209 views
  • 0 comments
  • 3 respects
Add projectSign up / Login