मंगलवार, 30 अप्रैल 2019

2 चॅनल रिले को आरडूइनोसे कैसे कंट्रोल करें

आज हम  Arduino  से एक 2 चैनल रिले कैसे कंट्रोल किया जाता है यह सीखेंगे.





ऊपर फोटो में दिखाई देने वाला 2 चैनल ऑप्टो कपलर रिले मैंने अमेज़न इंडिया से खरीदा था.  यह एक 5v का रिले है. इसका मतलब उसे ऑपरेट करने के लिए 5 वोल्ट की जरूरत होती है.  यह सप्लाय रिले को दो अलग अलग जगहों पर देना पड़ता है. एक है VCC और GND  और दुसरा है JD-VCC और GND


इस रिले में ऑप्टो कप्लर या ऑप्टो आइसोलेटर की सर्किट भी बने हुई है. इसमें दो सर्किट होते हैं और दोनों के बीच में कोई इलेक्ट्रिक कनेक्शन नहीं होता. यही ऑप्टो कप्लर का काम है.

जब आप नया रिले खरीदते हो तो उसमें VCC और JD-VCC के ऊपर एक जम्पर पिन लगी हुई दिखाई देती है. इसके कारण सिर्फ VCC को दिया हुआ सप्लाय JD-VCC के मार्फ़त दुसरे सर्किट में पहुंचता है. इससे ऑप्टो आइसोलेशन खतरे में  पड जाता है. आप इस तरह रिले ठीक से काम कर रहा है या नहीं इसे चेक कर सकते हो, उसमें कुछ जादा प्रॉब्लम नहीं आती. लेकिन अगर आपको रिले के आउटपुट में कोई AC या DC लोड लगाना हो तब आपको यह जम्पर हटा देना चाहिए, और VCC - GND को 5v का अलग सप्लाय देना चाहिए.



यहाँ पर एक बात का ख़ास ध्यान रखना जरूरी है और वो ये की जम्पर पिन को कभी भी VCC-GND के ऊपर ना जोडें. ऐसे स्थिति में शोर्ट सर्किट हो जाएगा.






अब हम इस एक्सपेरिमेंट में प्रयोग में आने वाली चीजों को देखें


Arduino Uno,उसकी केबल, कुछ मेल - फिमेल जम्पर केबल,  2 चैनल का रिले , एक ब्रेड बोर्ड पॉवर सप्लाय, 12 वोल्ट का dc एडाप्टर.







इसकी वायरिंग समझाने के लिए मैंने नीचे एक ड्राइंग बनाया है.


Arduino का 5v और ग्राउंड  रिले के VCC और ग्राउंड को जोडें.
ब्रेड बोर्ड पॉवर सप्लाई से रिले के JD-VCC और ग्राउंड को (जम्पर हटा कर) 5 वोल्ट का सप्लाई दें

अब आरडूइनो के पिन 7 और 8 से रिले के IN1 और IN2 को जोडें.

अगर संभव हो तो कलर कोड का इस्तेमाल करें. मैंने पोजिटिव सप्लाई के लिए लाल, ग्राउंड के लिए काली और सिग्नल वायर के लिए पीले रंग की वायर का इस्तेमाल किया है

अब dc अडाप्टर को ब्रेड बोर्ड पॉवर सप्लाई मोड्यूल से जोडें.  और आरडूइनो लो कंप्यूटर से. अब आरडूइनो  का सोफ्त्वेअर ओपन कर लें. इसमें इस्तेमाल होने वाला प्रोग्राम मैंने नीचे दिया हुआ है. साथ ही उसकी डाउनलोड लिंक भी अंत में दी है. कृपया प्रोग्रामिंग के हिस्से को इंग्लिश में ही समझ लें तो बेहतर होगा.

These are the variables that you declare at the beginning of the program. Relay1, Relay2 are          variables. And 7 and 8 are the port number or pin numbers on Arduino Uno which we will be using to connect to the IN1 and IN2 of the relay module.

int Relay1 = 7;
int Relay2 = 8;


This is the setup() function of the Arduino. Whatever code you write here will be executed once in the beginning when the program runs. After that only the code in the loop() function will run over and over again till you disconnect the power supply of the Arduino. The program will resume as soon as you power the Arduino again.

The Serial.begin(9600) function opens the serial port and sets data rate to 9600 bps. We will be opening the Serial communication only if we need to check the output on the connected computer. If you intend to  run this program without connecting to the computer, after the program and the circuit are tested. You can reduce the overhead by commenting out all the lines that begin with "Serial."
You do not need Serial () functions to be consuming your processing power if you are not looking at the output on the Serial Monitor a computer.

There is more to understand here. We will go into it in a later article.

We declare the pins, that is the Variables Relay1 and Relay2 to be outputs. Then immediately we turn them High. When we turn a pin HIGH using the digitalWrite() function, the LED is turned on if connected  with that port, but that is not the case with our relays. We are using Active Low type of relays. And we will turn then Off, to do that we neeed to send HIGH on the port.

void setup() {

Serial.begin(9600);

pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);

digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
}


Now we come to the loop() function. Whatever code we write in this function runs over and over again till the Arduino has power. Now we will Turn the Relay On for 1 second one after the other  and then turn them off in the reverse order. You can notice the LEDs of the corresponding Relays turned on and the Clicking sound of the Relays as they take their turns.

void loop() {

  digitalWrite(Relay1, LOW);
  Serial.println("Relay 1 On");
  delay(1000);
  digitalWrite(Relay2, LOW);
  Serial.println("Relay 2 On");
  delay(1000);
  digitalWrite(Relay2, HIGH);
  Serial.println("Relay 2 Off");
  delay(1000);
  digitalWrite(Relay1, HIGH);
  Serial.println("Relay 1 Off");
  delay(1000);

}

एक्सपेरिमेंट करते समय छोटी छोटी गलतियां पकड़ में ना आने पर आप को काफी परेशान होना पड़ता है. इसलिए मैं कुछ गलतियों को किस तरह से पकड़ा सकता है यह भी बताऊंगा.



यह एक सर्किट है जिसमें रिले के दोनों एलईडी जलते बुझते दीखते हैं लेकिन रिले की आवाज नहीं सुनाई देती. ऐसा अगर आपके साथ हुआ तो जान लें की ब्रेड बोर्ड पॉवर सप्लाई से JD-VCC और GND को जुड़ने वाली वायरें ठीक से नहीं बैठी हैं, या खराब हैं.


Download the code from this link 


कोई टिप्पणी नहीं:

एक टिप्पणी भेजें

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.