Arduino Full Stack
Ctrlk
  • Preface
  • Part 1 - Introduction
  • Chapter 1. Getting Started with Arduino
  • Chapter 2. Programming Grammar
  • Part 2 - Sensors
  • Chapter 3. LED Sensors
  • Chapter 4. Infrared Sensors
  • Chapter 5. Audio Sensors
  • Chapter 6. Magnetic Sensors
    • 6.1 Hall Magnetic Sensor
    • 6.2 Mini Reed
    • 6.3 Linear Hall Magnetic Sensor
    • 6.4 Reed
    • 6.5 Analog Hall
  • Chapter 7. Touch Sensors
  • Chapter 8. Thermist Sensors
  • Chapter 9. Switches
  • Chapter 10. Other Sensors
  • Chapter 11. More Discussions on Sensors
  • Part 3 - Motors
  • Chapter 12. Motors
  • Part 4 - Display
  • Chapter 13. Display
  • Part 5 - Communication
  • Chapter 14. Communication
  • Part 6 - Arduino Based Mini Automated Vehicle
  • Chapter 15. Assemble a Mini Automated Vehicle
  • Chapter 16. Remote Control
Powered by GitBook
On this page
  1. Chapter 6. Magnetic Sensors

6.4 Reed

Hardware Wiring

Reed

Sketch

The code can be found at Examples_Arduino - sensor-kit-for-arduino - _022_Reed - _022_Reed.ino.

Previous6.3 Linear Hall Magnetic SensorNext6.5 Analog Hall

Last updated 7 years ago

  • Hardware Wiring
  • Sketch
int Led=13;      // Define LDE Pin
int buttonpin=3; // Define reed sensor's pin
int val;         // Define Variable val
void setup()
{
  pinMode(Led,OUTPUT);  // Define LED as output
  pinMode(buttonpin,INPUT); // Define reed sensor's pin as output
}
void loop()
{
  val=digitalRead(buttonpin); // assign digital pin 3's reading to val
  if(val==HIGH)  // anything detected by linear hall sensor, LED starts
  {
    digitalWrite(Led,HIGH);
  }
  else
  {
    digitalWrite(Led,LOW);
  }
}