วันจันทร์ที่ 23 กรกฎาคม พ.ศ. 2561

หุ่นยนต์หลบสิ่งกีดขวาง2

// ---------------------------------------------------------------------------
// NewPing Library - v1.7 - 09/29/2015
//
// AUTHOR/LICENSE:
// Created by Tim Eckel - teckel@leethost.com
// Copyright 2015 License: GNU GPL v3 http://www.gnu.org/licenses/gpl.html
//
// LINKS:
// Project home: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
// Blog: http://arduino.cc/forum/index.php/topic,106043.0.html
//
// DISCLAIMER:
// This software is furnished "as is", without technical support, and with no
// warranty, express or implied, as to its usefulness for any purpose.
//
// BACKGROUND:
// When I first received an ultrasonic sensor I was not happy with how poorly
// it worked. Quickly I realized the problem wasn't the sensor, it was the
// available ping and ultrasonic libraries causing the problem. The NewPing
// library totally fixes these problems, adds many new features, and breaths
// new life into these very affordable distance sensors.
//
// FEATURES:
// * Works with many different ultrasonic sensors: SR04, SRF05, SRF06, DYP-ME007, URM37 & Parallax PING)))™.
// * Compatible with the entire Arduino line-up, Teensy family (including $19 96Mhz 32 bit Teensy 3.0) and derivatives.
// * Interface with all but the SRF06 sensor using only one Arduino pin.
// * Doesn't lag for a full second if no ping/echo is received.
// * Ping sensors consistently and reliably at up to 30 times per second.
// * Timer interrupt method for event-driven sketches.
// * Built-in digital filter method ping_median() for easy error correction.
// * Uses port registers for a faster pin interface and smaller code size.
// * Allows you to set a maximum distance where pings beyond that distance are read as no ping "clear".
// * Ease of using multiple sensors (example sketch with 15 sensors).
// * More accurate distance calculation (cm, inches & uS).
// * Doesn't use pulseIn, which is slow and gives incorrect results with some ultrasonic sensor models.
// * Actively developed with features being added and bugs/issues addressed.
//
// CONSTRUCTOR:
//   NewPing sonar(trigger_pin, echo_pin [, max_cm_distance])
//     trigger_pin & echo_pin - Arduino pins connected to sensor trigger and echo.
//       NOTE: To use the same Arduino pin for trigger and echo, specify the same pin for both values.
//     max_cm_distance - [Optional] Maximum distance you wish to sense. Default=500cm.
//
// SYNTAX:
//   sonar.ping() - Send a ping and get the echo time (in microseconds) as a result.
//   sonar.ping_in() - Send a ping and get the distance in whole inches.
//   sonar.ping_cm() - Send a ping and get the distance in whole centimeters.
//   sonar.ping_median(iterations) - Do multiple pings (default=5), discard out of range pings and return median in microseconds.
//   sonar.convert_in(echoTime) - Convert echoTime from microseconds to inches (rounds to nearest inch).
//   sonar.convert_cm(echoTime) - Convert echoTime from microseconds to centimeters (rounds to nearest cm).
//   sonar.ping_timer(function) - Send a ping and call function to test if ping is complete.
//   sonar.check_timer() - Check if ping has returned within the set distance limit.
//   NewPing::timer_us(frequency, function) - Call function every frequency microseconds.
//   NewPing::timer_ms(frequency, function) - Call function every frequency milliseconds.
//   NewPing::timer_stop() - Stop the timer.
//
// HISTORY:
// 09/29/2015 v1.7 - Removed support for the Arduino Due and Zero because
//   they're both 3.3 volt boards and are not 5 volt tolerant while the HC-SR04
//   is a 5 volt sensor.  Also, the Due and Zero don't support pin manipulation
//   compatibility via port registers which can be done (see the Teensy 3.2).
//
// 06/17/2014 v1.6 - Corrected delay between pings when using ping_median()
//   method. Added support for the URM37 sensor (must change URM37_ENABLED from
//   false to true). Added support for Arduino microcontrollers like the $20
//   32 bit ARM Cortex-M4 based Teensy 3.2. Added automatic support for the
//   Atmel ATtiny family of microcontrollers. Added timer support for the
//   ATmega8 microcontroller. Rounding disabled by default, reduces compiled
//   code size (can be turned on with ROUNDING_ENABLED switch). Added
//   TIMER_ENABLED switch to get around compile-time "__vector_7" errors when
//   using the Tone library, or you can use the toneAC, NewTone or
//   TimerFreeTone libraries: https://bitbucket.org/teckel12/arduino-toneac/
//   Other speed and compiled size optimizations.
//
// 08/15/2012 v1.5 - Added ping_median() method which does a user specified
//   number of pings (default=5) and returns the median ping in microseconds
//   (out of range pings ignored). This is a very effective digital filter.
//   Optimized for smaller compiled size (even smaller than sketches that
//   don't use a library).
//
// 07/14/2012 v1.4 - Added support for the Parallax PING)))™ sensor. Interface
//   with all but the SRF06 sensor using only one Arduino pin. You can also
//   interface with the SRF06 using one pin if you install a 0.1uf capacitor
//   on the trigger and echo pins of the sensor then tie the trigger pin to
//   the Arduino pin (doesn't work with Teensy). To use the same Arduino pin
//   for trigger and echo, specify the same pin for both values. Various bug
//   fixes.
//
// 06/08/2012 v1.3 - Big feature addition, event-driven ping! Uses Timer2
//   interrupt, so be mindful of PWM or timing conflicts messing with Timer2
//   may cause (namely PWM on pins 3 & 11 on Arduino, PWM on pins 9 and 10 on
//   Mega, and Tone library). Simple to use timer interrupt functions you can
//   use in your sketches totally unrelated to ultrasonic sensors (don't use if
//   you're also using NewPing's ping_timer because both use Timer2 interrupts).
//   Loop counting ping method deleted in favor of timing ping method after
//   inconsistent results kept surfacing with the loop timing ping method.
//   Conversion to cm and inches now rounds to the nearest cm or inch. Code
//   optimized to save program space and fixed a couple minor bugs here and
//   there. Many new comments added as well as line spacing to group code
//   sections for better source readability.
//
// 05/25/2012 v1.2 - Lots of code clean-up thanks to Arduino Forum members.
//   Rebuilt the ping timing code from scratch, ditched the pulseIn code as it
//   doesn't give correct results (at least with ping sensors). The NewPing
//   library is now VERY accurate and the code was simplified as a bonus.
//   Smaller and faster code as well. Fixed some issues with very close ping
//   results when converting to inches. All functions now return 0 only when
//   there's no ping echo (out of range) and a positive value for a successful
//   ping. This can effectively be used to detect if something is out of range
//   or in-range and at what distance. Now compatible with Arduino 0023.
//
// 05/16/2012 v1.1 - Changed all I/O functions to use low-level port registers
//   for ultra-fast and lean code (saves from 174 to 394 bytes). Tested on both
//   the Arduino Uno and Teensy 2.0 but should work on all Arduino-based
//   platforms because it calls standard functions to retrieve port registers
//   and bit masks. Also made a couple minor fixes to defines.
//
// 05/15/2012 v1.0 - Initial release.
// ---------------------------------------------------------------------------

#ifndef NewPing_h
#define NewPing_h

#if defined (ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#endif

#if defined (__AVR__)
#include <avr/io.h>
#include <avr/interrupt.h>
#endif

// Shouldn't need to change these values unless you have a specific need to do so.
#define MAX_SENSOR_DISTANCE 500 // Maximum sensor distance can be as high as 500cm, no reason to wait for ping longer than sound takes to travel this distance and back. Default=500
#define US_ROUNDTRIP_CM 57      // Microseconds (uS) it takes sound to travel round-trip 1cm (2cm total), uses integer to save compiled code space. Default=57
#define US_ROUNDTRIP_IN 146     // Microseconds (uS) it takes sound to travel round-trip 1 inch (2 inches total), uses integer to save compiled code space. Defalult=146
#define ONE_PIN_ENABLED true    // Set to "false" to disable one pin mode which saves around 14-26 bytes of binary size. Default=true
#define ROUNDING_ENABLED false  // Set to "true" to enable distance rounding which also adds 64 bytes to binary size. Default=false
#define URM37_ENABLED false     // Set to "true" to enable support for the URM37 sensor in PWM mode. Default=false
#define TIMER_ENABLED true      // Set to "false" to disable the timer ISR (if getting "__vector_7" compile errors set this to false). Default=true

// Probably shouldn't change these values unless you really know what you're doing.
#define NO_ECHO 0               // Value returned if there's no ping echo within the specified MAX_SENSOR_DISTANCE or max_cm_distance. Default=0
#define MAX_SENSOR_DELAY 5800   // Maximum uS it takes for sensor to start the ping. Default=5800
#define ECHO_TIMER_FREQ 24      // Frequency to check for a ping echo (every 24uS is about 0.4cm accuracy). Default=24
#define PING_MEDIAN_DELAY 29000 // Microsecond delay between pings in the ping_median method. Default=29000
#define PING_OVERHEAD 5         // Ping overhead in microseconds (uS). Default=5
#define PING_TIMER_OVERHEAD 13  // Ping timer overhead in microseconds (uS). Default=13
#if URM37_ENABLED == true
#undef  US_ROUNDTRIP_CM
#undef  US_ROUNDTRIP_IN
#define US_ROUNDTRIP_CM 50    // Every 50uS PWM signal is low indicates 1cm distance. Default=50
#define US_ROUNDTRIP_IN 127   // If 50uS is 1cm, 1 inch would be 127uS (50 x 2.54 = 127). Default=127
#endif

// Conversion from uS to distance (round result to nearest cm or inch).
#define NewPingConvert(echoTime, conversionFactor) (max(((unsigned int)echoTime + conversionFactor / 2) / conversionFactor, (echoTime ? 1 : 0)))

// Detect non-AVR microcontrollers (Teensy 3.x, Arduino DUE, etc.) and don't use port registers or timer interrupts as required.
#if (defined (__arm__) && defined (TEENSYDUINO))
#undef  PING_OVERHEAD
#define PING_OVERHEAD 1
#undef  PING_TIMER_OVERHEAD
#define PING_TIMER_OVERHEAD 1
#elif !defined (__AVR__)
#undef  PING_OVERHEAD
#define PING_OVERHEAD 1
#undef  PING_TIMER_OVERHEAD
#define PING_TIMER_OVERHEAD 1
#undef  TIMER_ENABLED
#define TIMER_ENABLED false
#endif

// Disable the timer interrupts when using ATmega128 and all ATtiny microcontrollers.
#if defined (__AVR_ATmega128__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny261__) || defined(__AVR_ATtiny461__) || defined(__AVR_ATtiny861__) || defined(__AVR_ATtiny43U__)
#undef  TIMER_ENABLED
#define TIMER_ENABLED false
#endif

// Define timers when using ATmega8 microcontrollers.
#if defined (__AVR_ATmega8__)
#define OCR2A OCR2
#define TIMSK2 TIMSK
#define OCIE2A OCIE2
#endif

class NewPing {
public:
NewPing(uint8_t trigger_pin, uint8_t echo_pin, unsigned int max_cm_distance = MAX_SENSOR_DISTANCE);
unsigned int ping();
unsigned long ping_cm();
unsigned long ping_in();
unsigned long ping_median(uint8_t it = 5);
unsigned int convert_cm(unsigned int echoTime);
unsigned int convert_in(unsigned int echoTime);
#if TIMER_ENABLED == true
void ping_timer(void (*userFunc)(void));
boolean check_timer();
unsigned long ping_result;
static void timer_us(unsigned int frequency, void (*userFunc)(void));
static void timer_ms(unsigned long frequency, void (*userFunc)(void));
static void timer_stop();
#endif
private:
boolean ping_trigger();
#if TIMER_ENABLED == true
boolean ping_trigger_timer(unsigned int trigger_delay);
boolean ping_wait_timer();
static void timer_setup();
static void timer_ms_cntdwn();
#endif
uint8_t _triggerBit;
uint8_t _echoBit;
volatile uint8_t *_triggerOutput;
volatile uint8_t *_echoInput;
volatile uint8_t *_triggerMode;
unsigned int _maxEchoTime;
unsigned long _max_time;
};


#endif

2-way morot speed sensor เซนเซอร์ infrared วัดความเร็วรอบ speed counter สำหรับ Smart Car

2-way morot speed sensor เซนเซอร์ infrared วัดความเร็วรอบ speed counter สำหรับ Smart Car

2-way morot speed sensor เซนเซอร์ infrared วัดความเร็วรอบ speed counter สำหรับ Smart Car

เซนเซอร์วัดความเร็วรอบ speed counter สำหรับ Smart Car
เซนเซอร์แสง ให้สัญญาณเอาต์พุตเป็นแบบดิจิตอลค่า 1 เมื่อมีวัตถุผ่านเซนเซอร์พร้อม LED แสดงผล ใช้ไฟเลี้ยง 3.3-5V
ปรับความไวการตรวจจับได้ที่ตัวต้านทานปรับค่าได้บนบอร์ด เหมาะสำหรับนับความเร็วรอบ smart car
ตัวอย่างโคดทดลอง Arduino Speed counter 
int sp1 = 2;
int sp2 = 3;
int count_sp1 = 0;
int count_sp2 = 0;
void setup() {
pinMode(sp1, INPUT);
pinMode(sp2, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(sp1) == 1) {
count_sp1++;
Serial.print("speed1 = "); Serial.println(count_sp1);
}
if (digitalRead(sp2) == 1) {
count_sp2++;
Serial.print("speed2 = "); Serial.println(count_sp2);
}
}




โปรเจค หุ่นยนต์เดินตาม เปลวไฟ Fire Extinguis

โปรเจค หุ่นยนต์เดินตาม เปลวไฟ Fire Extinguisher





โปรเจค หุ่นยนต์เดินตาม-เปลวไฟ 
อุปกรณ์ที่ต้องใช้ก็คือ

     1. 2WD Smart Robot Car Chassis Kits

     2. Arduino UNO R3 - Made in italy

     3. Arduino Sensor Shield V5.0

     4. Motor Drive Module L298N

     5. สาย Jumper Female to Male ยาว 20cm.

     6. สาย Jumper Female to Female ยาว 20cm.

     7. รางถ่านแบบ 18650 ใส่ถ่าน 2 ก้อน

     8. แบตเตอรี่ลิเธียม 18650 จำนวน 2 ก้อน

     9. เสารองแผ่นพีซีบีแบบโลหะ ยาว 25 มม.

     10. สกรูหัวกลมน็อตตัวเมีย ขนาด 3มม ยาว10มม.
 
     11. 5 Way Fire Extinguisher Sensor เซ็นเซอร์ตรวจจับเปลวไฟ


เริ่มต้นด้วยการ ประกอบ 2WD Smart Car Robot Chassis Kits และประกอบ รางถ่านแบบ 18650 และ เชื่อมต่อ Motor Drive Module L298N  เข้ากับ Arduino Sensor Shield V 5.0 วงจรตามรูป

หมายเหตุ : ถ้ามี Jumper อยู่ที่ขา ENA และ ENB ของ บอร์ด L298N  ให้ถอดออก

การเชื่อมต่อระหว่าง บอร์ด Arduino Sensor Shield V5.0 กับ บอร์ด L298N  

*** VCC ของ  Sensor Shield V5.0   คือ  V ***



ประกอบ 2WD Smart Car Robot Chassis Kits และประกอบ รางถ่านแบบ 18650 และ เชื่อมต่อ 5V และ GND ของ Motor Drive Module L298N  เข้ากับ V และ G ของ Arduino Sensor Shield 





เชื่อมต่อการควบคุมมอเตอร์ ของ Motor Drive Module L298N  เข้ากับ  Arduino Sensor Shield




หลังจากนั้นให้ทดสอบเบื้องต้น ว่าการหมุนของล้อถูกต้องหรือไม่ โดย

เปิดโปรแกรม Arduino (IDE) และ Upload โค้ดนี้ ไปยัง บอร์ด Arduino UNO R3



// Motor A pins (enableA = enable motor, pinA1 = forward, pinA2 = backward)
int enableA = 3;
int pinA1 = 6;
int pinA2 = 7;

//Motor B pins (enabledB = enable motor, pinB2 = forward, pinB2 = backward)
int enableB = 5;
int pinB1 = 8;
int pinB2 = 9;

//This lets you run the loop a single time for testing
boolean run = true;

void setup() {
 pinMode(enableA, OUTPUT);
 pinMode(pinA1, OUTPUT);
 pinMode(pinA2, OUTPUT);

 pinMode(enableB, OUTPUT);
 pinMode(pinB1, OUTPUT);
 pinMode(pinB2, OUTPUT);
}
void loop() {
  if (run) {
    delay(2000);
    enableMotors();
    //Go forward
    forward(200);
    //Go backward
    backward(200);
    //Turn left
    turnLeft(400);
    coast(200);
    //Turn right
    turnRight(400);
    coast(200);
    //This stops the loop
    run = false; 
  }
}

//Define high-level H-bridge commands

void enableMotors()
{
 motorAOn();
 motorBOn();
}

void disableMotors()
{
 motorAOff();
 motorBOff();
}

void forward(int time)
{
 motorAForward();
 motorBForward();
 delay(time);
}

void backward(int time)
{
 motorABackward();
 motorBBackward();
 delay(time);
}

void turnLeft(int time)
{
 motorABackward();
 motorBForward();
 delay(time);
}

void turnRight(int time)
{
 motorAForward();
 motorBBackward();
 delay(time);
}

void coast(int time)
{
 motorACoast();
 motorBCoast();
 delay(time);
}

void brake(int time)
{
 motorABrake();
 motorBBrake();
 delay(time);
}
//Define low-level H-bridge commands

//enable motors
void motorAOn()
{
 digitalWrite(enableA, HIGH);
}

void motorBOn()
{
 digitalWrite(enableB, HIGH);
}

 //disable motors
void motorAOff()
{
 digitalWrite(enableB, LOW);
}

void motorBOff()
{
 digitalWrite(enableA, LOW);
}

 //motor A controls
void motorAForward()
{
 digitalWrite(pinA1, HIGH);
 digitalWrite(pinA2, LOW);
}

void motorABackward()
{
 digitalWrite(pinA1, LOW);
 digitalWrite(pinA2, HIGH);
}

//motor B controls
void motorBForward()
{
 digitalWrite(pinB1, HIGH);
 digitalWrite(pinB2, LOW);
}

void motorBBackward()
{
 digitalWrite(pinB1, LOW);
 digitalWrite(pinB2, HIGH);
}

//coasting and braking
void motorACoast()
{
 digitalWrite(pinA1, LOW);
 digitalWrite(pinA2, LOW);
}

void motorABrake()
{
 digitalWrite(pinA1, HIGH);
 digitalWrite(pinA2, HIGH);
}

void motorBCoast()
{
 digitalWrite(pinB1, LOW);
 digitalWrite(pinB2, LOW);
}

void motorBBrake()
{
 digitalWrite(pinB1, HIGH);
 digitalWrite(pinB2, HIGH);
}



ใส่ แบตเตอรี่ลิเธียม 18650 จำนวน 2 ก้อน ไปที่ รางถ่าน และ ตรวจสอบขั้วของแบตเตอรี่ ใส่ถุกต้องหรือไม่


โปรแกรมนี้จะทำงานเพียง 1 ครั้ง ถ้าต้องการทดลองใหม่ให้ถอด แบตเตอรี่ออก (หรือ ปิดเปิด สวิทช์ไฟใหม่) แล้วใส่เข้าไปใหม่ เมื่อล้อหมุน ตรวจสอบการหมุน ขอล้อต่างๆถูกต้องหรือไม่ ถ้าต่อวงจรถูกต้อง ล้อ ทั้งสองข้างจะหมุนไปข้างหน้า 1ครั้ง กลับหลัง 1 ครั้ง และ เดินหน้าอีกหนึ่งครั้งแล้วจึงหยุด ถ้าไม่ถูกต้องให้แก้ไข เช่นการต่อขั้วของมอเตอร์ผิด เป็นต้น

ถ้าทุกอย่างถูกต้อง ทดลอง ยกลงวางที่พื้นแล้วทดสอบ อีกครั้ง ถอด แบตเตอรี่ออก (หรือ ปิดเปิด สวิทช์ไฟใหม่) แล้วใส่เข้าไปใหม่ ถ้าทุกอย่างถูกต้อง รถจะเคลื่อนที่ไปข้างหน้า-ถอยหลัง แล้ว เลี้ยวซ้าย แล้ว จึงกลับสู่ตำแหน่งเดิม

จากนั้นประกอบ 5 Way Fire Extinguisher Sensor




ทดสอบการทำงานของ 5 Way Fire Extinguisher Sensor



การเชื่อมต่อ ระหว่าง 5 Way Fire Extinguisher Sensor กับ 
บอร์ด Arduino UNO


5 Way
 -> Arduino

A1D1 -> A1

A2D2 -> A2

A3D3 -> A3

A4D4 -> A4

A5D5 -> A5

VCC -> 5V

GND -> GND



และ  Upload โค้ดนี้ ไปยัง บอร์ด Arduino UNO R3




/*


read analog data from A1-A5 and send to PC via Serial port


*/




int sensor_1 , sensor_2 , sensor_3 , sensor_4 , sensor_5 ; //optical sensor values


String tmp ;

int ADC_stabilize = 5 ;
void setup ( ) {
  // initialize the serial communication:
  Serial . begin ( 9600 ) ;
}
void loop ( ) {
  //take a snapshot
  sensor_1 = analogRead ( A1 ) ;
  delay ( ADC_stabilize ) ; //stabilize
  sensor_1 = analogRead ( A1 ) ;
  delay ( ADC_stabilize ) ;
  sensor_2 = analogRead ( A2 ) ;
  delay ( ADC_stabilize ) ;
  sensor_2 = analogRead ( A2 ) ;
  delay ( ADC_stabilize ) ;
  sensor_3 = analogRead ( A3 ) ;
  delay ( ADC_stabilize ) ;
  sensor_3 = analogRead ( A3 ) ;
  delay ( ADC_stabilize ) ;
  sensor_4 = analogRead ( A4 ) ;
  delay ( ADC_stabilize ) ;
  sensor_4 = analogRead ( A4 ) ;
  delay ( ADC_stabilize ) ;
  sensor_5 = analogRead ( A5 ) ;
  delay ( ADC_stabilize ) ;
  sensor_5 = analogRead ( A5 ) ;
  delay ( ADC_stabilize ) ;
  tmp = " S1=" + String ( sensor_1 ) + " S2=" + String ( sensor_2 ) + " S3=" + String ( sensor_3 ) + " S4=" + String ( sensor_4 ) + " S5=" + String ( sensor_5 ) ;
  // send the value of analog inputs:
  Serial . println ( tmp ) ;
  // wait a bit for next reading
  delay ( 1000 ) ; //1000=1 sec
}



นำเปลวไฟ มาทดสอบ แล้ว เปิดดูที่ Serial Monitor


เมื่อนำ เปลวไฟ เข้าใกล้ เซ็นเซอร์ ตัวไหนมากที่สุด ก็จะได้ค่าที่อ่านได้ มากที่สุด





ภาพรวมการต่อ หุ่นยนต์เดินตาม เปลวไฟ Fire Extinguisher





จากนั้นทดสอบ หุ่นยนต์เดินตาม เปลวไฟ Fire Extinguisher ได้โดย  Upload โค้ดนี้ ไปยัง บอร์ด Arduino UNO R3





// Motor A pins (enableA = enable motor, pinA1 = forward, pinA2 = backward)
int enableA = 3;
int pinA1 = 6;
int pinA2 = 7;
//Motor B pins (enabledB = enable motor, pinB2 = forward, pinB2 = backward)
int enableB = 5;
int pinB1 = 8;
int pinB2 = 9;
int sensor[5] = {0, 0, 0, 0, 0};
void setup()
{
  pinMode(enableA, OUTPUT);
  pinMode(pinA1, OUTPUT);
  pinMode(pinA2, OUTPUT);
  pinMode(enableB, OUTPUT);
  pinMode(pinB1, OUTPUT);
  pinMode(pinB2, OUTPUT);
  enableMotors();
  analogWrite(enableA, 120);  // ปรับค่าความเร็วของหุ่นยนต์
  analogWrite(enableB, 120);  // ปรับค่าความเร็วของหุ่นยนต์
  delay(2000);
}
void loop()
{
  sensor[0] = analogRead(A1);
  sensor[1] = analogRead(A2);
  sensor[2] = analogRead(A3);
  sensor[3] = analogRead(A4);
  sensor[4] = analogRead(A5);
  if ((sensor[0] > sensor[1]) && (sensor[0] > sensor[2]) && (sensor[0] > sensor[3]) && (sensor[0] > sensor[4]))
    turnLeft(200);
  else if ((sensor[1] > sensor[0]) && (sensor[1] > sensor[2]) && (sensor[1] > sensor[3]) && (sensor[1] > sensor[4]))
    turnLeft(100);
  else if ((sensor[2] > sensor[0]) && (sensor[2] > sensor[1]) && (sensor[2] > sensor[3]) && (sensor[2] > sensor[4]))
    forward(1);
  else if ((sensor[3] > sensor[0]) && (sensor[3] > sensor[1]) && (sensor[3] > sensor[2]) && (sensor[3] > sensor[4]))
    turnRight(100);
  else if ((sensor[4] > sensor[0]) && (sensor[4] > sensor[1]) && (sensor[4] > sensor[2]) && (sensor[4] > sensor[3]))
    turnRight(200);
  else
    coast(100);
}
//Define high-level H-bridge commands
void enableMotors()
{
  motorAOn();
  motorBOn();
}
void disableMotors()
{
  motorAOff();
  motorBOff();
}
void forward(int time)
{
  motorAForward();
  motorBForward();
  delay(time);
}
void backward(int time)
{
  motorABackward();
  motorBBackward();
  delay(time);
}
void turnLeft(int time)
{
  motorABackward();
  motorBForward();
  delay(time);
}
void turnRight(int time)
{
  motorAForward();
  motorBBackward();
  delay(time);
}
void coast(int time)
{
  motorACoast();
  motorBCoast();
  delay(time);
}
void brake(int time)
{
  motorABrake();
  motorBBrake();
  delay(time);
}
//Define low-level H-bridge commands
//enable motors
void motorAOn()
{
  digitalWrite(enableA, HIGH);
}
void motorBOn()
{
  digitalWrite(enableB, HIGH);
}
//disable motors
void motorAOff()
{
  digitalWrite(enableB, LOW);
}
void motorBOff()
{
  digitalWrite(enableA, LOW);
}
//motor A controls
void motorAForward()
{
  digitalWrite(pinA1, HIGH);
  digitalWrite(pinA2, LOW);
}
void motorABackward()
{
  digitalWrite(pinA1, LOW);
  digitalWrite(pinA2, HIGH);
}
//motor B controls
void motorBForward()
{
  digitalWrite(pinB1, HIGH);
  digitalWrite(pinB2, LOW);
}
void motorBBackward()
{
  digitalWrite(pinB1, LOW);
  digitalWrite(pinB2, HIGH);
}
//coasting and braking
void motorACoast()
{
  digitalWrite(pinA1, LOW);
  digitalWrite(pinA2, LOW);
}
void motorABrake()
{
  digitalWrite(pinA1, HIGH);
  digitalWrite(pinA2, HIGH);
}
void motorBCoast()
{
  digitalWrite(pinB1, LOW);
  digitalWrite(pinB2, LOW);
}
void motorBBrake()
{
  digitalWrite(pinB1, HIGH);
  digitalWrite(pinB2, HIGH);
}

หลักของมาตรฐาน ISO 9001:2000      หลักการมาตรฐานของ ISO 9001:2000 จะเป็นการระบุถึงข้อกำหนดที่ใช้ในระบบบริหารที่เกี่ยวกับคุณภาพ โดยเป้าหมา...