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!