บทความ

งานที่ 19 หุ่นยนต์เดินตาม เปลวไฟ Fire Extinguisher

รูปภาพ
HARDWARE SOFTWARE // 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)...

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

รูปภาพ
HARDWARE SOFTWARE #include <NewPing.h> //Tell the Arduino where the sensor is hooked up NewPing sonar(10, 11); int enableA = 3; int pinA1 = 6; int pinA2 = 7; int enableB = 5; int pinB1 = 8; int pinB2 = 9; long inches; void setup() {   pinMode(enableA, OUTPUT);   pinMode(pinA1, OUTPUT);   pinMode(pinA2, OUTPUT);   pinMode(enableB, OUTPUT);   pinMode(pinB1, OUTPUT);   pinMode(pinB2, OUTPUT);   pinMode(2, OUTPUT);   pinMode(12, OUTPUT);   pinMode(13, OUTPUT); } void loop() {   //Run the motors at slightly less than full power   analogWrite(enableA, 200);   analogWrite(enableB, 200);   //Ping the sensor and determine the distance in inches   inches = sonar.ping_in();   //If the robot detects an obstacle less than four inches away, it will back up, then turn left; if no obstacle is detected, it will go forward   if (inches < 5) {     analogWrite(enableA, 255);     analogWrite(e...