Lesson 17: RoboJax Arduino Step-by-Step Course: NJk-5002C Hall Proximity Sensor
This is the Arduino code to use the NJK-5002C Hall proximity sensor to control a DC or AC load.552-Lesson 17, Robojax Arduino Step-by-Step Course: NJK-5002C Hall proximity sensor
语言: C++
/*
* Robojax Arduino Step-by-Step Course
* Lesson 17: NJK-5002C hall proximity sensor
* This is the Arduino code to use the NJK-5002C hall sensor to control a DC or AC load.
Please watch video instructions here: https://youtu.be/AGXJKU2mHsE
This code is available at: http://robojax.com/course1/?vid=lecture11
With over 100 lectures free on YouTube! Watch it here: http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339
* Written by Ahmad Shamshiri for Robojax, www.Robojax.com
* Date: November 10, 2018, 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 downloaded from Robojax.com
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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 <https://www.gnu.org/licenses/>.
*/
#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 http://robojax.com/L/?id=338
pinMode(sensorPin, INPUT_PULLUP);// define pin as input for sensor
// watch video explaining the INPUT_PULLUP
//Robojax Arduino Step-by-Step Course http://robojax.com/L/?id=338
pinMode(relayPin, OUTPUT);// define pin as output
Serial.begin(9600);// initialize serial monitor with 9600 baud.
}
void loop() {
//Robojax Arduino Step-by-Step Course http://robojax.com/L/?id=338
int sensed = digitalRead(sensorPin);// read pin 2 and put the result in the "sensed" variable
if(sensed == LOW){
Serial.println("Sensed");
digitalWrite(relayPin, LOW);// if sensed turn relay ON
delay(wait);// keep the relay ON for the "wait" amount of time
}else{
digitalWrite(relayPin, HIGH);// else turn the relay OFF
Serial.println("====");
}
delay(300);// delay for 0.3 seconds
//Robojax Arduino Step-by-Step Course http://robojax.com/L/?id=338
}
资源与参考
尚无可用资源。
文件📁
没有可用的文件。