|
|||
Arduino ½º¸¶Æ®Æù ºí·çÅõ½º ÁÖÇà·Îº¿ »ç¿ë Çϱâ |
|||
* Update history - 2016.5.17 : Ãʱâ Release |
|||
¾ÆµÎÀ̳ë(Arduino) µð¹ÙÀ̽º¸¦ ÀÌ¿ëÇØ¼ ÀڽŸ¸ÀÇ Àå³²°¨, ¿ø°ÝÁ¶Á¤±â, ·Îº¿µîÀÇ ¸¹Àº ´Ù¸¥ Èï¹Ì·Î¿î ÇÁ·ÎÁ§Æ®¸¦ ÇÒ¼ö ÀÖ½À´Ï´Ù. ±âº»ÀûÀ¸·Î °ËÀº»ö ¶óÀÎ Æ®·¹À̽ÌÀÌ °¡´ÉÇÑ ÁÖÇà ·Îº¿ ÀÔ´Ï´Ù. ½º¸¶Æ®Æù(¾Èµå·ÎÀ̵å) ¿¡¼ ºí·çÅõ½º Åë½ÅÀ» ÀÌ¿ëÇØ¼ ¾ÆµÎÀÌ³ë º¸µåÀÇ DC ¸ðÅ͸¦ Á¦¾îÇÏ¿© ÄÁÆ®·Ñµµ ÇÒ¼ö ÀÖ½À´Ï´Ù. L293D ¸ðÅÍ µå¶óÀ̹ö IC¸¦ »ç¿ëÇÏ¿´½À´Ï´Ù. * °ÀÇ Àüü ·Îµå¸Ê I. ÁÖÇà ·Îº¿ Á¶¸³Çϱâ ÁÖÇà·Îº¿ÀÇ ¸ðÅÍ, ÃÊÀ½ÆÄ¼¾¼, ºí·çÅõ½º, ¼º¸¸ðÅÍ µîÀÇ Á¶¸³¹æ¹ý°ú °á¼± ¹æ¹ý¿¡ ´ëÇØ¼ ¼³¸í ÇÕ´Ï´Ù. 1.1 DC ±â¾îµå ¸ðÅÍ Áغñ 1.2 º¼ÄɽºÆ®, ¹ÙÄû Á¶¸³ 1.3 ¹èÅ͸® ¹Ú½º Á¶¸³ 1.4 ¾ÆµÎÀ̳ë ÄÁÆ®·Ñ º¸µå Á¶¸³ 1.5 Àû¿Ü¼± Æ®·¹ÀÌ½Ì ¼¾¼ Á¶¸³ 1.6 DC ÃÊÀ½ÆÄ ¼¾¼ °ÅÄ¡¸¦ À§ÇÑ ¼º¸ ¸ðÅÍ Á¶¸³ 1.7 ÃÊÀ½ÆÄ ¼¾¼ Á¶¸³ II. ÁÖÇà·Îº¿ ÀÀ¿ë PCÀÇ Å͹̳ÎÀ» ÅëÇØ¼ ¸í·ÉÀ¸·Î ÁÖÇà·Îº¿ÀÇ DC¸ðÅ͸¦ Á¦¾îÇϰí, ºí·çÅõ½º¸¦ ÅëÇØ ¾Èµå·ÎÀÌµå ½º¸¶Æ®Æù¿¡¼ ÁÖÇà ·Îº¿À» Á¦¾îÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ¼ ¼³¸í ÇÕ´Ï´Ù. ¶ÇÇÑ ¼º¸¸ðÅÍ¿Í ÃÊÀ½ÆÄ ¼¾¼, Àû¿Ü¼± ¶óÀÎÆ®·¹ÀÌ½Ì ¼¾¼¸¦ ÀÌ¿ëÇØ¼ °ËÀº»ö ¶óÀÎÀ» µû¶ó°¡´Â ¹æ¹ý¿¡ ´ëÇØ¼µµ ¼³¸í ÇÕ´Ï´Ù. 2.1 ¾ÆµÎÀÌ³ë ´Ù¿î·Î´õ USB µå¶óÀ̹ö ¼³Ä¡ 2.2 À©µµ ȯ°æ¿¡¼ µå¶óÀ̹ö ¼³Ä¡ 2.3 ÁÖÇà·Îº¿ ¾ÆµÎÀÌ³ë º¸µåÀÇ ºÎÀ§º° ¸íĪ 2.4 ¾ÆµÎÀ̳ë ÄÁÆ®·Ñ º¸µå¿Í ¸ðÅÍ Á¦¾î ¹è¼± ¿¬°á 2.5 ¾ÆµÎÀ̳ë ȣȯ º¸µå ȯ°æ ¼³Á¤ 2.6 ȣȯ º¸µå ¼±Åà 2.7 L293D ¸ðÅÍ µå¶óÀ̹ö IC 2.8 L293D ¸ðÅÍ µå¶óÀ̹ö IC »ç¿ë ¼³¸í 2.9 DC ¸ðÅÍ Á¦¾î ¿¹Á¦ 2.10 ¾ÆµÎÀÌ³ë ºí·çÅõ½º Åë½Å 2.11 Àû¿Ü¼± ¶óÀÌÆ®·¹ÀÌ½Ì 2.12 ¼º¸¸ðÅÍ Á¦¾î 2.13 ÃÊÀ½ÆÄ ¼¾¼ Á¦¾î ÀÌ °ÀÇ ÀÚ·á¿¡ ´ëÇÑ ¸ðµç ÁúÀÇ»çÇ×Àº http://cafe.naver.com/avrstudio ÀÇ Arduino Q&A °Ô½ÃÆÇ¿¡ ±ÛÀ» ³²°Ü Áֽðųª master@deviceshop.net ·Î ¸ÞÀÏÀ» º¸³»Áֽñ⠹ٶø´Ï´Ù. °¡±ÞÀûÀÌ¸é ¿©·¯ »ç¶÷ÀÌ Áú¹®¿¡ ´ëÇÑ ´äº¯À» °øÀ¯ ÇÒ¼ö ÀÖµµ·Ï ³×À̹ö Ä«Æó °Ô½ÃÆÇÀ» ÀÌ¿ëÇØ ÁÖ¼ÌÀ¸¸é ÇÕ´Ï´Ù. °¨»çÇÕ´Ï´Ù. |
|||
2.1 ¾ÆµÎÀÌ³ë ´Ù¿î·Î´õ USB µå¶óÀ̹ö ¼³Ä¡ |
|||
- CP2102 USB µå¶óÀ̹ö¸¦ ¼³Ä¡ ÇÕ´Ï´Ù. USB µå¶óÀ̹ö ´Ù¿î·Îµå ( https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx ) »ç¿ëÇϽô ¿î¿µÃ¼Á¦¿¡ ¸Â´Â µå¶óÀ̹ö¸¦ ¼±ÅÃÇØ¼ ´Ù¿î·ÎµåÈÄ ¼³Ä¡ Çϼ¼¿ä. |
|||
![]() |
|||
2.2 À©µµ ȯ°æ¿¡¼ µå¶óÀ̹ö ¼³Ä¡ |
|||
![]() |
|||
![]() |
|||
- Á¤»óÀûÀ¸·Î USB µå¶óÀ̹ö ¼³Ä¡°¡ ¿Ï·á µÇ¾úÀ»¶§ ÀåÄ¡°ü¸®ÀÚÀÇ È¸é ÀÔ´Ï´Ù. | |||
![]() |
|||
2.3 ÁÖÇà·Îº¿ ¾ÆµÎÀÌ³ë º¸µåÀÇ ºÎÀ§º° ¸íĪ |
|||
- ºÎÀ§º° ¸íΰú ±â´ÉÀ» Àß È®ÀÎÇØ µÎ½Ã°í ³ªÁß¿¡ ¸ðÅÍ °á¼±À» ÇÒ¶§ ÁÖÀÇÇØ¼ °á¼±À» ÇØ¾ß ÇÕ´Ï´Ù. - ¿ÞÂÊ ¸ðÅÍÀÇ ºÓÀº»ö ¼±À» ½ÊÀÚµå¶óÀ̹ö¸¦ ÀÌ¿ëÇØ¼ "¿ÞÂʸðÅÍ1 +(Red)" "¿ÞÂʸðÅÍ1 -(Black)" "¿ÞÂʸðÅÍ2 +(Red)" "¿ÞÂʸðÅÍ2 -(Black)" ¿Í ¿¬°á ÇÕ´Ï´Ù. - ¿©±â¼ ¸ðÅÍ °á¼±À» À߸øÇÏ¸é ½ºÄÉÄ¡¸¦ ¾÷·Îµå Çϰí Å×½ºÆ®¸¦ ÇÒ¶§ ¸ðÅͰ¡ ¹Ý´ë·Î µ¿ÀÛ ÇÒ ¼ö ÀÖ½À´Ï´Ù. - ¹èÅ͸® ¿¬°á¼±µµ ¸¶Âù°¡Áö·Î "¹èÅ͸® ¹Ú½º¿¡ ¿¬°áµÈ ºÓÀº»ö ¼±À» "¹èÅ͸®(Red)+" "¹èÅ͸® ¹Ú½º¿¡ ¿¬°áµÈ °ËÀº»ö ¼±À» "¹èÅ͸®(Black)-" ¿Í ¿¬°á ÇÕ´Ï´Ù. - ³ªÁß¿¡ ÁÖÇà ·Îº¿ Å×½ºÆ®¸¦ ÇÒ¶§´Â Àü¿ø°ø±Þ, ÃæÀü ½ºÀ§Ä¡¸¦ "TAB" À§Ä¡·Î ÇØ¼ »ç¿ëÀ» ÇØ¾ß ÇÕ´Ï´Ù. |
|||
![]() |
|||
2.4 ¾ÆµÎÀ̳ë ÄÁÆ®·Ñ º¸µå¿Í ¸ðÅÍ Á¦¾î ¹è¼± ¿¬°á |
|||
- ¾Ï/¾Ï Á¡ÇÁ ¿ÍÀ̾ ÀÌ¿ëÇØ¼ ¾Æ·¡ ±×¸²À» º¸°í ¿ÍÀÌ¾î ¿¬°áÀ» ÇÕ´Ï´Ù. - ¸ðÅÍ EA, EB Æ÷Æ®¿¡ ÀÖ´Â Á¡ÆÛ´Â Á¦°Å ÇÕ´Ï´Ù. |
|||
![]() |
|||
2.5 ¾ÆµÎÀ̳ë ȣȯ º¸µå ȯ°æ ¼³Á¤ |
|||
- º» Á¦Ç°Àº ¾ÆµÎÀ̳ëÀÇ ÀÔÃâ·Â Æ÷Æ®¸¦ ´õ ¸¹ÀÌ »ç¿ëÇϱâ À§Çؼ Atmega64
±â¹ÝÀÇ ¸¶ÀÌÅ©·ÎÄÁÆ®·Ñ·¯¸¦ »ç¿ë ÇÏ¿´½À´Ï´Ù. - ¾ÆµÎÀÌ³ë °³¹ßȯ°æ¿¡´Â ±âº»ÀûÀ¸·Î Áö¿øÀ» ÇÏÁö ¾Ê±â ¶§¹®Ã¼ ȣȯ º¸µå¸¦ Ãß°¡ÇÏ´Â ÀýÂ÷°¡ ÇÊ¿ä ÇÕ´Ï´Ù. - ¾Æ·¡ ÀýÂ÷´ë·Î ¾ÆµÎÀ̳밡 ¼³Ä¡µÈ Æú´õÀÇ boards.txt ÆÄÀÏÀ» º¯°æÇØ¾ß ÇÕ´Ï´Ù. - - boards.txt ÆÄÀÏÀ» º¯°æÇÑ´Ù°í ÇØ¼ ¾ÆµÎÀÌ³ë ±âº» º¸µåµéÀ» »ç¿ëÇÏÁö ¸øÇÏ´Â °ÍÀº ¾Æ´Ï°í, ȣȯ º¸µå°¡ »õ·Î Ãß°¡¸¸ µÇ´Â °ÍÀÔ´Ï´Ù. |
|||
![]() |
|||
- ¾ÆµÎÀ̳ë Çϵå¿þ¾îÀÇ Variant ÆÄÀÏ Ãß°¡ - ÆÄÀϵéÀ» ÅØ½ºÆ® ¿¡µðÅÍ·Î ¿¾î¼ ºñ±³ÇØ º¸¸é ¾ÆµÎÀÌ³ë ±âº» º¸µå¿Í IO Æ÷Æ®ÀÇ °¹¼ö¿Í ŸÀÌ¸Ó ¼³Á¤µîÀÌ ´Ù¸¥°ÍÀ» º¼¼ö ÀÖ½À´Ï´Ù. - linetracer.zip ÆÄÀÏ ´Ù¿î·Îµå |
|||
![]() |
|||
2.6 ȣȯ º¸µå ¼±Åà |
|||
- ¾ÆµÎÀÌ³ë °³¹ßȯ°æ¿¡¼ "Åø/º¸µå/Arduino Line Tracer" º¸µå¸¦ ¼±Åà ÇÕ´Ï´Ù. | |||
![]() |
|||
2.7 L293D ¸ðÅÍ µå¶óÀ̹ö IC |
|||
- 5V DC ¸ðÅ͸¦ ¾ÆµÎÀ̳뿡¼ Á÷Á¢ Á¦¾îÇÒ ¼öµµ ÀÖÁö¸¸, ÀÌ·¸°Ô ÇÏ¸é ½ºÄÉÄ¡ Äڵ嵵 º¹ÀâÇØ Áö°í ÃÖ´ë Ãâ·ÂÀÌ ¾àÇØÁö±â ¶§¹®¿¡ ¸ðÅ͸¦ Á¦¾îÇÏ´Â Àü¿ë µå¶óÀ̹ö IC¸¦ »ç¿ë ÇÏ¿´½À´Ï´Ù. | |||
![]() |
|||
2.8 L293D ¸ðÅÍ µå¶óÀ̹ö IC »ç¿ë ¼³¸í |
|||
- ¾ÆµÎÀÌ³ë º¸µåÀÇ ¸ðÅÍ ENA°¡ Motor1 EnableÇÉ
ÀÔ´Ï´Ù. - ¾ÆµÎÀÌ³ë º¸µåÀÇ ¸ðÅÍ ENB°¡ Motor2 EnableÇÉ ÀÔ´Ï´Ù. - ´õ ÀÚ¼¼ÇÑ ¼³¸íÀº ¾Æ·¡ Ç¥¸¦ ÂüÁ¶Çϼ¼¿ä. |
|||
![]() |
|||
![]() |
|||
2.9 DC ¸ðÅÍ Á¦¾î ¿¹Á¦ |
|||
- ¾ÆµÎÀÌ³ë ½Ã¸®¾ó ¸ð´ÏÅÍ¿¡¼ ¾Æ·¡ µ¥ÀÌÅ͸¦ ÀÔ·ÂÇØ¼ DC ¸ðÅ͸¦ Á¦¾î ÇÕ´Ï´Ù. 'F' - ¿ÞÂÊ, ¿À¸¥ÂÊ ¸ðÅ͸¦ Á¤¹æÇâ À¸·Î ȸÀü 'B' - ¿ÞÂÊ, ¿À¸¥ÂÊ ¸ðÅ͸¦ ¿ª¹æÇâ À¸·Î ȸÀü 'L' - ¿ÞÂÊ ¸ðÅ͸¦ Á¤¹æÇâ À¸·Î ȸÀü 'R' - ¿À¸¥ÂÊ ¸ðÅ͸¦ ¿ª¹æÇâ À¸·Î ȸÀü 'S' - ¿ÞÂÊ, ¿À¸¥ÂÊ ¸ðÅÍ Á¤Áö - DC¸ð ÅÍ Á¦¾î ½ºÄÉÄ¡ ´Ù¿î·Îµå |
|||
#include <Servo.h> Servo myservo; int pos = 0; // variable to store the servo position #define trigPin 11 #define echoPin 10 #define servoPin 13 // for Car const int MOTO1_EN_PIN = 14; // Left wheel const int MOTO2_EN_PIN = 15; // right wheel int gbl_cur_motor_speed = 140; // motor speed // ¿ÞÂÊ ¸ðÅÍ È¸Àü ¹æÇâ const int I11_PIN = 16; // In1 const int I12_PIN = 17; // In2 // ¿À¸¥ÂÊ ¸ðÅÍ È¸Àü ¹æÇâ const int I21_PIN = 18; // In3 const int I22_PIN = 19; // In4 void setup() { Serial.begin(9600); delay(100); myservo.attach(servoPin); pinMode(MOTO1_EN_PIN, OUTPUT); pinMode(MOTO2_EN_PIN, OUTPUT); pinMode(I11_PIN, OUTPUT); pinMode(I12_PIN, OUTPUT); pinMode(I21_PIN, OUTPUT); pinMode(I22_PIN, OUTPUT); } void car_forward(int moto_speed) { digitalWrite(I11_PIN, LOW); digitalWrite(I12_PIN, HIGH); digitalWrite(I21_PIN, LOW); digitalWrite(I22_PIN, HIGH); // motion analogWrite(MOTO1_EN_PIN, moto_speed); analogWrite(MOTO2_EN_PIN, moto_speed); } void car_backward(int moto_speed) { digitalWrite(I11_PIN, HIGH); digitalWrite(I12_PIN, LOW); digitalWrite(I21_PIN, HIGH); digitalWrite(I22_PIN, LOW); // motion analogWrite(MOTO1_EN_PIN, moto_speed); analogWrite(MOTO2_EN_PIN, moto_speed); } void car_left(int moto_speed) { digitalWrite(I21_PIN, LOW); digitalWrite(I22_PIN, HIGH); // motion analogWrite(MOTO1_EN_PIN, 0); analogWrite(MOTO2_EN_PIN, moto_speed); } void car_right(int moto_speed) { digitalWrite(I11_PIN, LOW); digitalWrite(I12_PIN, HIGH); // motion analogWrite(MOTO1_EN_PIN, moto_speed); analogWrite(MOTO2_EN_PIN, 0); } void car_stop() { digitalWrite(I11_PIN, LOW); digitalWrite(I12_PIN, LOW); digitalWrite(I21_PIN, LOW); digitalWrite(I22_PIN, LOW); // motion analogWrite(MOTO1_EN_PIN, 0); analogWrite(MOTO2_EN_PIN, 0); } /* void serialEvent(){ char text = Serial.read(); Serial.print("data : "); Serial.println(text); } */ void loop() { int cmd ; if( Serial.available() > 0 ) { myservo.write(120); cmd = Serial.read(); if( cmd == 'L' ) { car_left(gbl_cur_motor_speed); Serial.println("Left"); } else if( cmd == 'R' ) { car_right(gbl_cur_motor_speed); Serial.println("Right"); } else if( cmd == 'F' ) { car_forward(gbl_cur_motor_speed); Serial.println("Forward"); } else if( cmd == 'B' ) { car_backward(gbl_cur_motor_speed); Serial.println("Backward"); } else if( cmd == 'S' ) { car_stop(); Serial.println("Stop"); } } delay(20); } |
|||
2.10 ¾ÆµÎÀÌ³ë ºí·çÅõ½º Åë½Å |
|||
- ºí·çÅõ½º ¸ðµâÀ» SPP(Serial Port Profile) ±â´ÉÀÌ ÀÖ´Â Á¦Ç°À» »ç¿ëÇÑ´Ù¸é ¾ÆµÎÀ̳뿡¼ ºí·çÅõ½º Åë½ÅÀ» ÇÏ´Â ¹æ¹ýÀº ½Ã¸®¾ó Åë½ÅÀ»ÇÏ´Â ¹æ¹ý°ú µ¿ÀÏ ÇÕ´Ï´Ù. ÃÖ±Ù¿¡ ¸¹ÀÌ »ç¿ëµÇ°í ÀÖ´Â HC-06 ¸ðµâÀ» »ç¿ë ÇÏ¿´½À´Ï´Ù. | |||
![]() |
|||
- HC-06 ºí·çÅõ½º ¸ðµâÀ» USB ÄɳØÅÍ ¹Ù·Î¾ÕÀÇ ¼ÒÄÏ¿¡ ¿¬°á ÇÕ´Ï´Ù. | |||
![]() |
|||
![]() |
|||
- ÀÌÁ¦ ¾Èµå·ÎÀÌµå ½º¸¶Æ®Æù¿¡¼ ºí·çÅõ½º ÄÁÆ®·Ñ ¾ÛÀ» ´Ù¿î·ÎµåÇÏ°í ¼³Ä¡ ÇÕ´Ï´Ù. - ¿©±â¼´Â ÀÌ¹Ì ±¸±Û Ç÷¹ÀÌ ½ºÅä¾î¿¡ ¸¹ÀÌ ¿Ã¶ó¿Í ÀÖ´Â ±âº» ¾ÛÀ» »ç¿ëÇϵµ·Ï ÇÒ°Ô¿ä. - ºí·çÅõ½º Á¦¾î ¿¹Á¦ÀÇ ¾Èµå·ÎÀÌµå ¼Ò½º°¡ ÇÊ¿äÇϽŠºÐµéÀº master@deviceshop.net ¸ÞÀÏ·Î ¿äûÀ» ÇØÁÖ½Ã¸é º¸³»µå¸±°Ô¿ä. |
|||
![]() |
|||
- ÀåÄ¡ °Ë»öÀ» ÇØ¼ ¾ÆµÎÀÌ³ë ºí·çÅõ½º HC-06 ¸ðµâ°ú Æä¾î¸µÀ» ÇÕ´Ï´Ù. | |||
![]() |
|||
- Ãʱâ ÇÉ ¹øÈ£´Â "1234" ÀÔ´Ï´Ù. | |||
![]() |
|||
- " Ű ¼³Á¤" ¹öưÀ» ´·¯¼ 9°³ÀÇ ¹öư¿¡ ۸¦ ÇÒ´ç ÇÕ´Ï´Ù. - ´ë/¼Ò ¹®ÀÚ¸¦ ±¸ºÐÀ» ÇϹǷΠ¹Ýµå½Ã ´ë¹®ÀÚ·Î ÇÒ´ç Çϼ¼¿ä. |
|||
![]() |
|||
- ¾ÆµÎÀ̳ëÀÇ ½ºÄÉÄ¡ ¿¹Á¦´Â ½Ã¸®¾ó Åë½ÅÀ¸·Î ÇÏ´Â DC¸ðÅÍ Á¦¾î
½ºÄÉÄ¡¿Í µ¿ÀÏ ÇÕ´Ï´Ù. - DC¸ð ÅÍ Á¦¾î ½ºÄÉÄ¡ ´Ù¿î·Îµå |
|||
![]() |
|||
2.11 Àû¿Ü¼± ¶óÀÌÆ®·¹ÀÌ½Ì |
|||
- 3°³ÀÇ Àû¿Ü¼± Æ®·¹ÀÌ½Ì ¼¾¼¸¦ ¿¬°á ÇÕ´Ï´Ù. - ¾Æ·¡ ±×¸²¿¡¼ ¼¾¼°¡ °ËÀº»öÀ» ÀνÄÇÏ¸é ¾ÆµÎÀÌ³ë µðÁöÅÐ Æ÷Æ®¿¡ "HIGH" °¡ µÈ´Ù°í Çߴµ¥, ½ÇÁ¦ Å×½ºÆ®°á°ú "LOW" °¡ ¸Â´Â³×¿ä. ÁÖÀÇÇØ¼ ½ºÄÉÄ¡ Äڵ带 º¸¾Æ¾ß ÇÒ°Í °°½À´Ï´Ù. |
|||
![]() |
|||
- ¶óÀÎÆ®·¹ÀÌ½Ì ½ºÄÉÄ¡ ÄÚµå - ¶ó ÀÎÆ®·¹ÀÌ½Ì ½ºÄÉÄ¡ ´Ù¿î·Îµå |
|||
#define trigPin 11 #define echoPin 10 #define servoPin 13 #include <Servo.h> Servo myservo; int pos = 0; // variable to store the servo position const int MOTO1_EN_PIN = 14; // Left wheel const int MOTO2_EN_PIN = 15; // right wheel // ¿ÞÂÊ ¸ðÅÍ È¸Àü ¹æÇâ const int I11_PIN = 16; // In1 const int I12_PIN = 17; // In2 // ¿À¸¥ÂÊ ¸ðÅÍ È¸Àü ¹æÇâ const int I21_PIN = 18; // In3 const int I22_PIN = 19; // In4 // int MOTO_SPEED = 110; int MOTO_SPEED_L = 50; int MOTO_SPEED_R = 50; int MOTO_SPEED = 150; int MOTO_SPEED_L1 = MOTO_SPEED-30; int MOTO_SPEED_L2 = MOTO_SPEED-50; int IR_L = 3; // ¿ÞÂÊ Àû¿Ü¼± ¼¾¼ int IR_M = 4; // °¡¿îµ¥ Àû¿Ü¼± ¼¾¼ int IR_R = 5; // ¿À¸¥ÂÊ Àû¿Ü¼± ¼¾¼ int last_status = 'S'; void setup() { Serial.begin(9600); delay(100); myservo.attach(servoPin); pinMode(MOTO1_EN_PIN, OUTPUT); pinMode(MOTO2_EN_PIN, OUTPUT); pinMode(I11_PIN, OUTPUT); pinMode(I12_PIN, OUTPUT); pinMode(I21_PIN, OUTPUT); pinMode(I22_PIN, OUTPUT); } void car_forward(int moto_speed) { digitalWrite(I11_PIN, LOW); digitalWrite(I12_PIN, HIGH); digitalWrite(I21_PIN, LOW); digitalWrite(I22_PIN, HIGH); // motion analogWrite(MOTO1_EN_PIN, moto_speed); analogWrite(MOTO2_EN_PIN, moto_speed); delay(10); } void car_lf_rf(int moto_speed_left, int moto_speed_right) { // car_stop(); // left wheel digitalWrite(I11_PIN, LOW); digitalWrite(I12_PIN, HIGH); // right wheel digitalWrite(I21_PIN, LOW); digitalWrite(I22_PIN, HIGH); // motion analogWrite(MOTO1_EN_PIN, moto_speed_left); analogWrite(MOTO2_EN_PIN, moto_speed_right); } void car_stop() { digitalWrite(I11_PIN, LOW); digitalWrite(I12_PIN, LOW); digitalWrite(I21_PIN, LOW); digitalWrite(I22_PIN, LOW); // motion analogWrite(MOTO1_EN_PIN, 0); analogWrite(MOTO2_EN_PIN, 0); } void loop() { int r,m,l; myservo.write(128); r = digitalRead(IR_R); m = digitalRead(IR_M); l = digitalRead(IR_L); // LOWÀ϶§ °ËÀº»öÀÌ °ËÃâµÈ´Ù. if((l==HIGH) && (m==LOW) && (r==HIGH)) { car_forward(MOTO_SPEED); //retry = 0; } else if((l==LOW) && (m==LOW) && (r==LOW)) { car_forward(MOTO_SPEED); //retry = 0; } else if((l==LOW) && (m==HIGH) && (r==HIGH)) { // car_left(MOTO_SPEED); car_lf_rf(MOTO_SPEED_L2, MOTO_SPEED); last_status = 'L'; //retry = 0; Serial.println("Right"); } else if((l==LOW) && (m==LOW) && (r==HIGH)) { car_lf_rf(MOTO_SPEED_L1, MOTO_SPEED); last_status = 'L'; //retry = 0; Serial.println("Left"); } else if((l==HIGH) && (m==HIGH) && (r==LOW)) { //car_right(MOTO_SPEED); car_lf_rf(MOTO_SPEED, MOTO_SPEED_L2); last_status = 'R'; //retry = 0; Serial.println("Right"); } else if((l==HIGH) && (m==LOW) && (r==LOW)) { car_lf_rf(MOTO_SPEED, MOTO_SPEED_L1); last_status = 'R'; //retry = 0; Serial.println("Right"); } else if((l==HIGH) && (m==HIGH) && (r==HIGH)) { car_stop(); } // delay(2); } |
|||
2.12 ¼º¸¸ðÅÍ Á¦¾î |
|||
- ¾ÆµÎÀÌ³ë µðÁöÅÐ 13¹ø Æ÷Æ®¿¡ ¿¬°á ÇÕ´Ï´Ù. | |||
![]() |
|||
- ¼º¸¸ðÅÍ Á¦¾î ½ºÄÉÄ¡ ÄÚµå - ¼º¸ ¸ðÅÍ ½ºÄÉÄ¡ ´Ù¿î·Îµå |
|||
#include <Servo.h> #define servoPin 13 Servo myservo; int pos = 0; // variable to store the servo position void setup() { myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object } void loop() { for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } |
|||
2.13 ÃÊÀ½ÆÄ ¼¾¼ Á¦¾î |
|||
- ¾ÆµÎÀÌ³ë µðÁöÅÐ Æ÷Æ® 10, 11¿¡ ¿¬°á ÇÕ´Ï´Ù. | |||
![]() |
|||
- ÃÊÀ½ÆÄ¼¾¼ Á¦¾î ½ºÄÉÄ¡ ÄÚµå - ÃÊÀ½ ÆÄ¼¾¼ Á¦¾î ½ºÄÉÄ¡ ´Ù¿î·Îµå |
|||
#define trigPin 11 #define echoPin 10 #define servoPin 13 #include <Servo.h> Servo myservo; int pos = 0; // variable to store the servo position void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); myservo.attach(servoPin); } long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; } int GetCentiMeter() { long duration, cm; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); // convert the time into a distance cm = microsecondsToCentimeters(duration); return cm; } void loop() { long cm; for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' cm = GetCentiMeter(); Serial.print(cm); Serial.println(" cm"); } for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' cm = GetCentiMeter(); Serial.print(cm); Serial.println(" cm"); } } |
|||
¿©±â±îÁö ÁÖÇà ·Îº¿ Á¦¾î¸¦ À§ÇÑ ¹è¼±µµ¿Í ¿¹Á¦ Äڵ带 »ìÆì º¸¾Ò½À´Ï´Ù. Ãß°¡·Î Áú¹®»çÇ×À̳ª ¿äû »çÇ×ÀÌ ÀÖÀ¸½Ã¸é http://cafe.naver.com/avrstudio ³ª master@deviceshop.net ·Î ¹®ÀÇÇØ ÁÖ¼¼¿ä. Áñ ¾ÆµÎÀ̳ë Çϼ¼¿ä.. ¤» |