Wa Koodu

Lilo lilo Reed Switch lati Ṣakoso Relay ati Awọn Ẹrù AC/DC pẹlu Arduino

Lilo lilo Reed Switch lati Ṣakoso Relay ati Awọn Ẹrù AC/DC pẹlu Arduino

Nínú ẹ̀kọ́ yìí, a óò ṣàwárí bí a ṣe lè lo reed switch pẹ̀lú Arduino láti ṣàkóso relay tí ó lè ṣàkóso àwọn ẹrù AC àti DC. Reed switch ń ṣiṣẹ́ gẹ́gẹ́ bí ẹ̀rọ ìmọ̀lára oògùn, tí ó ń jẹ́ kí a lè mú relay ṣiṣẹ́ nípa sísúnmọ́ mágínẹ̀ẹ̀tì. Ìtòlẹ́ yìí pípé fún àwọn ohun èlò bíi ìtànìlétí, àwọn iná tí ń ṣiṣẹ́ láìsí ẹnìkan, tàbí èyíkéyìí ibi tí o bá fẹ́ ṣàkóso àwọn ẹ̀rọ nípa wíwà tàbí àìsí pápá oògùn. Àbájáde rẹ̀ yóò jẹ́ ẹ̀yà iná tí ó ń ṣiṣẹ́ pátápátá tí ó lè tan iná tàbí ìtànìlétí nípa ipò reed switch.

Reed Switch Schematic
Reed Switch module

Bí a ṣe ń kọ́ iṣẹ́ yìí, a óò jíròrò àwọn ohun èlò pàtàkì tí ó wà nínú rẹ̀, pẹ̀lú reed switch, relay, àti Arduino. Reed switch ní àwọn ẹ̀yà mẹ́ta: VCC (agbára), GND (ilẹ̀), àti OUTPUT (ìfihàn). Nígbà tí mágínẹ̀ẹ̀tì bá súnmọ́, switch yóò pa, tí yóò jẹ́ kí ẹ̀yà ìfihàn lọ sí HIGH, èyí tí ó lè mú relay ṣiṣẹ́. Relay ń ṣiṣẹ́ gẹ́gẹ́ bí ẹ̀rọ ìyípadà fún àwọn ẹrù foltaje gíga, tí ó mú un dára fún ṣíṣàkóso àwọn ẹ̀rọ bíi atupa tàbí ìtànìlétí.

Fún ìfihàn ojú tí ó yàtọ̀ àti ìpàlápàlẹ̀ síwájú sí i, rí i dájú pé o wo fídíò tí ó jọmọ́ rẹ̀ ní (nínú fídíò ní 00:00).

Reed Switch module to view

Àlàyé Ohun Èlò

Àwọn ohun èlò pàtàkì nínú iṣẹ́ yìí pẹ̀lú reed switch, relay module, àti Arduino board. Reed switch jẹ́ ẹ̀rọ ìmọ̀lára oògùn tí ó ń pa àwọn ìfarakanra rẹ̀ nígbà tí mágínẹ̀ẹ̀tì bá wà ní àyíká, tí ó ń jẹ́ kí iná kọjá nípasẹ̀ ẹ̀yà OUTPUT. Ẹ̀yà yìí ń fi ìfihàn sí relay, èyí tí ó lè ṣàkóso àwọn ẹ̀rọ foltaje gíga láìséwu.

Relay module jẹ́ àpẹẹrẹ láti ṣàkóso àwọn ẹrù tí ó tóbi. Ó ní àwọn ìsopọ̀ pàtàkì mẹ́ta: Common (COM), Normally Open (NO), àti Normally Closed (NC). Nígbà tí Arduino bá mú relay ṣiṣẹ́, ó ń so ẹ̀yà COM pọ̀ mọ́ ẹ̀yà NO, tí ó ń jẹ́ kí iná kọjá sí ẹ̀rọ tí ó ní ìsopọ̀. Ìtòlẹ́ yìí ń fún wa ní agbára láti ṣàkóso ọ̀pọ̀lọpọ̀ àwọn ẹ̀rọ iná láìsí fífi Arduino sopọ̀ tààrà pẹ̀lú àwọn foltaje gíga. Amplifier pàtàkì tí a lò láti mú ìfihàn reed switch pọ̀ sí i ni LM393 Operational Amplifier

Ìwé Ìtọ́kasí fún module

OlùṣeÀìmọ̀
Foltaje Logic/IO3.3V- 5 V
Foltaje ìpèsè5 V
Ìwọ̀n iná jáde (fún ikanni)10 A tó pọ̀ jù
Ìwọ̀n iná gíga (fún ikanni)16 A tó pọ̀ jù
Ìtọ́sọ́nà ìgbohùnsáfẹ́fẹ́ PWMKò wúlò
Àwọn ìpele ìfihàn logic2.5 V tó kéré jù (HIGH)
Ìdínkù foltaje / RDS(on) / ìkún0.1 V tí ó wọ́pọ̀
Àwọn ìwọ̀n ooru85 °C tó pọ̀ jù
Àkójọpọ̀PCB mount

Àwọn Ìtọ́sọ́nà Ìsopọ̀

Arduino wiring for Reed switch module
Arduino wiring for Reed switch module

Láti so ẹ̀yà náà, bẹ̀rẹ̀ nípa sísopọ̀ reed switch. So ẹ̀yà VCC ti reed switch pọ̀ mọ́ ìwọ̀n 5V lórí Arduino, kí o sì so ẹ̀yà GND pọ̀ mọ́ ọ̀kan nínú àwọn ẹ̀yà ilẹ̀ lórí Arduino. Ẹ̀yà OUTPUT ti reed switch yẹ kí ó sopọ̀ sí ẹ̀yà oní nọ́ḿbà 2 lórí Arduino. Èyí yóò jẹ́ kí Arduino ka ipò reed switch.

Ní àtẹ̀yìnwá, so relay module. So ẹ̀yà VCC ti relay pọ̀ mọ́ ìwọ̀n 5V lórí Arduino, àti ẹ̀yà GND pọ̀ mọ́ ilẹ̀. Ẹ̀yà input ti relay, èyí tí ń ṣàkóso iṣẹ́ relay, yẹ kí ó sopọ̀ sí ẹ̀yà oní nọ́ḿbà 10 lórí Arduino. Ní ìparí, so ẹrù (bíi atupa) pọ̀ mọ́ àwọn ẹ̀yà Common àti Normally Open ti relay, ní ríri dájú pé ẹrù náà bá àwọn ìwọ̀n relay mu.

Àwọn Àpẹẹrẹ Kóòdù & Ìtọ́sọ́nà

Kóòdù tí ó tẹ̀le yìí ń bẹ̀rẹ̀ àwọn ẹ̀yà náà tí ó sì ń ṣètò ìbánisọ̀rọ̀ serial fún ìwádìí. Reed switch ti sopọ̀ sí ẹ̀yà 2, nígbà tí relay ń ṣàkóso nípasẹ̀ ẹ̀yà 10.


int LD = 200; // àkókò ní milliseconds láti dúró kí ó tó ṣe ìwọ̀n mìíràn.

void setup() {
    Serial.begin(9600);
    pinMode(10, OUTPUT); // sopọ̀ sí relay
    pinMode(2, INPUT); // reed switch input ẹ̀yà 2  
    Serial.println("Robojax Test: Reed switch");
}

Nínú iṣẹ́ loop, a ń ṣàyẹ̀wò ipò reed switch nígbà gbogbo. Bí switch bá pa (tí ó ń fi hàn pé mágínẹ̀ẹ̀tì wà), a óò mú relay ṣiṣẹ́. Bí switch bá ṣí, a óò pa relay lẹ́yìn ìdúró 5 ìṣẹ́jú àáyá, tí ó ń fún ní àkókò ìyọ̀ǹda kí ó tó pa á.


void loop() {
    if(digitalRead(2)){
      Serial.println("Switch ON "); 
      digitalWrite(10, LOW); // Mú relay ṣiṣẹ́    
      delay(LD); 
    }else{
      delay(5000); // dúró 5 ìṣẹ́jú àáyá kí ó tó pa ìtànìlétí
      digitalWrite(10, HIGH); // Pa relay
    }
}

Kóòdù yìí ń fún wa ní ààyè láti ṣàkóso relay nípa ipò reed switch. O lè yí àkókò àti ìwà padà nípa yíyí àwọn iye delay padà tàbí bí a ṣe ń ṣàkóso relay nípa ìfihàn switch.

Ìfihàn / Ohun Tí O Lè Retí

Nígbà tí ìtòlẹ́ bá parí, sísúnmọ́ mágínẹ̀ẹ̀tì sí reed switch yóò mú relay ṣiṣẹ́, tí yóò tan iná tàbí ìtànìlétí tí ó sopọ̀. Bí a bá yọ mágínẹ̀ẹ̀tì kúrò, iná yóò dúró fún àkókò ìdúró kan kí ó tó pa, tí ó ń fún olùṣàmúlò ní àkókò ìyọ̀ǹda. Rí i dájú pé o dán iṣẹ́ náà wò láti fi ìdí rẹ̀ múlẹ̀ pé relay ń ṣiṣẹ́ bí a ti retí àti pé ó ń dáhùn sí reed switch ní ọ̀nà tí ó tọ́.

Àwọn Àkókò Fídíò

  • 00:00 - Ìfihàn sí iṣẹ́ náà
  • 02:15 - Àlàyé ohun èlò
  • 05:30 - Ìfihàn ìsopọ̀
  • 08:45 - Ìtọ́sọ́nà kóòdù
  • 12:00 - Àwọn àbájáde tí a retí àti àwọn ìtọ́sọ́nà ìwádìí

Aworan

Reed Switch module top view
Reed Switch module top view
Reed Switch Schematic
Reed Switch Schematic
reed_switch-4
reed_switch-4
Reed Switch module
Reed Switch module
Reed Switch module to view
Reed Switch module top view
Reed Switch module
Reed Switch module
Arduino wiring for Reed switch module
Arduino wiring for Reed switch module
22-Reed Magnetic Switch Arduino with Relay code
Ede: C++
++
//*
 * This is the Arduino code for a reed switch to
 * turn a relay ON, which the relay
 * can turn a light or alarm ON.
 * The reed switch is connected to pin 2.
 * The 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: December 5, 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 downloaded 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 milliseconds to wait before making another reading.

void setup() {
    Serial.begin(9600);
    // output 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 off
				// remove this line if you don't want any delay
      digitalWrite(10, HIGH);// Turn the relay OFF
      
    }
  




}// loop

Orisun & itọkasi

Ko si awọn orisun sibẹsibẹ.

Fáìlìs📁

Ko si awọn faili ti o wa.