CamJam EduKit Robotics Worksheet Six Distance Sensor camjam.me/edukit

Similar documents
CamJam EduKit Robotics Worksheet Nine Obstacle Avoidance camjam.me/edukit

J. La Favre Controlling Servos with Raspberry Pi November 27, 2017

Fading a RGB LED on BeagleBone Black

Aim: To learn the resistor color codes and building a circuit on a BreadBoard. Equipment required: Resistances, millimeter, power supply

Project Kit Project Guide

Objectives: Learn what an Arduino is and what it can do Learn what an LED is and how to use it Be able to wire and program an LED to blink

Pibrella Fairground Ride. This lesson follows on from the Pelican Crossing lesson

Patton Robotics, LLC.

Bohunt School (Wokingham) Internet of Things (IoT) and Node-RED

CSE208W Lecture #1 Notes Barry E. Mapen

LEVEL A: SCOPE AND SEQUENCE

Measuring Distance Using Sound

Adafruit's Raspberry Pi Lesson 8. Using a Servo Motor

Pi-Cars Factory Tool Kit

Lab 2.4 Arduinos, Resistors, and Circuits

Digital Electronics & Chip Design

Moto1. 28BYJ-48 Stepper Motor. Ausgabe Copyright by Joy-IT 1

Circuit Board Assembly Instructions for Babuinobot 1.0

TV Remote. Discover Engineering. Youth Handouts

Musical Pencil. Tutorial modified from musical pencil/

SPACE WAR GUN KIT MODEL K-10. Assembly and Instruction Manual. Elenco Electronics, Inc.

Workshop 9: First steps in electronics

Build this Direct Digital Synthesizer "Development Kit" By: Diz Gentzow, W8DIZ

Activity 2: Opto Receiver

Two Hour Robot. Lets build a Robot.

Never power this piano with anything other than a standard 9V battery!

Peek-a-BOO Kit JAMECO PART NO / / Experience Level: Beginner Time Required: 1+ hour

Pololu DRV8835 Dual Motor Driver Kit for Raspberry Pi B+

Adafruit 16-Channel PWM/Servo HAT & Bonnet for Raspberry Pi

Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi

Controlling a Sprite with Ultrasound

National Quali cations Date of birth Scottish candidate number

EET 150 Introduction to EET Lab Activity 1 Resistor Color Codes and Resistor Value Measurement

A.M. WEDNESDAY, 19 May minutes

Congratulations on your purchase of the SparkFun Arduino ProtoShield Kit!

D.I.Y L.E.D CUBE 4X4X4. Level: Intermediate

IR add-on module circuit board assembly - Jeffrey La Favre January 27, 2015

EASY BUILD TIMER KIT TEACHING RESOURCES. Version 2.0 LEARN ABOUT SIMPLE TIMING CIRCUITS WITH THIS

Sten BOT Robot Kit 1 Stensat Group LLC, Copyright 2016

Introduction to the Laboratory

CodeBug I2C Tether Documentation

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

The Robot Builder's Shield for Arduino

RC Servo Interface. Figure Bipolar amplifier connected to a large DC motor

Oct 10 & 17 EGR 220: Engineering Circuit Theory Due Oct 17 & 24 Lab 4: Op Amp Circuits

Programmable Timer Teaching Notes Issue 1.2

The µbotino Microcontroller Board

1. Line Follower Placing the Line Follower Electrical Wiring of Line Follower Source Code Example and Testing...

1-1. Kirchoff s Laws A. Construct the circuit shown below. R 1 =1 kω. = 2.7 kω R 3 R 2 5 V

BAT DETECTOR A project of the Service Kring JOTA-JOTI.

Internet of Things Student STEM Project Jackson High School. Lesson 3: Arduino Solar Tracker

Nano v3 pinout 19 AUG ver 3 rev 1.

HEAT ACTIVATED SWITCH KIT

Lab. I Electrical Measurements, Serial and Parallel Circuits

Quantizer step: volts Input Voltage [V]

ECE 2010 Laboratory # 5 J.P.O Rourke

BAT BEACON A project of the Service Kring JOTA-JOTI. Manual Bat Beacon kit.

Resistance Measurements (Measure all of your resistors, since even those that are labeled the same can be at least a little different)

OTTO THE BIPEDAL ROBOT

Materials: resistors: (5) 1 kω, (4) 2 kω, 2.2 kω, 3 kω, 3.9 kω digital multimeter (DMM) power supply w/ leads breadboard, jumper wires

4ms SCM Breakout. Kit Builder's Guide for PCB v2.1 4mspedals.com

INSTANT ROBOT SHIELD (AXE408)

Smart Circuits: Lights On!

Arduino: Sensors for Fun and Non Profit

Available online Journal of Scientific and Engineering Research, 2018, 5(4): Research Article

DARK ACTIVATED COLOUR CHANGING NIGHT LIGHT KIT

Gertboard Assembly Manual Rev 1.1

Stand Alone VXO (SAVXO) Assembly Manual Manual Version 1.0B_

Electronic Components

Motor Driver HAT User Manual

Assembling the board. Getting started with Enviro phat

TEACHING RESOURCES SCHEMES OF WORK DEVELOPING A SPECIFICATION COMPONENT FACTSHEETS HOW TO SOLDER GUIDE GET IN TUNE WITH THIS FM RADIO KIT. Version 2.

Chapter #5: Measuring Rotation

Line Following Circuit Board Wiring Guide

GCSE (9-1) WJEC Eduqas GCSE (9-1) in ELECTRONICS ACCREDITED BY OFQUAL DESIGNATED BY QUALIFICATIONS WALES SAMPLE ASSESSMENT MATERIALS

Bill of Materials: Metronome Kit PART NO

Data Conversion and Lab Lab 1 Fall Operational Amplifiers

HANDS-ON LAB INSTRUCTION SHEETS MODULE

Series and parallel resistances

Coding with Arduino to operate the prosthetic arm

Electric Circuit I Lab Manual Session # 2

DIY KIT 141. Multi-Mode Timer

Physics 323. Experiment # 1 - Oscilloscope and Breadboard

Board Of Education, Revision C (28150)

TECH 3232 Fall 2010 Lab #1 Into To Digital Circuits. To review basic logic gates and digital logic circuit construction and testing.

Give one or two examples of electrical devices that you have personally noticed getting warm when they are turned on.

EE 209 Lab Range Finder

Experiment 1: Breadboard Basics

Unit 1 Electronics Name: Form:

Electronics (JUN ) General Certificate of Secondary Education June Thursday 5 June pm to 3.30 pm. Time allowed 2 hours

LAB 1 AN EXAMPLE MECHATRONIC SYSTEM: THE FURBY

ArduTouch Music Synthesizer

555 Morse Code Practice Oscillator Kit (draft 1.1)

Building The DC Beeper from Jackson Harbor Press A Morse code voltmeter / DC switch

Two-Tone Phototransistor Theremin Using a 556 Timer IC

Lab 06: Ohm s Law and Servo Motor Control

6.01, Fall Semester, 2007 Assignment 8, Issued: Tuesday, Oct. 23rd 1

Breadboard Primer. Experience. Objective. No previous electronics experience is required.

Explore and Challenge:

Total solder points: 101 Difficulty level: beginner advanced ELECTRONIC WATCHDOG K2655 ILLUSTRATED ASSEMBLY MANUAL

Transcription:

Distance Sensor Project Description Ultrasonic distance measurement In this worksheet you will use an HR-SC04 sensor to measure real world distances. Equipment Required For this worksheet you will require: Your robot, including the line follower installed in the last worksheet The HR-SC04 ultrasonic module Jumper leads (4 Male-Male) 330Ω resistor 470Ω resistor You will be adding the distance sensor to the breadboard used in the previous worksheet, and connecting it to the EduKit Motor Controller Board. HR-SC04 Ultrasonic Module volts. The HR-SC04 Ultrasonic Sensor module is used to detect the distance from the sensor to a surface. The Trigger: When the sensor is triggered by a voltage being applied to the Trig pin, it sends a high pitched (ultrasonic) sound from the speaker marked T (transmit). The voltage is only applied for 1 microsecond (0.0001 seconds). The Echo: When the sound is heard by the receiver (marked R), the Echo pin is taken high, which means that it is made to provide 5 By timing how long it is between the sound being produced and the sound being detected, and making a calculation, it is possible to work out the distance between the sensor and an object in front of it. The echo pin should stay high however long it takes the pulse to return. You work out the distance from how long the pulse is using the following formulae: distance = elapsed * 34326 where: elapsed is the length of the pulse (the time between trigger and echo) in seconds 34326 is the speed of sound in cm/s Since the ultrasound has to travel both to the object and echoed back from the object, it has covered twice the distance. Therefore, you need to halve the distance: distance = distance / 2.0 The HR-SC04 requires 5 volts to work. This is fed from the Raspberry Pi via the EduKit Motor Controller Board. It also outputs 5 volts on the Echo pin. However, the Raspberry Pi GPIO input pins should only be supplied with 3.3 volts. Therefore, you are going to use what is known as a voltage divider to split the output voltage between the GPIO input pin and the ground pin. This is made using resistors on the ultrasonic sensor s output pin, diverting some voltage to the GPIO input pin with the rest going to ground. Rev 1.01 Page 1 of 5 February 02, 2016

Resistors Resistors are a way of limiting the amount of electricity going through a circuit; specifically, they limit the amount of current that is allowed to flow. The measure of resistance is called the Ohm (Ω), and the larger the resistance, the more it limits the current. The value of a resistor is marked with coloured bands along the length of the resistor body. The EduKit is supplied with two sets of resistors. There are two 330Ω resistors and two 470Ω resistors. Only one of each is required; extras are supplied as spares. You can identify the resistors by the colour bands along the body. The colour coding will depend on how many bands are on the resistors supplied: If there are four colour bands: o The 330Ω resistor will be Orange, Orange, Brown, and then Gold. o The 470Ω resistor will be Yellow, Violet, Brown, and then Gold. If there are five colour bands: o The 330Ω resistor will be Orange, Orange, Black, Black, Brown. o The 470Ω resistor will be Yellow, Violet, Black, Black, Brown. The resistors in this circuit will be acting as a voltage divider, reducing the voltage of the output from the ultrasonic sensor (5 volts) down to a level that the Raspberry Pi can handle (3.3 volts). It does not matter which way round you connect the resistors. Current flows in both ways through them. Note: You may find that your kit has been supplied with THREE sets of resistors. One set is marked Yellow, Violet, Black Brown, Brown (4.7kΩ), and is not required. Rev 1.01 Page 2 of 5 February 02, 2016

Building the Circuit Push the ultrasonic sensor into the holes on the breadboard, with the pin marked GND in the same column as the jumper wire that goes to the ground of the EduKit Controller Board. Bend the legs of the two resistors and place them in the breadboard as on the diagram. Ensure that the correct resistors are placed in the right position. The 330Ω resistor (orangeorange-brown) goes between the Echo pin of the sensor and an unused column of the breadboard. The 470Ω resistor (yellowpurple-brown) goes between that same column and the ground (GND) pin. Then connect the breadboard column to socket 18 of the EduKit Controller Board. Connect the row with the sensors VCC connection (red wire in the diagram) to the EduKit Controller Board s 5v socket. The sonar module requires 5v to run. Connect the column with the sensors trigger (green wire in the diagram) to the EduKit Controller Board s socket marked #17 (The Pi s GPIO pin 17). Remember: the echo pin of the sensor module is connected to the Raspberry Pi GPIO with resistors and ground because the module uses a +5V level for a high, but this is too high for the inputs on the GPIO header, which only likes 3.3V. In order to ensure the Pi only gets hit with 3.3V you use a basic voltage divider formed with the two resistors. Code In a terminal window, change to the EduKitRobotics directory using: cd ~/EduKitRobotics/ Create a new text file 5-distance.py by typing the following: nano 6-distance.py Type in the following code: # CamJam EduKit 3 - Robotics # Worksheet 6 Measuring Distance import RPi.GPIO as GPIO # Import the GPIO Library import time # Import the Time library # Set the GPIO modes GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # Define GPIO pins to use on the Pi pintrigger = 17 pinecho = 18 print("ultrasonic Measurement") Rev 1.01 Page 3 of 5 February 02, 2016

# Set pins as output and input GPIO.setup(pinTrigger, GPIO.OUT) # Trigger GPIO.setup(pinEcho, GPIO.IN) # Echo try: # Repeat the next indented block forever while True: # Set trigger to False (Low) GPIO.output(pinTrigger, False) # Allow module to settle time.sleep(0.5) # Send 10us pulse to trigger GPIO.output(pinTrigger, True) time.sleep(0.00001) GPIO.output(pinTrigger, False) # Start the timer StartTime = time.time() # The start time is reset until the Echo pin is taken high (==1) while GPIO.input(pinEcho)==0: StartTime = time.time() # Stop when the Echo pin is no longer high - the end time while GPIO.input(pinEcho)==1: StopTime = time.time() # If the sensor is too close to an object, the Pi cannot # see the echo quickly enough, so it has to detect that # problem and say what has happened if StopTime-StartTime >= 0.04: print("hold on there! You're too close for me to see.") StopTime = StartTime break # Calculate pulse length ElapsedTime = StopTime - StartTime # Distance pulse travelled in that time is # time multiplied by the speed of sound (cm/s) Distance = ElapsedTime * 34326 # That was the distance there and back so halve the value Distance = Distance / 2 print("distance : %.1f" % Distance) time.sleep(0.5) # If you press CTRL+C, cleanup and stop except KeyboardInterrupt: # Reset GPIO settings GPIO.cleanup() Once you have typed all the code and checked it, save and exit the text editor with Ctrl + x then y then enter. Rev 1.01 Page 4 of 5 February 02, 2016

Running the Code To start the program, type the following into the terminal window: python3 6-distance.py Move an object (e.g. your hand) in front of the sensor and watch the distance change. If the code does not run correctly there may be an error in the code. Re-edit the code by using the nano editor, typing nano 6-distance.py. Next Steps The breadboard has double sided tape on the bottom. Remove the wax paper to stick it to the front of your robot so that the ultrasonic sensor points forward. Rev 1.01 Page 5 of 5 February 02, 2016