Back to Arduino Step By Step Course

Lesson 17, Robojax Arduino Step by Step Course: NJK-5002C hall proximity sensor

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy or purchase YouTube premium Here

This is the Arduino code to use NJK-5002C hall proximity sensor to control DC or AC load

 * Robojax Arduino Step By Step Course
 * Lesson 17 NJK-5002C hall proximity sensor
 * This is the Arduino code to use NJK-5002C hall sensor to control  DC or AC load
  Please watch video instruction here
 This code is available at
with over 100 lectures Free On  YouTube Watch it here
Get the code for the course: 

 * Written by Ahmad Shamshiri for Robojax,
 * Date: Nov 10, 2018 on Saturday at 09:34 in Ajax, Ontario, Canada

 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <>.

#define sensorPin  2 // pin 2 
#define relayPin 8 // pin

const int wait = 3000;// after switched ON, wait for this amount of time

void setup() {

  	//Robojax Arduino Step By Step Course
  pinMode(sensorPin, INPUT_PULLUP);// define pin  as input for sensor
  // watch video explaining the INPUT_PULLUP
  	//Robojax Arduino Step By Step Course
  pinMode(relayPin, OUTPUT);// defind pin as output

  Serial.begin(9600);// initialize serial monitor with 9600 baud.

void loop() {
  	//Robojax Arduino Step By Step Course
  int sensed = digitalRead(sensorPin);// read pin 2 and put the result in the "sensed" variable
  if(sensed == LOW){
    digitalWrite(relayPin, LOW);// if sensed turn relay ON
    delay(wait);// keep the relay ON for the "wait" amount of time
    digitalWrite(relayPin, HIGH);// else turn the relay OFF
 delay(300);// delay for 0.3 seconds
  	//Robojax Arduino Step By Step Course


The least I expect from you is to thumb up the video and subscribe to my channel. I appriciate that. .I have spent months making these lectures and writing code. You don't lose anything by subscribging to my channel. Your subscription is stamp of approval to my videos and more people can find them and in it turn it helps me. Thank you

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to and affiliated sites.