Specification: 1 Specification



Similar documents
Ultrasonic Distance Measurement Module

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

SRF08 Ultra sonic range finder Technical Specification

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Electronic Brick of Current Sensor

Section 14. Compare/Capture/PWM (CCP)

Lab 6 Introduction to Serial and Wireless Communication

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

SPI. Overview and Use of the PICmicro Serial Peripheral Interface. Getting Started: SPI

Microcontroller Programming Beginning with Arduino. Charlie Mooney

Arduino Lesson 16. Stepper Motors

Accurate Measurement of the Mains Electricity Frequency

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Embedded Systems Design Course Applying the mbed microcontroller

Web Site: Forums: forums.parallax.com Sales: Technical:

Interfacing Analog to Digital Data Converters

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

ET-BASE AVR ATmega64/128

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Timer A (0 and 1) and PWM EE3376

Design And Implementation Of Bank Locker Security System Based On Fingerprint Sensing Circuit And RFID Reader

Web Site: Forums: forums.parallax.com Sales: Technical:

DEPARTMENT OF ELECTRONICS ENGINEERING

IR Communication a learn.sparkfun.com tutorial

4. Optical position sensor, photo-current measurement

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

Wireless Security Camera

NHD-0420D3Z-FL-GBW-V3

Pulse Width Modulation Applications

Arduino Lesson 13. DC Motors. Created by Simon Monk

MicroMag3 3-Axis Magnetic Sensor Module

AC : PRACTICAL DESIGN PROJECTS UTILIZING COMPLEX PROGRAMMABLE LOGIC DEVICES (CPLD)

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

DS1307 Real Time Clock Breakout Board Kit

An Introduction to MPLAB Integrated Development Environment

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Arduino Motor Shield (L298) Manual

Basic Pulse Width Modulation

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

Technical Data Sheet UM-005. UM005-doc In reference to UM005-c-01.04

Controlling a Dot Matrix LED Display with a Microcontroller

I 2 C Master Mode Overview and Use of the PICmicro MSSP I 2 C Interface with a 24xx01x EEPROM

40-Segment 2.54 pitch LED Bar Display Board User s Guide

Arduino Lesson 4. Eight LEDs and a Shift Register

Software Manual RS232 Laser Merge Module. Document # SU Rev A

C4DI Arduino tutorial 4 Things beginning with the letter i

Technical data. General specifications. Indicators/operating means. 30 Hz Multiplex operation 30 Hz / n, n = number of sensors, n 5

Lecture 7: Programming for the Arduino

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Preset Counter signo 721

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Optimizing VCO PLL Evaluations & PLL Synthesizer Designs

Peak Power Tracker Circuit Description (from

Pmod peripheral modules are powered by the host via the interface s power and ground pins.

CHAPTER 11: Flip Flops

PCAN-MicroMod Universal I/O Module with CAN Interface. User Manual. Document version ( )

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK

LCD I 2 C/Serial RX Backpack. Data Sheet. LCD to I2C/Serial RX Backpack I2C or Serial RX communication with Standard 16 Pin LCD modules

Using The PIC I/O Ports

A Lesson on Digital Clocks, One Shots and Counters

How To Control A Car With A Thermostat

A Lesson on Digital Clocks, One Shots and Counters

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Real-Time Application Surveillance Security System Based on LabVIEW

HT1632C 32 8 &24 16 LED Driver

Small Hardware Development and Prototyping Board for the SX28

Application Note. Sharp Memory LCD Technology

A Surveillance Robot with Climbing Capabilities for Home Security

A simple RF/Microwave frequency counter

Technical data. General specifications. Indicators/operating means. Electrical specifications Operating voltage U B Power consumption P 0 Interface

Lab Experiment 1: The LPC 2148 Education Board

DS1621 Digital Thermometer and Thermostat

Adding Heart to Your Technology

DS Wire Digital Thermometer and Thermostat

C Programming Structure of a C18 Program

1-Mbit (128K x 8) Static RAM

HT46R14A Single Phase AC Induction Motor Frequency Converter Application

1602 LCD adopts standard 14 pins(no backlight) or 16pins(with backlight) interface, Instruction of each pin interface is as follows:

Measuring Resistance Using Digital I/O

Programming the Arduino

Working with microcontroller-generated audio frequencies (adapted from the Machine Science tutorial)

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Lecture 22: C Programming 4 Embedded Systems

SAH2217 Enhanced ATHEROS GPS Module with ultra high sensitivity and antenna open/short detection/protection

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Keil C51 Cross Compiler

Crazy Alarm Clock L A K S H M I M E Y Y A P P A N J A M E S K A Y E W I L L I A M D I E H L C O N G C H E N

FEATURES DESCRIPTION APPLICATIONS BLOCK DIAGRAM. PT2248 Infrared Remote Control Transmitter

User and installation manual

Serial Communications

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

ZX-NUNCHUK (# )

Transcription:

Arduino Ultrasonic Range Detection Sensor A guide to using the Arduino Ultrasonic Range Detection Sensor with Arduino in order to calculate distances from objects. In this case I m also altering the output of an LED with PWM according to how close an object is to the sensor. So the nearer you are the brighter the LED. So if we start with the Arduino Ultrasonic Range Detection Sensor, it s an IC that works by sending an ultrasound pulse at around 40Khz. It then waits and listens for the pulse to echo back, calculating the time taken in microseconds (1 microsecond = 1.0 10-6 seconds). You can trigger a pulse as fast as 20 times a second and it can determine objects up to 3 metres away and as near as 3cm. It needs a 5V power supply to run. Adding the Arduino Ultrasonic Range Detection Sensor to the Arduino is very easy, only 4 pins to worry about. Power, Ground, Trigger and Echo. Since it needs 5V and Arduino provides 5V I m obviously going to use this to power it. Below is a diagram of my Arduino Ultrasonic Range Detection Sensor, showing the pins. There are 2 sets of 5 pins, 1 set you can use, the other is for programming the PIC chip so don t touch them! 1 Specification Specification: Working Voltage : 5V(DC) Working Current : max 15 ma Working frequency : 40HZ Output Signal : 0-5V (Output high when obstacle in range)

Sentry Angle : max 15 degree Sentry Distance : 2cm - 500cm High-accuracy : 0.3cm Input trigger signal : 10us TTL impulse Echo signal : output TTL PWL signal Size : 45*20*15mm Note : This module is not suitable to connect with electric power, if you need to connect this module with electronic power,then let the GND terminal of this module to be connected first,otherwise, it will affect the normal work of the module 2 Interface Interface:

Pin: 1:VCC ; 2:trig(T);3:echo(R);4:GND 3 Usage: Supply module with 5V, the output will be 5V while obstacle in range, or 0V if not. The out pin of this module is used as a switching output when anti-theft module, and without the feet when ranging modules, Note : the module should be inserted in the circuit before been power, which avoid producing high level of misoperation ;if not, then power again. Module Working Principle: (1) Adopt IO trigger through supplying at least 10us sequence of high level signal, (2) The module automatically send eight 40khz square wave and automatically detect whether receive the returning pulse signal, (3) If there is signals returning, through outputting high level and the time of high level continuing is the time of that from the ultrasonic transmitting to

receiving. Test distance = (high level time * sound velocity (340M/S) / 2, The circuit: Very, very simple circuit, I ve used the breadboard to share the GND connection and to add the LED which I could probably have done with out the breadboard. You ll see the most complex thing is the code later on. The sketch: All the work is done here, I ve added code that averages the distance readings to remove some of the jitter in the results as the DYP-ME007 is calculating distances very rapidly and there can be a lot of fluctuation. Also I convert the time in microseconds to distance by dividing the time by 58. Why 58? Well because if you take the time in microseconds for a pulse to be sent and received e.g. for 1 meter it takes about 5764 microseconds at least from my wall anyway. If I divide this time by the distance in cm in I will get 57.64 so I just round this up you can calculate distance in any other unit with this method. Here I ve also decided that for every cm under 255 my LED will get 1 step brighter. I ve been lazy here for the sake of the sensors 3 metre range I didn t see the point in making this any more complicated. Otherwise I would calculate the brightness on the percentile of proximity out of total range. There are three code for you to test, there must be one you can pass the test :

1 Test Code: int pingpin = 13; int inpin = 12; long microseconds; void setup() Serial.begin(9600); void loop() long duration, inches, cm; digitalwrite(pingpin, LOW); delaymicroseconds(2); digitalwrite(pingpin, HIGH); delaymicroseconds(10); digitalwrite(pingpin, LOW); delaymicroseconds(2); pinmode(pingpin, OUTPUT); pinmode(inpin, INPUT); duration = pulsein(inpin, HIGH); inches = microsecondstoinches(duration); cm = microsecondstocentimeters(duration); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); long microsecondstoinches(long microseconds) return microseconds / 74 / 2; long microsecondstocentimeters(long microseconds) return microseconds / 29 / 2;

2 Example Code 1: // variables to take x number of readings and then average them // to remove the jitter/noise from the DYP-ME007 sonar readings const int numofreadings = 10; // number of readings to take/ items in the array int readings[numofreadings]; // stores the distance readings in an array int arrayindex = 0; // arrayindex of the current item in the array int total = 0; // stores the cumlative total int averagedistance = 0; // stores the average value // setup pins and variables for DYP-ME007 sonar device int echopin = 2; // DYP-ME007 echo pin (digital 2) int initpin = 3; // DYP-ME007 trigger pin (digital 3) unsigned long pulsetime = 0; // stores the pulse in Micro Seconds unsigned long distance = 0; // variable for storing the distance (cm) // setup pins/values for LED int redledpin = 9; // Red LED, connected to digital PWM pin 9 int redledvalue = 0; // stores the value of brightness for the LED (0 = fully off, 255 = fully on) //setup void setup() pinmode(redledpin, OUTPUT); // sets pin 9 as output pinmode(initpin, OUTPUT); // set init pin 3 as output pinmode(echopin, INPUT); // set echo pin 2 as input // create array loop to iterate over every item in the array for (int thisreading = 0; thisreading < numofreadings; thisreading++) readings[thisreading] = 0; // initialize the serial port, lets you view the // distances being pinged if connected to computer Serial.begin(9600); // execute void loop() digitalwrite(initpin, HIGH); // send 10 microsecond pulse delaymicroseconds(10); // wait 10 microseconds before turning off digitalwrite(initpin, LOW); // stop sending the pulse pulsetime = pulsein(echopin, HIGH); // Look for a return pulse, it should be high as the pulse goes low-high-low distance = pulsetime/58; // Distance = pulse time / 58 to convert to cm.

total= total - readings[arrayindex]; // subtract the last distance readings[arrayindex] = distance; // add distance reading to array total= total + readings[arrayindex]; // add the reading to the total arrayindex = arrayindex + 1; // go to the next item in the array // At the end of the array (10 items) then start again if (arrayindex >= numofreadings) arrayindex = 0; averagedistance = total / numofreadings; // calculate the average distance // if the distance is less than 255cm then change the brightness of the LED if (averagedistance < 255) redledvalue = 255 - averagedistance; // this means the smaller the distance the brighterthe LED. analogwrite(redledpin, redledvalue); // Write current value to LED pins Serial.println(averageDistance, DEC); // print out the average distance to the debugger delay(100); // wait 100 milli seconds before looping again 3 Example Code 2: //////////////////////////////////////////////////////////////////////////////// // // PIC16F877 + DYP-ME007 + LCD03 example // Written October 2005 by Gerald Coe, using HITECH PIC16 compiler // // Note - assumes a 20MHz crystal, which is 5MHz timer clock // A 1:4 prescaler is used to give a 1.25MHz timer count (0.8uS per tick) // // This code is Freeware - Use it for any purpose you like. // /////////////////////////////////////////////////////////////////////////////// #include <pic.h> #include <stdio.h> CONFIG(0x3b32); #define trig #define echo RB0 RB1

void clrscn(void); void cursor(char pos); void print(char *p); void setup(void); unsigned int get_srf04(void); // prototypes char s[21]; // buffer used to hold text to print void main(void) unsigned int range; setup(); clrscn(); cursor(2); sprintf(s,"srf04 Ranger Test"); print(s); // sets up the PIC16F877 I2C port // clears the LCD03 disply // sets cursor to 1st row of LCD03 // text, printed into our buffer // send it to the LCD03 while(1) // loop forever range = get_srf04(); // get range from srf04 (round trip flight time in 0.8uS units) cursor(24); // sets cursor to 2nd row of LCD03 sprintf(s,"range = %dcm ", range/72); // convert to cm print(s); // send it to the LCD03 cursor(44); // sets cursor to 3rd row of LCD03 sprintf(s,"range = %dinch ", range/185); // convert to inches print(s); // send it to the LCD03 TMR1H = 0; SRF04 ranging is not too rapid TMR1L = 0; away before we start the next one T1CON = 0x21; TMR1IF = 0; while(!tmr1if); TMR1ON = 0; // 52mS delay - this is so that the // and the previous pulse has faded // 1:4 prescale and running // wait for delay time // stop timer unsigned int get_srf04(void) TMR1H = 0xff; TMR1L = -14; // prepare timer for 10uS pulse

T1CON = 0x21; TMR1IF = 0; trig = 1; while(!tmr1if); trig = 0; TMR1ON = 0; // 1:4 prescale and running // start trigger pulse // wait 10uS // end trigger pulse // stop timer TMR1H = 0; TMR1L = 0; T1CON = 0x20; TMR1IF = 0; while(!echo &&!TMR1IF); TMR1ON = 1; while(echo &&!TMR1IF); TMR1ON = 0; return (TMR1H<<8)+TMR1L; in 0.8uS units // prepare timer to measure echo pulse // 1:4 prescale but not running yet // wait for echo pulse to start (go high) // start timer to measure pulse // wait for echo pulse to stop (go low) // stop timer // TMR1H:TMR1L contains flight time of the pulse void clrscn(void) SEN = 1; while(sen); // send start bit // and wait for it to clear SSPBUF = 0xc6; while(!sspif); // LCD02 I2C address // wait for interrupt // then clear it. SSPBUF = 0; // address of register to write to SSPBUF = 12; // clear screen SSPBUF = 4; // cursor off PEN = 1; while(pen); // // send stop bit

void cursor(char pos) SEN = 1; while(sen); // send start bit // and wait for it to clear SSPBUF = 0xc6; while(!sspif); // LCD02 I2C address // wait for interrupt // then clear it. SSPBUF = 0; // address of register to write to SSPBUF = 2; // set cursor SSPBUF = pos; // PEN = 1; while(pen); // // send stop bit void print(char *p) SEN = 1; while(sen); // send start bit // and wait for it to clear SSPBUF = 0xc6; while(!sspif); // LCD02 I2C address // wait for interrupt // then clear it. SSPBUF = 0; // address of register to write to while(*p) SSPBUF = *p++; // write the data

PEN = 1; while(pen); // // send stop bit void setup(void) unsigned long x; TRISB = 0xfe; PORTB = 0xfe; // RB0 (trig) is output // and starts low TRISC = 0xff; PORTC = 0xff; SSPSTAT = 0x80; SSPCON = 0x38; SSPCON2 = 0x00; SSPADD = 50; // SCL = 91khz with 20Mhz Osc for(x=0; x<300000l; x++); // wait for LCD03 to initialise