Created
July 28, 2018 06:10
Code toggling a Relay with the help of Hall Effect IC and Arduino.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int relayPin = 10; | |
const int hallPin = 2; | |
int hallVal = 0; | |
int relayToggle = LOW; | |
int previousState = HIGH; | |
void setup () | |
{ | |
pinMode (relayPin, OUTPUT); | |
pinMode (hallPin, INPUT); | |
} | |
void loop () | |
{ | |
hallVal = digitalRead(hallPin); | |
if (hallVal == LOW && previousState==HIGH) | |
{ | |
relayToggle=!relayToggle; | |
digitalWrite (relayPin, relayToggle); | |
} | |
previousState=hallVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment