วันเสาร์ที่ 28 กรกฎาคม พ.ศ. 2561

Building a Simple Arduino Robot

This guide shows you how to quickly and easily build an Arduino robot. Robotics is an exciting and fun hobby that has become very affordable in recent years. What would have required a lot of money and experience to do a few decades ago is now affordable, easy, and most of all, FUN!
.
Simple Arduino Robot
The parts used in this guide can all be purchased together in the Funduino UNO Robotics Kit, but you can follow along with a different kit just as easily as long as you have similar components.
Keep in mind that this tutorial shows just one way to make a robot — you’re limited only by your budget and imagination. If you want to buy more sensors, or a nicer chassis, go for it! The entire process may take an hour or two, so get ready to have some fun!//PERFECT RUNNING PROGRAM FOR ONE ULTRASONIC + SERVO + 2 DC MOTOR BASED //ROBOT CAR 
// REGARDS ENG.SURESH KUMAR CONTACT AT suresh.kkes@gmail.com
#include <servo.h>
const int trigPin = 11;
const int echoPin = 8;
const int MotorAn = 10;
const int MotorAp = 9;
//Motor B
const int MotorBn = 5;
const int MotorBp = 3;
Servo myservo;
int pos = 75;
void setup() {
Serial.begin(5000);
myservo.attach(12);
}
void loop()
{
long duration, inches, cm;
pinMode(MotorAn, OUTPUT);
pinMode(MotorAp, OUTPUT);
pinMode(MotorBn, OUTPUT);
pinMode(MotorBp, OUTPUT);
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
if (inches <= 6)
{
sweep(1);
Serial.println ("Motion Backwards");
}
else if (inches >= 6)
{
myservo.write(pos);
delay(100);
Serial.println ("Motion Forward");
digitalWrite (MotorAn,HIGH);
digitalWrite (MotorAp,LOW);
digitalWrite (MotorBn,HIGH);
digitalWrite (MotorBp,LOW);
}}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
void sweep(int turn)
{
for (int j=0; j<turn; j++)="" digitalwrite="" (motoran,low);="" digitalwrite="" (motorap,low);="" digitalwrite="" (motorbn,low);="" digitalwrite="" (motorbp,low);="" for(pos="-10;" pos="" <="" 180;="" pos="" +="2)" {="" myservo.write(pos);="" delay(10);="" }="" digitalwrite(motoran,="" high);="" digitalwrite(motorap,="" low);="" delay(10);="" for(pos="150;" pos="">=75; pos-=2) {
myservo.write(pos);
delay(10); }
myservo.write(pos);
delay(10);
}
(อ้างอิง) https://makezine.com/projects/building-a-simple-arduino-robot/

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

Internet of Things (IoT)

Internet of Things หรือ IoT  Internet of Things (IoT)  คือ การที่อุปกรณ์อิเล็กทรอนิกส์ต่างๆ สามารถเชื่อมโยงหรือส่งข้อมูลถึงกันได้ด้วยอิ...