Devices & Components
Arduino Uno Rev3
Relay (generic)
Resistor 10k ohm
hall sensor
Hardware & Tools
solenoid valve
electric motor
hydrolic pump
Project description
Code
magnetic_switch.ino
arduino
1const int hall1Pin = 7; // the number of the hall effect sensor pin 2const int ledPin1 = 2; // the number of the LED pin 3const int hall2Pin = 10; 4const int ledPin2 = 4; 5int hall1State = 0; 6int hall2State = 0; // variable for reading the hall sensor status 7 8void setup() { 9 // initialize the LED pin as an output: 10 pinMode(ledPin1, OUTPUT); 11 pinMode(ledPin2, OUTPUT); 12 // initialize the hall effect sensor pin as an input: 13 pinMode(hall1Pin, INPUT); 14 pinMode(hall2Pin, INPUT); 15} 16 17void loop(){ 18 // read the state of the hall effect sensor: 19 hall1State == digitalRead(hall1Pin); 20 21 if (hall1State = HIGH) { 22 // turn LED on: 23 digitalWrite(ledPin1,LOW); 24 25 } 26 27 else { 28 // turn LED off: 29 digitalWrite(ledPin1, HIGH); 30 } 31 32 33 34 hall2State = digitalRead(hall2Pin); 35 36 if (hall2State == HIGH) { 37 // turn LED on: 38 digitalWrite(ledPin2,LOW); 39 } 40 else { 41 // turn LED off: 42 digitalWrite(ledPin2, HIGH); 43 } 44} 45 46
Downloadable files
untitled
untitled

untitled
untitled

Comments
Only logged in users can leave comments