Arduino car entry-fourth day (sensor), arduino car

Source: Internet
Author: User

Arduino car entry-fourth day (sensor), arduino car

Hello everyone, I am a small Editor.

Record the content in the previous section and click "open link ".

Today we will talk about sensors.

Today we will talk about light and ultrasound.

Start with a chart:


There are three optical interfaces:

UCC, out, And GND.

Ultrasonic has four interfaces:

UCC, T, E, And GND.

The following is the principle.


The ultrasonic wave emits an ultrasonic wave, and the sound waves rebound when they hit the object. The other side receives the ultrasonic wave to determine the distance.

The light sensation is the minimum 0 value of the detected light value, and the maximum 255 is determined.

Procedures attached:

Vehicle with obstacle avoidance

#include <Servo.h> int pinLF=14;     int pinLB=15;     int pinRF=16;    int pinRB=17;   int PWMEN1=3;int PWMEN2=5;void setup() {  Serial.begin(9600);      pinMode(pinLB,OUTPUT);   pinMode(pinLF,OUTPUT);   pinMode(pinRB,OUTPUT);   pinMode(pinRF,OUTPUT);   pinMode(PWMEN1,OUTPUT);   pinMode(PWMEN2,OUTPUT);  }void advance(int a)         {     digitalWrite(pinRF,HIGH);      digitalWrite(pinRB,LOW);             analogWrite(pinRF,150);             analogWrite(pinRB, 0);     digitalWrite(pinLF,HIGH);      digitalWrite(pinLB,LOW);             analogWrite(pinLF,150);             analogWrite(pinLB,0);     delay(a * 100);         }void right(int b)            {     digitalWrite(pinRF,LOW);     digitalWrite(pinRB,LOW);                analogWrite(pinRF,0);             analogWrite(pinRB, 0);     digitalWrite(pinLF,HIGH);        digitalWrite(pinLB,LOW);             analogWrite(pinLF,150);             analogWrite(pinLB,0);     delay(b * 100);    }void left(int c)             {     digitalWrite(pinRF,HIGH);     digitalWrite(pinRB,LOW);                analogWrite(pinRF,150);             analogWrite(pinRB, 0);     digitalWrite(pinLF,LOW);        digitalWrite(pinLB,LOW);             analogWrite(pinLF,0);             analogWrite(pinLB,0);     delay(c * 100);    }void turnR(int d)            {     digitalWrite(pinRF,LOW);     digitalWrite(pinRB,HIGH);                analogWrite(pinRF,0);             analogWrite(pinRB, 150);     digitalWrite(pinLF,HIGH);        digitalWrite(pinLB,LOW);             analogWrite(pinLF,100);             analogWrite(pinLB,0);     delay(d * 100);    }void turnL(int e)            {     digitalWrite(pinRF,HIGH);     digitalWrite(pinRB,LOW);                analogWrite(pinRF,150);             analogWrite(pinRB, 0);     digitalWrite(pinLF,LOW);        digitalWrite(pinLB,HIGH);             analogWrite(pinLF,0);             analogWrite(pinLB,150);     delay(e * 100);    }    void stopp(int f)             {     digitalWrite(pinRB,LOW);     digitalWrite(pinRF,LOW);     digitalWrite(pinLB,LOW);     digitalWrite(pinLF,LOW);     delay(f * 100);    }void back(int g)           {     digitalWrite(pinRF,LOW);       digitalWrite(pinRB,HIGH);             analogWrite(pinRF,0);             analogWrite(pinRB, 150);     digitalWrite(pinLF,LOW);       digitalWrite(pinLB,HIGH);             analogWrite(pinLF,0);             analogWrite(pinLB,150);     delay(g * 100);         }void loop() {    advance(1);                  delay(1000);    back(1);                     delay(1000);        turnL(1);                   delay(1000);        turnR(1);                   delay(1000); }      

Tracking car

#include <Servo.h> int pinLF=14;     int pinLB=15;     int pinRF=16;   int pinRB=17;    int PWM1=3;   int PWM2=5;  void setup() {  Serial.begin(9600);      pinMode(pinLB,OUTPUT);   pinMode(pinLF,OUTPUT);   pinMode(pinRB,OUTPUT);   pinMode(pinRF,OUTPUT);    }void advance(int a)       {     digitalWrite(pinRF,HIGH);       digitalWrite(pinRB,LOW);             analogWrite(pinRF,130);             analogWrite(pinRB, 0);     digitalWrite(pinLF,HIGH);      digitalWrite(pinLB,LOW);             analogWrite(pinLF,200);             analogWrite(pinLB,0);     delay(a * 100);         }void loop() {    advance(1);                }


Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.