Skip to content

Instantly share code, notes, and snippets.

@elktros
Created July 28, 2018 06:10
Code toggling a Relay with the help of Hall Effect IC and Arduino.
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