فهرست مطالب
ماژول رید سوئیچ
رید سوئیچ استفاده شده در این ماژول در واقع یک سنسور مغناطیسی است که به طورمعمول باز است و اگر نزدیک به یک میدان مغناطیسی باشد بسته می شود.
مشخصات فنی ماژول
ماژول رید سوئیچ میدان مغناطیسی KY-021 از یک مقاومت 10kΩ و یک رید سوئیچ کوچک تشکیل شده توسط یک میدان مغناطیسی که معمولاً در سیستم های مکانیکی به عنوان حسگر استفاده می شود، تشکیل شده است. این ماژول با سیستم عامل های الکترونیکی محبوب مانند Arduino ، Teensy و ESP8266 سازگار می باشد.
مشخصات در جدول زیر امده است :


پایه های ماژول رید سوئیچ میدان مغناطیسی

اتصال پایه های ماژول در برد Arduino و Raspberry Pi در جدول های زیر آورده شده است:


دیاگرام اتصالات
پایه های مختلف ماژول را مطابق جدول بالا و به صورت آنچه در تصویر زیر مشاهده میشود به برد آردوینو متصل کنید.


کدهای آردوینو
هنگامی که ماژول یک میدان مغناطیسی را تشخیص می دهد، چراغ LED پین 13 را در آردوینو روشن می کند. برای فعال کردن رید سوئیچ حتما یک آهنربا در نزدیکی KY-021 قرار دهید.
از ماژول های KY-011 ، KY-016 یا KY-029 می توان به عنوان یک LED استفاده کرد.
int led = 13; // LED pin
int reelSwitch = 10; // magnetic senso rpin
int switchState; // variable to store reel switch value
void setup()
{
pinMode (led, OUTPUT);
pinMode (reelSwitch, INPUT);
}
void loop()
{
switchState = digitalRead(reelSwitch); // read the value of digital interface 10 and assign it to switchState
if (switchState == HIGH) // when the magnetic sensor detect a signal, LED is flashing
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
}
کدهای رزبری پای
# Needed modules will be imported and configured
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# Declaration of the input pin which is connected with the sensor.
GPIO_PIN = 24
GPIO.setup(GPIO_PIN, GPIO.IN)
print "Sensor-test [press ctrl+c to end]"
# This outFunction will be started after a signal was detected.
def outFunction(null):
print("Signal detected")
# The outFunction will be started after a signal (falling signal edge) was detected.
GPIO.add_event_detect(GPIO_PIN, GPIO.FALLING, callback=outFunction, bouncetime=100)
# main program loop
try:
while True:
time.sleep(1)
# Scavenging work after the end of the program
except KeyboardInterrupt:
GPIO.cleanup()


