Other Arduino Codes and Videos by Robojax

Using reed switch to control relay and AC/DC load with Arduino

دروس آردوینو به فارسی

Reed Magnetic Switch Arduino with Relay Code

this video shows you how to use reed switch with relay to detect door or window opening to turn on ligh or Alarm using a relay. You will learn how to use it without Arduino and with Arduino.

 //*
 * This is the Arduino code for reed switch to
 * turn a relay ON which the relay
 * can turn a light or alarm ON
* reed switch is connected to pin 2
 * Relay is connected to pin 10
 
 watch the video for this code: https://www.youtube.com/watch?v=2RBFKqoauaI
 * 
 * Written by Ahmad Shamshiri for Robojax.com Video
 * Date: Dec 05, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.

 * Please keep this note with the code.
 * This code is available on Robojax.com
 * 
 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


 int LD = 200; // time in melliseond to wait before make another reading.

void setup() {
    Serial.begin(9600);
    // out pins
    pinMode(10, OUTPUT);// connected to relay
         

    // input pins
    pinMode(2, INPUT);// reed switch  input pin 2  


    Serial.println("Robojax Test: Reed switch");

}

void loop() {

    // read the REED switch
    if(digitalRead(2)){
      Serial.println("Switch ON "); 
      digitalWrite(10, LOW); // Turn the relay ON    
      delay(LD); 
    }else{
      delay(5000);// wait 5 seconds before turning the alarm
				// remove this line if you don't want any delay
      digitalWrite(10, HIGH);// Turn the relay OFF
      
    }
  




}// loop



   

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal