Keyestudio Smart Little Turtle Robot V3 Manual page 169

Table of Contents

Advertisement

www.keyestudio.com
int right_pwm = 5;//define the speed control pin of B motor
#include "SR04.h" //define the function library of ultrasonic sensor
#define TRIG_PIN 12// set the signal of ultrasonic sensor to D12
#define ECHO_PIN 13// set the signal of ultrasonic sensor to D13
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long distance;
void setup() {
Serial.begin(9600);//open serial monitor and set baud rate to 9600
pinMode(left_ctrl,OUTPUT);//set direction control pin of A motor to
OUTPUT
pinMode(left_pwm,OUTPUT);//set PWM control pin of A motor to
OUTPUT
pinMode(right_ctrl,OUTPUT);//set direction control pin of B motor to
OUTPUT
pinMode(right_pwm,OUTPUT);//set PWM control pin of B motor to
OUTPUT
}
void loop() {
distance =
sr04.Distance();//the distance detected by ultrasonic sensor
169

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents