top of page
Search

Mini Reed switch with Arduino

Magnets around us! arent they? Here is a small post about the reed switch which senses these magnets around us! Rather than letting you read, I am going to show it as a video! watch it ! have fun!


Well, the procedure is very simple, all we have to do is get the sensor and connect it with the Arduino!. The connections are

VCC - 5V

GND - GND (of course)

Data - 2


Connect and run the setup using the code below!




int led = 13; // LED pin

int reed = 2; // The sensor data pin is connected to the digital pin no.2 of arduino

int state; // A variable to store the state of the switch


void setup()

{

pinMode (led, OUTPUT);

pinMode (reed, INPUT);

Serial.begin(9600);

}


void loop()

{

state = digitalRead(reed); // read the value and assign it to state

if (state == HIGH) //LED glows when magnetic field is detected

{

digitalWrite(led, HIGH);

Serial.print('\n');

Serial.print(digitalRead(reed));

}

else

{

digitalWrite(led, LOW);

Serial.print('\n');

Serial.print(digitalRead(reed));

}

delay(500);

}




15 views0 comments

Recent Posts

See All

Comentarios


Post: Blog2_Post
bottom of page