NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <QTRSensors.h>
#define NUM_SENSORS 5 // number of sensors used
#define NUM_SAMPLES_PER_SENSOR 4 // average 4 analog samples per sensor reading
#define QTR_NO_EMITTER_PIN // no emitter pin

// sensors 1 through 5 are connected to analog inputs 1 through 5, respectively
QTRSensorsAnalog qtra((unsigned char[]) {1, 2, 3, 4, 5}, NUM_SENSORS, NUM_SAMPLES_PER_SENSOR);
unsigned int sensorValues[NUM_SENSORS];
int dist=0;
int sensorPin=A0;
int obstaculo=450; //distancia do obstaculo

void setup() {
Serial.begin(9600); // iniciar serial
pinMode(sensorPin, INPUT);
pinMode(2, OUTPUT); // IN4 - motor direita
pinMode(3, OUTPUT); // IN3 - motor direita
pinMode(4, OUTPUT); // IN2 - motor esquerda
pinMode(5, OUTPUT); // IN1 - motor esquerda
pinMode(6, OUTPUT); // PWM - motor esquerda
pinMode(9, OUTPUT); // PWM - motor direita
delay(500);
// ----------------- CALIBRAçAO dos SENSORES----------------------
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); // turn on Arduino's LED to indicate we are in calibration mode
for (int i = 0; i < 400; i++) // make the calibration take about 10 seconds
{
qtra.calibrate(); // reads all sensors 10 times at 2.5 ms per six sensors (i.e. ~25 ms per call)
}
digitalWrite(13, LOW); // turn off Arduino's LED to indicate we are through with calibration
// print the calibration minimum values measured when emitters were on
Serial.begin(9600);
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtra.calibratedMinimumOn[i]);
Serial.print(' ');
}
Serial.println();
// print the calibration maximum values measured when emitters were on
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtra.calibratedMaximumOn[i]);
Serial.print(' ');
}
Serial.println();
Serial.println();
delay(1000);
}

void loop() {
delay(50);
dist=analogRead(sensorPin);
if(dist<obstaculo){
segue_linha();
if(dist>=obstaculo){
parar();
}
}
}
void segue_linha(){
qtra.read(sensorValues);
if (sensorValues[3] > 100) { // se sensor3 estiver na linha
frente ();
}
else if (sensorValues[3] < 100) {
findline ();
}

}

void frente () {
analogWrite(6, 180);
analogWrite(9, 150);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay (90); // varia - conforme a espessura da linha e da curva
parar();
return;
}

void findline () {
parar();
if (sensorValues[2] > 100) { // se o sensor2 está no preto vira para esquerda
vira_direita();
}
else if (sensorValues[1] > 100) { // se o sensor2 está no preto vira para esquerda
vira_direita();
}
else if (sensorValues[4] > 100) { // se o sensor4 está no preto vira para direita
vira_esquerda();
}
else if (sensorValues[5] > 100) { // se o sensor5 está no preto vira para direita
vira_esquerda();
}
}

void parar() {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay (50);
return;
}

void vira_direita() {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay (80); // variar conforme a espessura da linha
parar();
return;
}
void vira_esquerda() {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay (80);
parar();
return;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.