பாடம் 74: Arduino உடன் ஒரு கூர்மையான அகச்சிவப்பு சென்சார் தொகுதியைப் பயன்படுத்துதல்
அறிமுகம்
இந்த வழிகாட்டி, Arduino உடன் இரண்டு அல்லது அதற்கு மேற்பட்ட Sharp அகச்சிவப்பு (IR) தொலைவு சென்சார்களை எவ்வாறு பயன்படுத்தி தொலைவை அளவிடுவது மற்றும் முடிவுகளை Serial Monitor இல் காண்பிப்பது என்பதை நிரூபிக்கிறது. ஒற்றை சென்சார் பயனுள்ளதாக இருந்தாலும், ஸ்மார்ட் கார், ரோபோடிக் கை அல்லது எந்த நகரும் இயந்திரம் போன்ற பல நிஜ உலக பயன்பாடுகளுக்கு பல திசைகளில் இருந்து ஒரே நேரத்தில் தொலைவு அளவீடுகள் தேவைப்படுகின்றன. எடுத்துக்காட்டாக, முன்பக்கத்தில் ஒரு சென்சாரை நிறுவி முன்னால் உள்ள தொலைவை அளவிடலாம், மேலும் மோதல்களைத் தவிர்க்க வலது அல்லது இடது பக்கத்தில் மற்றொன்றை நிறுவலாம். இந்த டுடோரியல், தனிப்பட்ட சென்சாரின் விவரக்குறிப்புகள் மற்றும் செயல்பாட்டை விளக்கும் தனி, விரிவான வீடியோவை அடிப்படையாகக் கொண்டு, பல சென்சார்களை திறமையாக கையாள உங்கள் Arduino ஐ எவ்வாறு கட்டமைப்பது என்பதைக் காட்டுகிறது.
உங்களை ஊக்குவிக்க சில நடைமுறை திட்ட யோசனைகள் இங்கே:
- இடது, வலது மற்றும் முன் பக்கங்களில் தொலைவுகளை அளவிடுவதன் மூலம் தடைகளைத் தவிர்க்கும் ரோபோவை உருவாக்குதல்.
- இறுக்கமான இடத்தில் வாகனத்தை வழிநடத்த பல சென்சார்களைப் பயன்படுத்தும் ஸ்மார்ட் பார்க்கிங் உதவியாளரை உருவாக்குதல்.
- வெவ்வேறு கோணங்களில் வைக்கப்பட்ட சென்சார்கள் மூலம் கதவு அல்லது நடைபாதையை கண்காணிக்கும் பாதுகாப்பு அமைப்பை உருவாக்குதல்.
- பார்வையாளரின் கையின் தொலைவு காட்சிப்படுத்தப்படுவதை மாற்றும் ஊடாடும் கலை நிறுவலை உருவாக்குதல்.

இந்த வீடியோவில், பல Sharp IR சென்சார்களை இயக்க தேவையான வயரிங் மற்றும் குறியீட்டில் கவனம் செலுத்தப்படுகிறது. ஆர்ப்பாட்டம் இரண்டு GP2Y0A21YK0F சென்சார்களைப் பயன்படுத்துகிறது, அவை 10 முதல் 80 செ.மீ வரை தொலைவுகளை அளவிடுகின்றன. குறியீடு எளிதில் விரிவாக்கக்கூடிய வகையில் கட்டமைக்கப்பட்டுள்ளது, எனவே சில வரிகளுடன் மூன்றாவது, நான்காவது அல்லது அதற்கு மேற்பட்ட சென்சார்களைச் சேர்க்கலாம்.
வன்பொருள் மற்றும் கூறுகள்
இந்த திட்டத்துடன் தொடர, உங்களுக்கு பின்வரும் கூறுகள் தேவைப்படும்:
- ஒரு Arduino போர்டு (எ.கா., Uno, Mega).
- இரண்டு அல்லது அதற்கு மேற்பட்ட Sharp IR தொலைவு சென்சார்கள் (எ.கா., GP2Y0A21YK0F).
- ஜம்பர் கம்பிகள்.
- ஒரு பிரெட்போர்டு (விருப்பம், எளிதான இணைப்புகளுக்கு).
வயரிங் வழிகாட்டி
Sharp IR சென்சாரில் மூன்று கம்பிகள் உள்ளன: சிவப்பு (மின்சாரம்), கருப்பு (தரை), மற்றும் மஞ்சள் (சிக்னல் வெளியீடு). வயரிங் நேரடியானது. முதல் சென்சாருக்கு, அதன் சிவப்பு கம்பியை Arduino இன் 5V பின்னுடன் இணைக்கவும், கருப்பு கம்பியை ஒரு தரை (GND) பின்னுடன் இணைக்கவும், மஞ்சள் சிக்னல் கம்பியை ஒரு அனலாக் பின்னுடன், எடுத்துக்காட்டாக A1 உடன் இணைக்கவும். இரண்டாவது சென்சாருக்கு, அதன் சிவப்பு கம்பியை அதே அல்லது மற்றொரு 5V பின்னுடன் இணைக்கவும், கருப்பு கம்பியை GND உடன் இணைக்கவும், மஞ்சள் கம்பியை A2 போன்ற வேறு அனலாக் பின்னுடன் இணைக்கவும்.
5V பின்கள் தீர்ந்துவிட்டால், வீடியோ ஒரு புத்திசாலித்தனமான தீர்வை வழங்குகிறது. எந்த டிஜிட்டல் பின்னையும் மின்சார மூலமாகப் பயன்படுத்தலாம். குறியீட்டில், டிஜிட்டல் பின் 2 வெளியீடாக உள்ளமைக்கப்பட்டு HIGH ஆக அமைக்கப்படுகிறது, இது நிலையான 5V ஐ வழங்குகிறது. உங்கள் சென்சார்களின் சிவப்பு கம்பிகளை அர்ப்பணிக்கப்பட்ட 5V பின்னுக்கு பதிலாக இந்த டிஜிட்டல் பின்னுடன் இணைப்பீர்கள். தரை கம்பிகளை Arduino இல் உள்ள எந்த GND பின்களுடனும் இணைக்கலாம். இந்த அமைப்பின் ஆர்ப்பாட்டத்தை வீடியோ [00:06:10] இல் காட்டுகிறது.
இணைப்புகளின் காட்சி குறிப்புக்கு, கீழே உள்ள வயரிங் வரைபடத்தைப் பார்க்கவும்:



குறியீடு விளக்கம்
இந்த பிரிவு குறியீட்டின் பயனர்-கட்டமைக்கக்கூடிய பகுதிகளில் கவனம் செலுத்துகிறது, அவை அனைத்தும் ஸ்கெட்ச்சின் மேலே அமைந்துள்ளன. உங்கள் பின்கள் மற்றும் சென்சார் மாதிரிகளை இங்கே வரையறுப்பீர்கள்.
முதலில், குறியீடு Sharp IR சென்சார்களுக்கு தேவையான நூலகத்தை உள்ளடக்கியது, #include <SharpIR.h>. இந்த நூலகம் சென்சாரிலிருந்து அனலாக் மின்னழுத்தத்தை தொலைவு அளவீடாக மாற்ற தேவையான சிக்கலான கணிதத்தை கையாளுகிறது.
அடுத்து, உங்கள் ஒவ்வொரு சென்சாருக்கும் அனலாக் பின்களை வரையறுப்பீர்கள். எடுத்துக்காட்டு குறியீடு #define IR1 A1 மற்றும் #define IR2 A2 ஐப் பயன்படுத்துகிறது. இரண்டுக்கும் மேற்பட்ட சென்சார்களைப் பயன்படுத்தினால், #define IR3 A3 போன்ற கூடுதல் வரையறைகளை இங்கே சேர்ப்பீர்கள்.
கட்டமைப்பின் முக்கியமான பகுதி உங்கள் சென்சாருக்கு சரியான மாதிரியை அமைப்பது. குறியீடு #define model1 1080 மற்றும் #define model2 1080 ஐப் பயன்படுத்துகிறது. இந்த எண் தன்னிச்சையானது அல்ல; இது உங்களிடம் எந்த சென்சார் உள்ளது என்பதை நூலகத்திற்கு சொல்கிறது, ஏனெனில் ஒவ்வொரு மாதிரிக்கும் வெவ்வேறு மின்னழுத்த-க்கு-தொலைவு வளைவு உள்ளது. குறியீட்டு கருத்துகள் ஒரு பயனுள்ள பட்டியலை வழங்குகின்றன:
- 2 முதல் 15 செ.மீ GP2Y0A51SK0F 215 ஐப் பயன்படுத்தவும்
- 4 முதல் 30 செ.மீ GP2Y0A41SK0F / GP2Y0AF30 தொடர் 430 ஐப் பயன்படுத்தவும்
- 10 முதல் 80 செ.மீ GP2Y0A21YK0F 1080 ஐப் பயன்படுத்தவும்
- 10 முதல் 150 செ.மீ GP2Y0A60SZLF 10150 ஐப் பயன்படுத்தவும்
- 20 முதல் 150 செ.மீ GP2Y0A02YK0F 20150 ஐப் பயன்படுத்தவும்
- 100 முதல் 550 செ.மீ GP2Y0A710K0F 100550 ஐப் பயன்படுத்தவும்
உங்கள் குறிப்பிட்ட சென்சாருடன் பொருந்த இந்த மதிப்பை மாற்ற வேண்டும். எடுத்துக்காட்டாக, நீங்கள் GP2Y0A02YK0F ஐப் பயன்படுத்தினால், வரையறையை #define model1 20150 என மாற்றுவீர்கள். குறியீடு ஒவ்வொரு சென்சாருக்கும் ஒரு பொருளை உருவாக்குகிறது, SharpIR SharpIR1(IR1, model1); போன்றது. இந்த வரி முதல் சென்சாருக்கு பின் மற்றும் மாதிரியை இணைக்கிறது. அதிக சென்சார்களைச் சேர்த்தால், இந்த வரியை நகலெடுத்து பொருள் பெயர், பின் மற்றும் மாதிரியை அதற்கேற்ப மாற்றுவீர்கள்.
setup() செயல்பாட்டில், Serial Monitor 9600 பாட் வேகத்தில் துவக்கப்படுகிறது. இது Arduino உங்கள் கணினியுடன் தொடர்பு கொள்ளும் வேகம். குறியீடு தேவைப்பட்டால் ஒரு டிஜிட்டல் பின்னை 5V மூலமாகப் பயன்படுத்த ஒரு பகுதியையும் உள்ளடக்கியது, வயரிங் பிரிவில் விளக்கப்பட்டுள்ளது. இது pinMode(2,OUTPUT); மற்றும் digitalWrite(2, HIGH); மூலம் செய்யப்படுகிறது.
இறுதியாக, loop() செயல்பாடு முக்கிய தர்க்கத்தைக் கொண்டுள்ளது. தொடக்கத்தில் delay(500); உள்ளது, இது ஒவ்வொரு அளவீட்டு தொகுப்பிற்கும் இடையே உள்ள நேரத்தை 500 மில்லி விநாடிகளாக அமைக்கிறது. அளவீடுகளை அதிக அல்லது குறைவான அடிக்கடி செய்ய இதை சரிசெய்யலாம். லூப்பின் மையமானது நூலகத்தின் distance() செயல்பாட்டைப் பயன்படுத்தி ஒவ்வொரு சென்சாரிலிருந்தும் தொலைவைப் படிப்பது, int dis1=SharpIR1.distance(); போன்றது. முடிவுகள் விளக்க உரையுடன் Serial Monitor இல் அச்சிடப்படுகின்றன, Serial.print("Distance (1): "); போன்றது, அதைத் தொடர்ந்து மதிப்பு மற்றும் "cm" அலகு.
நேரடி திட்ட ஆர்ப்பாட்டம்
வீடியோவில், வழங்குநர் இரண்டு சென்சார்களுடன் அமைப்பை நிரூபிக்கிறார். [00:07:44] இல் உள்ள ஆர்ப்பாட்டத்தில் நீங்கள் பார்க்க முடியும் என, சீரியல் மானிட்டர் இரண்டு சென்சார்களின் தூர அளவீடுகளையும் காட்டுகிறது. முதல் சென்சாரின் முன் ஒரு பொருள் வைக்கப்படும்போது, "Distance (1)" க்கான அளவீடு மாறுகிறது. இதேபோல், இரண்டாவது சென்சாரின் முன் ஒரு பொருள் வைக்கப்படும்போது, "Distance (2)" க்கான அளவீடு புதுப்பிக்கப்படுகிறது. ஒரு தாளை ஒரு தூரத்தில் பிடித்து வைப்பதன் மூலம், சென்சார்கள் தோராயமாக 23 மற்றும் 24 செ.மீ. அளவிடுவதாக வீடியோ காட்டுகிறது. ஒரு சென்சார் தடுக்கப்படும்போது, அதன் அளவீடு சுமார் 17 செ.மீ. ஆகக் குறைகிறது, இது ஒவ்வொரு சென்சாரும் சுயாதீனமாக செயல்படுகிறது மற்றும் அதன் சம்பந்தப்பட்ட திசைக்கு நிகழ்நேர தூரத் தரவை வழங்குகிறது என்பதை உறுதிப்படுத்துகிறது. இது பல சென்சார்களை ஒரே நேரத்தில் கையாளும் குறியீட்டின் திறனை சரிபார்க்கிறது.
அத்தியாயங்கள்
- [00:00] பல ஷார்ப் IR சென்சார்களைப் பயன்படுத்துவதற்கான அறிமுகம்
- [00:28] பல தூர சென்சார்களுக்கான பயன்பாடுகள்
- [01:34] குறியீடு விளக்கம்: நூலகம் மற்றும் பின் வரையறைகள்
- [02:24] சென்சார் மாதிரிகளை உள்ளமைத்தல் மற்றும் பொருட்களை உருவாக்குதல்
- [04:15] அமைப்பு மற்றும் லூப் செயல்பாடுகள் விளக்கப்பட்டுள்ளன
- [06:10] பல சென்சார்களுக்கான வயரிங் வழிகாட்டி
- [07:44] இரண்டு சென்சார்களுடன் நேரடி ஆர்ப்பாட்டம்
++
/*
* Using two or more Sharp IR distance sensors with Arduino
* Measure distance
* Download and resource page for this video https://robojax.com/RJT143
* Watch video instructions for this video: https://youtu.be/WQ3oFyF5qeY
*
* Watch main video explaining the Sharp IR distance sensor:
* https://robojax.com?vid=robojax-sharp_IR
*
* Written by Ahmad Shamshiri for Robojax.com on Saturday, December 1, 2018
* at 20:56 in Ajax, Ontario, Canada
*
* 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/>.
*/
#include <SharpIR.h>
#define IR1 A1 // define signal pin
#define IR2 A2 // define signal pin
#define model1 1080 // for GP2Y0A21YK0F used 1080
#define model2 1080 // for GP2Y0A21YK0F used 1080
// Sharp IR code for Robojax.com
// ir: the pin where your sensor is attached
/*
2 to 15 cm GP2Y0A51SK0F use 215
4 to 30 cm GP2Y0A41SK0F / GP2Y0AF30 series use 430
10 to 80 cm GP2Y0A21YK0F use 1080
10 to 150 cm GP2Y0A60SZLF use 10150
20 to 150 cm GP2Y0A02YK0F use 20150
100 to 550 cm GP2Y0A710K0F use 100550
*/
SharpIR SharpIR1(IR1, model1);
SharpIR SharpIR2(IR2, model2);
void setup() {
// Multiple Sharp IR Distance meter code for Robojax.com
Serial.begin(9600);
Serial.println("Robojax Sharp IR ");
// extra pin for 5V if needed
pinMode(2,OUTPUT);// define pin 2 as output
digitalWrite(2, HIGH);// set pin 2 HIGH so it always have 5V
// Robojax.com 20181201
}
void loop() {
// Sharp IR code for Robojax.com 20181201
delay(500);
unsigned long startTime=millis(); // takes the time before the loop on the library begins
int dis1=SharpIR1.distance(); // this returns the distance for sensor 1
int dis2=SharpIR2.distance(); // this returns the distance for sensor 2
// Sharp IR code for Robojax.com 20181201
Serial.print("Distance (1): ");
Serial.print(dis1);
Serial.println("cm");
Serial.print("Distance (2): ");
Serial.print(dis2);
Serial.println("cm");
// Sharp IR code for Robojax.com
}
++
/*
* Lesson 74: Using two or more Sharp IR distance sensors
* Sharp IR (infrared) distance measurement module for Arduino
* Measures the distance in cm.
* Written by Ahmad Shamshiri for Robojax.com
* on February 25, 2019 at 21:38 in Ajax, Ontario, Canada
* Original library: https://github.com/guillaume-rico/SharpIR
* Watch video instructions for this code: https://youtu.be/WQ3oFyF5qeY
*
* Full explanation of this code and wiring diagram is available at
* my Arduino Course at Udemy.com here: http://robojax.com/L/?id=62
* Written by Ahmad Shamshiri on February 3, 2018 at 07:34
* in Ajax, Ontario, Canada. www.robojax.com
*
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a donation using PayPal http://robojax.com/L/?id=64
* * 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/>.
*/
*/
// Sharp IR code for Robojax.com
#include
#define IR A0 // define signal pin
#define model 1080 // used 1080 because model GP2Y0A21YK0F is used
// Sharp IR code for Robojax.com
// ir: the pin where your sensor is attached
// model: an int that determines your sensor: 1080 for GP2Y0A21Y
// 20150 for GP2Y0A02Y
// 430 for GP2Y0A41SK
/*
2 to 15 cm GP2Y0A51SK0F use 1080
4 to 30 cm GP2Y0A41SK0F / GP2Y0AF30 series use 430
10 to 80 cm GP2Y0A21YK0F use 1080
10 to 150 cm GP2Y0A60SZLF use 10150
20 to 150 cm GP2Y0A02YK0F use 20150
100 to 550 cm GP2Y0A710K0F use 100550
*/
#include <SharpIR.h>
#define IR1 A1 // define signal pin
#define IR2 A2 // define signal pin
#define model1 1080 // for GP2Y0A21YK0F used 1080
#define model2 1080 // for GP2Y0A21YK0F used 1080
// Sharp IR code for Robojax.com
// ir: the pin where your sensor is attached
/*
2 to 15 cm GP2Y0A51SK0F use 215
4 to 30 cm GP2Y0A41SK0F / GP2Y0AF30 series use 430
10 to 80 cm GP2Y0A21YK0F use 1080
10 to 150 cm GP2Y0A60SZLF use 10150
20 to 150 cm GP2Y0A02YK0F use 20150
100 to 550 cm GP2Y0A710K0F use 100550
*/
SharpIR SharpIR1(IR1, model1);
SharpIR SharpIR2(IR2, model2);
void setup() {
// Multiple Sharp IR Distance meter code for Robojax.com
Serial.begin(9600);
Serial.println("Robojax Sharp IR ");
// extra pin for 5V if needed
pinMode(2,OUTPUT);// define pin 2 as output
digitalWrite(2, HIGH);// set pin 2 HIGH so it always have 5V
// Robojax.com 20181201
}
void loop() {
// Sharp IR code for Robojax.com 20181201
delay(500);
unsigned long startTime=millis(); // takes the time before the loop on the library begins
int dis1=SharpIR1.distance(); // this returns the distance for sensor 1
int dis2=SharpIR2.distance(); // this returns the distance for sensor 2
// Sharp IR code for Robojax.com 20181201
Serial.print("Distance (1): ");
Serial.print(dis1);
Serial.println("cm");
Serial.print("Distance (2): ");
Serial.print(dis2);
Serial.println("cm");
// Sharp IR code for Robojax.com
}
வளங்கள் மற்றும் மேற்கோள்கள்
-
வெளியுறுப்புDistance-measuring sensors (website)sharp-world.com
-
வெளியுறுப்புSharp IR Library (from GitHub)github.com
-
வெளியுறுப்புSharp Library from RoboJob.comrobojax.com
கோப்புகள்📁
பிரிட்சிங் கோப்பு
-
sharp ir sensor GP2Y0A02YK0F
sharp ir sensor GP2Y0A02YK0F .fzz
மற்ற கோப்புகள்
-
Sharp GP2Y0A41SK0F Infrared distance sensor datasheet
robojax_sharp_IR_GP2Y0A41SK0F_datasheet.pdf0.84 MB -
Sharp GP2Y0A710K0F Infrared distance sensor datashee
robojax_sharp_IR_GP2Y0A710K0F_datasheet.pdf0.33 MB -
Arduino library for Sharp Infrard distance sensor
robojax-sharp_IR-master.zip