Camion RC robot Arduino w / capteurs multiples (8 / 10 étapes)

Étape 8: Copiez ce croquis dans l’IDE et de télécharger à votre Arduino

 /* Sketch written by ImMrRoboto to convert an RC truck into a robot using 3 PING sensors, an Arduino UNO and a SEEED Studio Motor Shield. It is built upon PING example code by Tom Igoe and a motor shield tutorial sketch by SEEED Studio. */ int pinI1=8;//define I1 interface int pinI2=11;//define I2 interface int speedpinA=9;//enable motor A int pinI3=12;//define I3 interface int pinI4=13;//define I4 interface int steerpinB=10;//enable motor B int speed_drive =420;//define the speed of drive motor int speed_steer =1524;//define the speed of steering motor const int pingPin_R = 7;//sets the pin for the PING sensor on the right side of the car const int pingPin_C = 6;//sets the pin for the PING sensor in the center side of the car const int pingPin_L = 5;//sets the pin for the PING sensor on the left side of the car long duration_C, inches_C,duration_R, inches_R,duration_L, inches_L; void setup() { pinMode(pinI1,OUTPUT); pinMode(pinI2,OUTPUT); pinMode(speedpinA,OUTPUT); pinMode(pinI3,OUTPUT); pinMode(pinI4,OUTPUT); pinMode(steerpinB,OUTPUT); } void loop() { int i; int j = 1; delay(5000); for(i=0; i<1; i*1){ j++; getping_all(); //all clear, no obstacles within 30" in any direction if(inches_C >= 30 && inches_R >= 30 && inches_L >= 30) { forward(); } //obstacle(s) within 0-6" range else if (inches_L < 6 || inches_C < 6 || inches_R < 6) { stop(); backward(); delay(1500); stop(); if(j%3 == 0){ //This if/else statement is designed to build a little "randomness" back_right(); //into the robot's movements, so it is less likely to become stuck back_right(); //in a loop, performing the same actions over and over which only. left(); j=1; } else{ back_left(); back_left(); right(); } } //obstacle(s) within 6"-12" range //obstacle on left and center and right else if (inches_R < 12 && inches_C < 12 && inches_L < 12) { stop(); backward(); delay(1500); back_left(); stop(); right(); forward(); } //obstacle on center OR left and right else if (inches_L >= 12 && inches_R >= 12 && inches_C < 12 || inches_C >= 12 && inches_R < 12 && inches_L < 12) { stop(); backward(); delay(1500); back_left(); stop(); right(); forward(); } //obstacle on left and center else if (inches_R >= 12 && inches_C < 12 && inches_L < 12) { stop(); backward(); delay(1500); back_left(); } //obstacle on right and center else if (inches_L >= 12 && inches_C < 12 && inches_R < 12) { stop(); backward(); delay(1500); back_right(); } //obstacle on right else if (inches_L >= 12 && inches_C >= 12 && inches_R < 12) { left(); left(); } //obstacle on left else if (inches_R >= 12 && inches_C >= 12 && inches_L < 12) { right(); right(); } //obstacle(s) within 12"-30" range //obstacle on left and center else if (inches_R >= 30 && inches_C < 30 && inches_L < 30) { right(); right(); } //obstacle on right and center else if (inches_L >= 30 && inches_C < 30 && inches_R < 30) { left(); left(); } //obstacle on right and left else if (inches_C >= 30 && inches_L < 30 && inches_R < 30) { forward(); } //obstacle on right else if (inches_L >= 30 && inches_C >= 30 && inches_R < 30) { left(); } //obstacle on left else if (inches_R >= 30 && inches_C >= 30 && inches_L < 30) { right(); } //obstacle on center else if (inches_L >= 30 && inches_R >= 30 && inches_C < 30) { if(j % 2 == 0){ left(); j=1; } else{ right(); } } } } void forward() {// turns on drive motor in forward and leaves it on analogWrite(speedpinA,speed_drive);//inputs speed_drive value to set the speed digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise digitalWrite(pinI1,HIGH); } void backward()// {// turns on drive motor in reverse and leaves it on analogWrite(speedpinA,speed_drive);//inputs speed_drive value to set the speed digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise digitalWrite(pinI1,LOW); } void right()// { analogWrite(steerpinB,speed_steer); digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise digitalWrite(pinI3,LOW); forward(); delay(300); analogWrite(steerpinB,LOW); } void back_left()// { analogWrite(steerpinB,speed_steer); digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise digitalWrite(pinI3,LOW); delay(250); backward(); delay(500); stop(); delay(250); } void left()// { analogWrite(steerpinB,speed_steer); digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise digitalWrite(pinI3,HIGH); forward(); delay(300); analogWrite(steerpinB,LOW); } void back_right()// { analogWrite(steerpinB,speed_steer); digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise digitalWrite(pinI3,HIGH); delay(250); backward(); delay(500); stop(); delay(250); } void stop()//stop both motors { digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. digitalWrite(steerpinB,LOW);// Unenble the pin, to stop the motor. } void getping_C()//get distance from center PING { pinMode(pingPin_C, OUTPUT); digitalWrite(pingPin_C, LOW); delayMicroseconds(2); digitalWrite(pingPin_C, HIGH); delayMicroseconds(5); digitalWrite(pingPin_C, LOW); pinMode(pingPin_C, INPUT); duration_C = pulseIn(pingPin_C, HIGH); inches_C = microsecondsToInches(duration_C); } void getping_R()//get distance from right PING { pinMode(pingPin_R, OUTPUT); digitalWrite(pingPin_R, LOW); delayMicroseconds(2); digitalWrite(pingPin_R, HIGH); delayMicroseconds(5); digitalWrite(pingPin_R, LOW); pinMode(pingPin_R, INPUT); duration_R = pulseIn(pingPin_R, HIGH); inches_R = microsecondsToInches(duration_R); } void getping_L()//get distance from left PING { pinMode(pingPin_L, OUTPUT); digitalWrite(pingPin_L, LOW); delayMicroseconds(2); digitalWrite(pingPin_L, HIGH); delayMicroseconds(5); digitalWrite(pingPin_L, LOW); pinMode(pingPin_L, INPUT); duration_L = pulseIn(pingPin_L, HIGH); inches_L = microsecondsToInches(duration_L); } void getping_all() { getping_C(); delay(2); getping_R(); delay(2); getping_L(); delay(2); } long microsecondsToInches(long microseconds){ return microseconds / 74 / 2;} /* The above converts the time of the return to inches as explained here: <a href="http://learn.parallax.com/kickstart/28015" rel="nofollow">http://learn.parallax.com/kickstart/28015 </a>*/ 

Articles Liés

Ligne suivant Robot Arduino

Ligne suivant Robot Arduino

Ce robot utilise un algorithme de contrôle PID autonome suivre une piste noire sur fond blanc. Il utilise un tableau de huit capteurs de réflectance infrarouge pour déterminer la position du robot sur la ligne, et le microcontrôleur Arduino Nano calc
Le Robot Arduino d’Uno

Le Robot Arduino d’Uno

Age : 13Répondre à Uno le robot Arduino alimenté.  Certaines fonctions incluent un nez clignote, antennes, tête tournante, capteur de distance infrarouge double engrenage du moteur boîte de rotation des compteurs et de déplacement.  Uno est réalisé a
RC voiture autonome robot Arduino

RC voiture autonome robot Arduino

Avez vous jamais désiré construire un simple robot autonome de Arduino ? Je me suis inspiré pour construire un robot Arduino base afin d'aider ma compréhension de l'Arduino, l'IDE Arduino et le fonctionnement des capteurs à ultrasons et les chauffeur
Débutants guident de construction de robots Arduino avec Bluetooth et Android

Débutants guident de construction de robots Arduino avec Bluetooth et Android

dans ce tutoriel, nous allons aller au cours de la construction d'un robot Arduino qui peut être contrôlé via bluetooth avec une téléphone/tablette Android. Il s'agit d'un guide de débutants qui va franchir brièvement le processus de câblage et de pr
Plateforme de robotique Arduino simple de Carduino - A avec sa propre bibliothèque

Plateforme de robotique Arduino simple de Carduino - A avec sa propre bibliothèque

il s'agit, comme le titre l'indique, une plate-forme robotique Arduino, avec sa propre bibliothèque. Le modèle « standard » est livré avec deux moteurs arrière, deux omni-roues à l'avant, et un capteur de distance montés à l'avant. Il a également l'e
Construire un Robot Arduino Simple

Construire un Robot Arduino Simple

Il s'agit de mon premier Instructable.. !Ce guide vous montre comment créer rapidement et facilement un robot Arduino-basé. La robotique est un passe-temps passionnant et amusant qui est devenu très abordable ces dernières années. Ce qui aurait néces
Arduino et capteur à ultrasons contrôle servo et distance compteur

Arduino et capteur à ultrasons contrôle servo et distance compteur

Arduino et capteur à ultrasons contrôle servo et distance meterDans ce projet, vous pouvez voir comment contrôler le moteur servo et tu calculer la distance à l'aide d'arduino et capteur à ultrasons. Vous avez besoin: 1. Arduino (uno, nano, mini pro)
Bras de Robot Arduino

Bras de Robot Arduino

je l'avais promis dans un précédent post pour partager avec vous un robot arduino arm projet à une date ultérieure. Eh bien, cette date est aujourd'hui ! Cependant, au lieu d'utiliser un joystick pour contrôler le bras du robot arduino, I ' m Gonna p
DIY 4WD carrosserie pour les projets de robotique arduino et voitures RC

DIY 4WD carrosserie pour les projets de robotique arduino et voitures RC

Salut salutations geeks instructables d'Egypte:):),dans ce instructable je vais vous montrer comment concevoir et fabriquer une voiture 4 roues pour robotique, arduino, voitures RC... etc. d'une manière facile il suffit de me suivre;): D >>>Etape
Commande de porte de Garage Bluetooth Arduino avec capteurs et personnalisable Android App

Commande de porte de Garage Bluetooth Arduino avec capteurs et personnalisable Android App

Utilisez un arduino pour activer le relais pour l'ouverture des portes de garage et serrures électriques.Une application Android personnalisable, se connecte à l'arduino via mot de passe bluetooth appairage.Un module de hc-05 bluetooth reçoit des com
Bras de robot arduino Bluetooth contrôlée

Bras de robot arduino Bluetooth contrôlée

J'ai enfin ajouté capacité bluetooth à mon bras de robot arduino. Je l'ai fait en utilisant le module bluetooth de HC-06.Étape 1: exigencesBras de robot Arduino - 6-dof-arduino uno ou régulièreBouclier de servo - SSC-32Module bluetooth - HC-06Je ne v
Le Robot Arduino - arbre de vie

Le Robot Arduino - arbre de vie

Robot Arduino - arbre de vieListe du matériel :1) Duemilanovue Arduino2) tôle aluminium3) fils d'équerre4) 5 x 3 mm bleu LED5) oeillets en laiton6) unique fils7) vitrine àVisitez http://retardokiddo.blogspot.com/ pour les détails et commentaires !(Ve
Arduino Pulse capteur Cardio graphique

Arduino Pulse capteur Cardio graphique

L'application de l'Arduino Pulse capteur Cardio graphique illustre coeur battre informations sous forme graphique. L'application affiche des graphiques de variation différente fréquence cardiaque : battements par Minute (BPM), Interbeat intervalles (
Lecteur de musique Android Arduino et-capteur-temporels

Lecteur de musique Android Arduino et-capteur-temporels

Imaginez votre lecteur de musique qui jouent pour vous, un joueur de ce sens lumièreambiante, température et temps qui affecte l'humeur d'une personne et choisir une chanson classent comme MOODs. Parce que je n'ai pas un capteur qui peut traduire l'é