Подключение ультразвукового датчика HC-SR04

Similar documents
Robot Eyes. DAY 3 Let's Make a Robot

Experiment 3: Sonar Navigation, CAD and 3D Printing

WALT: definition and decomposition of complex problems in terms of functional and non-functional requirements

IME-100 ECE. Lab 5. Electrical and Computer Engineering Department Kettering University

Basic Kit for Turtle 2WD SKU:ROB0118

Basic Kit for Turtle 2WD SKU:ROB0118

Handson Technology. HC-SR04 Ultrasonic Sensor Module. 1

Experiment 7: Robotics++ V3 Robot BlueToothbot

Arduino Smart Robot Car Kit User Guide

LEGO BB-8 Release: LEGO BB-8. Learn how to automate a LEGO BB-8for motion, light, and sound using Crazy Circuits. Written By: Joshua

Robotics/Electronics Review for the Final Exam

URM06 UART Ultrasonic SKU:SEN0150

This is the Arduino Uno: This is the Arduino motor shield: Digital pins (0-13) Ground Rail

Intelligent Machines Design Laboratory EEL 5666C

MAKE & COLLABORATE: SECRET KNOCK LOCK

DIY Remote Control Robot Kit (Support Android) SKU:COMB0004

ROBOTLINKING THE POWER SUPPLY LEARNING KIT TUTORIAL

A.U.R.A.S Autonomous Ultrasonic Robot for Area Scanning

Introduction to Processing

Introduction to Arduino Programming. Sistemi Real-Time Prof. Davide Brugali Università degli Studi di Bergamo

Obstacle Detecting Line Follower Robot

EEL 5666C - Intelligent Machine Design Lab Final report

Eng.mohammed Albhaisi. Lab#3 : arduino to proteus simulation. for simulate Arduino program that you wrote you have to have these programs :

Chapter 1: Getting Started

Joy-IT Ultrasonic Distance Sensor

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

Automated Waste Bin Monitor Md Ahad Bin Alam*

myservoa.attach(3); // attaches the servo on pin 3 to the servo object //copy from servo code

TETRIX Getting Started Guide. Harvester and Transporter Programming Guide (ROBOTC )

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

AndyMark Arduino Tutorial

18-heater Arduino code

TETRIX Getting Started Guide FTC Extension. Programming Guide (ROBOTC ) Autonomous Programming

ECE 271 Microcomputer Architecture and Applications University of Maine

Arduino Smart Bluetooth Robot Car Kit User Guide

ISL RGB Sensor Tutorial By: Sabrina Jones

Steering Engine Sample Sketch

Overview. Exploration: LED Ramp Light. cs281: Introduction to Computer Systems Lab04 K-Maps and a Sensor/Actuator Circuit

Grove - Gesture V1.0. Introduction. Features

Arduino Uno Microcontroller Overview

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

2014 МГУ/ВМК/СП. Лекция 7. 1 марта

m-block By Wilmer Arellano

Introduction to Arduino Diagrams & Code Brown County Library

Introduction to Arduino Diagrams & Code Brown County Library

Another Forking Robot

CHAPTER V IMPLEMENTATION AND TESTING

Activity Basic Inputs Programming VEX

Activity Basic Inputs Programming VEX

REFERENCE MATERIALS. Assignment, Display, and Input Evaluates expression and assigns the result to the variable a.

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

TA0139 USER MANUAL ARDUINO 2 WHEEL DRIVE WIRELESS BLUETOOTH ROBOT KIT

C Language Reference for ActivityBot. Driving the robot a specific distance or a specific amount of turn

2. Within your four student group, form a two student team known as Team A and a two student team known as Team B.

Arduino Programming and Interfacing

Activity Basic Inputs Programming - VEX Clawbot

/* to use: enter key aray and make sure that the userentered has the same number of zeros

Activity Basic Inputs Programming Answer Key (VEX)

Grove - 80cm Infrared Proximity Sensor

1. Introduction Packing list Parts Introduction Uno R3 Board for Arduino Specifications... 6

EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

Sten-SLATE ESP Kit. Description and Programming

Xplus an efficient mobile robot platform controlled by I2C

Grove - 80cm Infrared Proximity Sensor User Manual

Operation instructions. Network reader/controller

Praktikum: 4. Content of today s lecture. Content of today s lecture. Manfred Grove Houxiang Zhang. Program introduction. Program introduction

Obstacle Avoiding Robot

m-block By Wilmer Arellano

EXPERIMENT 7 Please visit to learn all features of arduino before you start the experiments

ARDUINO. By Kiran Tiwari BCT 2072 CoTS.

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

<Table of content> <Parts and description> <Circuit board Guide> <Pins> <Basics of Coding> <Intro to Arduino> <Intro> <Downloading Arduino IDO>

CONSTRUCTION GUIDE Remote Big Wheel. Robobox. Level VIII

Manfred Grove Houxiang Zhang

unsigned long NextTelevisonFlicker; // The time the TV light level is changed.

Programming with the NXT using the touch and ultrasonic sensors. To be used with the activity of the How do Human Sensors Work?

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

ACKNOWLEDGEMENT. Sagar Agrawal Parikshit jha Apar Sinha Gaurav Chauhan

To lead your students through this activity, you will need your computer, attached to a projector, for projecting your code for students to see.

Counter & LED (LED Blink)

The Arduino Briefing. The Arduino Briefing

Advanced Activities - Information and Ideas

Physical Computing Tutorials

RoboStamp Basic Software (A tutorial by Technotutorz)

Exercise 3. Task Programs EXERCISE OBJECTIVE

March 1 st, Dr. Andrew Rawicz School of Engineering Science Simon Fraser University Burnaby, British Columbia V5A 1S6

Arduino: Piezo Diagrams & Code Brown County Library. Projects 01 & 02: Scale and Playing a Tune Components needed: Arduino Uno board piezo

Procedure: Determine the polarity of the LED. Use the following image to help:

Timer1 Capture Mode:

Sensors and Motor Control Lab

Sensors and Motors Lab

Goal: Strengthen our understanding of C and program our Mudduino boards

ME 3200 Mechatronics Laboratory FALL 2002 Lab Exercise 7: Ultrasonic Sensors

Junying Huang Fangjie Zhou. Smartphone Locker

SPLDuino Programming Guide

Update: Ver 1.3 Dec Arduino Learning Guide For Beginner Using. Created by Cytron Technologies Sdn Bhd - All Rights Reserved

Using a Stepper Motor Like a Servo Controlled by a Potentiometer (G Payne 2017)

Schedule. Sanford Bernhardt, Sangster, Kumfer, Michalaka. 3:10-5:00 Workshop: Build a speedometer 5:15-7:30 Dinner and Symposium: Group 2

AP Computer Science Principles Exam Reference Sheet

boolean running = false; // false off, true on boolean gezielt = false; // Water turned on on purpose, true=on, false=off

Transcription:

Подключение ультразвукового датчика HC-SR04 Датчик HC-SR-04 состоит из передатчика, приемника и схемы управления. Для наиболее оптимального режима поиска препятствий датчик устанавливается на сервомотор SG90. Это позволяет искать и обнаруживать препятствия не только по направлению движения робота, но и с левой и с правой сторон от курса движения. Подключение сервомотора, датчика к блоку управления R-5 Назначение выводов: Gnd «земля». «Минус» батареи питания. Vcc «плюс» батареи питания. Trig вход сигнала управления датчиком. Echo выход сигнала измерения расстояния.

Подключение сервомотора и УЗ датчика определяется кодом программы. В программе мы определили следующее: Сервомотор подключается к контакту D9 ( коричневый провод к контакту GND, желтый провод к D6). Датчик HC-SR-06 Vcc к любому контакту в среднем ряду Trig к контакту D6 Echo к контакту D7 Gnd к любому контакту в правом ряду

Код программы: Для работы программы необходимо подключить две библиотеки. #include <Servo.h> #include <NewPing.h> //Below are the symbolic constants. Instead of having to type in a non-sensical pin number each time we want to do something we can write an easy to understand name which represents the pin, the compiler will then replace the names with the numbers #define MOTOR_R 2 #define SPEED_R 3 #define MOTOR_L 4 #define SPEED_L 5 #define USTrigger 6 #define USEcho 7 #define MaxDistance 100 #define LED 13 //Here we have created two 'objects', one for the servo and one for the ultrasonic sensor Servo servo; NewPing sonar(ustrigger, USEcho, MaxDistance); //Below we are creating unsigned integer variables which we will use later on in the code. They are unsigned as they will only have postive values unsigned int duration; unsigned int distance; unsigned int FrontDistance; unsigned int LeftDistance; unsigned int RightDistance; unsigned int Time; unsigned int CollisionCounter; void setup() //This block happens once on startup Serial.begin(9600); //I have included the serial initialize but commented it out, if you want to debug and print information to the serial monitor just uncomment //Here we are setting the pin modes. As we will sending out signals from the pins we set them as outputs pinmode(motor_r, OUTPUT); pinmode(speed_r, OUTPUT); pinmode(motor_l, OUTPUT); pinmode(speed_l, OUTPUT); pinmode(led, OUTPUT); servo.attach(9); //The servo is attached to pin 9 void loop() servo.write(90); //This block repeats itself while the Arduino is turned on //Rotate the servo to face the front

scan(); //Go to the scan function FrontDistance = distance; //Set the variable FrontDistance to the value of the distance returned from the scan function Serial.println("Front distance = "); Serial.print(distance); if(frontdistance > 60 FrontDistance == 0) //If there is nothing infront of the robot within 15cm or the distance value is 0 (which for the newping libary means no ping was returned) then... moveforward(); //Go to the moveforward function else //Else(if there is something infront of the robot within 40cm) then... CollisionCounter = CollisionCounter + 1; movestop(); //Go to the movestop function navigate(); void moveforward() //This function tells the robot to go forward Serial.println("Moving forward"); //digitalwrite(leftmotorbackward, LOW); digitalwrite(motor_r, HIGH); digitalwrite(motor_l, HIGH); void movebackward() Serial.println("Moving backward"); digitalwrite(motor_r, LOW); digitalwrite(motor_l, LOW); void moveleft() Serial.println("Moving left"); digitalwrite(motor_r, HIGH); digitalwrite(motor_l, LOW); //This function tells the robot to move backward //This function tells the robot to turn left void moveright() //This function tells the robot to turn right

Serial.println("Moving right"); digitalwrite(motor_r, LOW); digitalwrite(motor_l, HIGH); void movestop() //This function tells the robot to stop moving Serial.println("Stopping"); digitalwrite(speed_r, LOW); digitalwrite(speed_l, LOW); //digitalwrite(rightmotorforward, LOW); // digitalwrite(rightmotorbackward, LOW); void scan() //This function determines the distance things are away from the ultrasonic sensor Serial.println("Scanning"); Time = sonar.ping(); distance = Time / US_ROUNDTRIP_CM; delay(500); void navigate() Serial.println("There's an obstacle!"); servo.write(167); //Move the servo to the left (my little servos didn't like going to 180 so I played around with the value until it worked nicely) delay(1000); //Wait half a second for the servo to get there scan(); //Go to the scan function LeftDistance = distance; //Set the variable LeftDistance to the distance on the left Serial.println("Left distance = "); Serial.print(distance); servo.write(0); //Move the servo to the right delay(1000); //Wait half a second for the servo to get there scan(); //Go to the scan function RightDistance = distance; //Set the variable RightDistance to the distance on the right Serial.println("Right distance = "); Serial.print(distance); if(abs(rightdistance - LeftDistance) < 5) movebackward(); //Go to the movebackward function delay(200); //Pause the program for 200 milliseconds to let the robot reverse moveright(); //Go to the moveright function delay(100); //Pause the program for 200 milliseconds to let the robot turn right else if(rightdistance < LeftDistance) //If the distance on the right is less than that on the left then...

moveleft(); //Go to the moveleft function delay(100); //Pause the program for half a second to let the robot turn else if(leftdistance < RightDistance) //Else if the distance on the left is less than that on the right then... moveright(); //Go to the moveright function delay(100); //Pause the program for half a second to let the robot turn