Automatic Vehicle Speed Reduction System Using RF ...

57 downloads 0 Views 1MB Size Report
ME 362: Instrumentation and Measurement Sessional. Automatic Vehicle Speed Reduction System Using RF. Technology & Accident Prevention system.
ME 362: Instrumentation and Measurement Sessional

Automatic Vehicle Speed Reduction System Using RF Technology & Accident Prevention system

Submitted by (Group B17) Fatema Tahsin Huda Munira (1210067) Mehedi Hasan Akash (1210076) Sukanta Debnath (1210084) Moinuddin Shuvo (120092)

Supervised by Aminul Islam Khan Anup Saha Partha Kumar Das

Copyright

Copyright © 2015 Bangladesh University of Engineering and Technology. All rights reserved. This work or any part of this work can’t be used prior to the permission of Bangladesh University of Engineering and Technology, Dhaka, Bangladesh. i

Abstract

The objective of this project is to automatically control the speed of the vehicles at speed restricted areas such as school and hospital zone, U-turn etc. and accident avoidance using ultrasonic sensor. At particular zone special kind of transmitters which are tuned at a frequency of 433MHZ are mounted. These transmitters continuously radiate RF signal. When the vehicle comes within this radiation the receiver in the vehicle gets activated. Whenever the vehicle is within the zone, the vehicle speed is controlled by receiving the signal i.e. every time the vehicle speed is decreased to some cutoff and kept constant until the vehicle moves out of the zone, and then the vehicle can get accelerated by itself. The ultrasonic sensor system continuously sends signals and monitors any car or other obstacles which are in front of car. The distance up to which ultrasonic sensor can work is not more than 4 meter. When any obstacle or vehicle detected by ultrasonic sensor system it will send signal to the arduino After receiving this signal arduino sends a signal to the motor driver to stop the car immediately.

ii

Dedication

We would like to dedicate our work to our beloved parents for their constant support and inspiration.

iii

Acknowledgement

We would like to express our earnest gratitude to our course instructors Aminul Islam Khan1, Anup Saha2 and Partha Kumar Das3 for their motivational support and constant inspiration. It would have been impossible for us to complete the project without their technical support. We would also like to post our gratitude to our classmates for their continuous support and cooperation and also helping us in all possible ways to reach the deadline of project submission.

1

Assistant Professor, Bangladesh University of Engineering and Technology

2

Lecturer, Bangladesh University of Engineering and Technology

3

Lecturer, Bangladesh University of Engineering and Technology

iv

Table of Contents Copyright………………………………………………………………………… i Abstract………………………………………………….……………………… ii Dedication…………………….……………………………………………….... iii Acknowledgement……………………………………………………………… iv Chapter 1: Introduction ………………………………………………………………… 1 1.1 Background of Project……………………………………………………1 1.2 Problem Statement…………………………………………………………2 1.3 Objectives……………………………………………………………….… 2 Chapter 2: Hardware Requirements…………………………………………………… 3 2.1 RF Module ……………………………………………………………….…3 2.2 Breadboard……………………………………………………………… 4 2.3 Arduino UNO……………………………………………………………… 4 2.4 Jump Wire………………………………………………………………… 5 2.5 L293D-Motor Driver………………………………………………………5 2.5.1 L293D Logic Table…………………………...……………………5 2.5.2 Working of L293D ……………………………………………….6 2.6 Ultrasonic Sensor…………………………………………………………..6 2.7 Wheels…………………………………………………………………….…6 2.8 DC Gear Motor……………………………………………………………..6 2.9 Lithium Polymer Battery…………………………………………………..7 Chapter 3: Wireless Communication……………………………………………….8 3.1 Radio Frequency Technology……………………………………… 8 3.1.1 Description…………………………………………………... 8 3.1.2 Properties of RF………………………………………………8 3.1.3 Advantages and Disadvantages……………………………… 9 Chapter 4: Over-speed Control System………………………………………………… 10 Chapter 5: Accident Control System……………………………………………………12 v

5.1 Description……………………………………………………………… 12 5.2 Ultrasonic Sensor……………………………………………………..…12 5.3 Working Principles………………………………………………………12 5.4 Specifications…………………………………………………………… 13 5.5 Advantages and Disadvantages……………………………………… 13 Chapter 6: Overview of Working Model……………………………………………… 14 Chapter 7: Circuit Diagram………………………………………………………………15 Chapter 8: Conclusions and Future Recommendations……………………………… 19 References………………………………………………………………………………... 20 Appendices………………………………….…………………………………………… 21

vi

List of Figures 1

Police reported Trend of Road Accidents & Fatalities (1970-2007)…………1

2.1

Radio frequency Module……………………………………………………..3

2.2

Breadboard………………………………………………………………….. 4

2.3

Microcontroller board………………………………………………………...4

2.4

Male to Male jumper Wire…………………………………………….……..5

2.5

L293D Motor Driver………………………………………………………....5

2.6

HC-SR05 Ultrasonic Sensor……………………………………….……….. 6

2.7

Wheels………………………………………………………………….….... 6

2.8

DC Gear Motor………………………………………………………….…...7

2.9

Lithium-Polymer Battery.................................................................................7

4

PWM output voltage waveforms………………………………………… 11

5

Working Principle of Ultrasonic sensor……………………………............12

6

Over-speeding vehicle approaching speed limit zone…………………...... 13

7.1

Flow chart for full working principle of project……………………..............15

7.2

Flow chart for RF Transmitter Power Supply…………………………….. 15

7.3

Flow chart for motor speed controlling…………………………………… 16

7.4

Arduino and RF transmitter connections………………………………….. 17

7.5

Arduino and L293D motor driver connections……………………………. 18

vii

Chapter 1 Introduction The following project will be concerned with the speed control of a vehicle using RF transmitter and receiver with the integration of obstacle detection and accident prevention with the help of Ultrasonic sensor. The transmitter has to be installed in required places where the speed limit of the vehicle has to be checked such as – Hospital, School, Highways, Government official buildings, U-Turns etc. The transmitter will transmit signal and the receiver has to be installed within the vehicle for speed controlling purpose. Whenever the vehicle is within the transmitter zone the speed of the vehicle is decreased to some cutoff and kept constant until the vehicle moves out of the transmitter zone. After that the vehicle can accelerate by itself. Ultrasonic sensor helps the vehicle to detect any obstacle in-front and preventing accidents by stopping the vehicle immediately.

1.1 Background of Project Every year a huge number of road accidents take place just because of careless driving of the drivers and people get hurt and killed because of this. The story is more hideous for those who gets badly injured and become physically disabled person. This must come to an end. The restless driving must be controlled. So we thought of introducing special safe zones over the country in which vehicles will automatically be forced to keep their velocity to some safe level and can not accelerate their vehicle while they are in that zone. These zones will be created by keeping focus in public places like Schools, Hospitals, Busy Roads, U-Turns etc. Here a statistics is given about road accidents over the year 1970 to 2007.

Fig.1: Police reported Trend of Road Accidents & Fatalities (1970-2007)

1

1.2 Problem Statement There are some roads in every state or country which deals with high traffic over the year. As a there must be a certain speed limit in those roads for convenient vehicle running. Also in Busy places like – Roads in front of Schools, Colleges, Universities, Government Official Buildings, Uturns etc. are always at high risk for occurring road accidents. So our group decided to make these important places a special safe zone for the children as well as the adults. This safe zone will ensure a certain speed limit of the vehicles so that these vehicles are forced to drive within or below a minimum speed limit whenever they are within that range.

1.3 Objectives The main objectives of the following projects are  Making the roads safer for every person in the world.  For controlling the irresponsible and reckless driving of the vehicle drivers.  Controlling speed of the vehicles in some special selected zones where the speed limit of the vehicle is to be set by the governing authority.  To make a vehicle that can protect itself from accident whenever it closes to another object or car with acceleration or high speed.

2

Chapter 2 Hardware Requirements The instruments used in the following project is listed below:         

RF transmitter receiver Bread Board Wheel – 4ps DC gear motor L293D IC Ultrasonic Sensor Arduino UNO Jumper Wire male to male connector Lithium-Polymer Battery (900mAh)

Short descriptions of these instruments are given below: 2.1 RF module: An RF module (radio frequency module) is a (usually) small electronic device used to transmit and/ or receive radio signals between two devices. An RF transceiver module incorporates both a transmitter and receiver. The circuit is typically designed for half-duplex operation, although fullduplex modules are available, typically at a higher cost due to the added

Fig. 2.1: Radio frequency module

3

2.2 Breadboard: Breadboard is a construction base for prototyping of electronics. Originally it was literally a bread board, a polished piece of wood used for slicing bread. A modern solderless breadboard consists of a perforated block of plastic with numerous tin plated phosphor bronze or nickel silver alloy spring clips under the perforations. The clips are often called tie points or contact points. The number of tie points is often given in the specification of the breadboard.

Fig. 2.2: Breadboard

2.3 Arduino UNO:

Fig. 2.3: Arduino UNO

The Uno is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with an AC-to-DC adapter or battery to get started. Differences with other boards: The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USB-to-serial converter. 4

2.4 Jump wire:

Fig 2.4.: Male to Male jumper Wire

A jump wire, is a short electrical wire with a solid tip at each end (or sometimes without them, simply "tinned"), which is normally used to interconnect the components in a breadboard. 2.5 L293D-Motor driver: L293D is a typical Motor driver or Motor Driver integrated circuit which is used to drive direct current on either direction. It is a 16-pin IC which can control a set of two DC motors simultaneously in any direction.

Fig. 2.5: L293D Motor Driver

2.5.1 L293D Logic Table: let’s consider a Motor connected on left side output pins (pin 3, 6). For rotating the motor in clockwise direction the input pins has to be given with Logic 1 and Logic 0. • Pin 2 = Logic 1 and Pin 7 = Logic 0 | Clockwise Direction • Pin 2 = Logic 0 and Pin 7 = Logic 1 | Anticlockwise Direction • Pin 2 = Logic 0 and Pin 7 = Logic 0 | Idle [No rotation] [Hi-Impedance state] • Pin 2 = Logic 1 and Pin 7 = Logic 1 | Idle [No rotation] 5

2.5.2: Working of L293D: The 4 input pins for this l293D, pin 2, 7 on the left and pin 15, 10 on the right as shown on the pin diagram. Left input pins will regulate the rotation of motor connected on the left side and right input for motor on the right hand side. The motors are rotated on the basis of the inputs provided at the input pins as LOGIC 1 or LOGIC 0.In simple we need to provide Logic 0 or 1 across the input pins for rotating the motor. 2.6 Ultrasonic Sensor: We used Ultrasonic sensor model (HC-SR05) for various advantages. Ultrasonic sensors overcome many of the weaknesses of IR sensors - they provide distance measurement regardless of color and lighting of obstacles. This one is a little bit more accurate and improved. They also provide lower minimum distances and wider angles of detection to guarantee that obstacles are not missed by a narrow sensor beam.

Fig. 2.6: HC-SR05 Ultrasonic Sensor

Fig. 2.7: Wheels

2.7 Wheels: Four wheels were used in this project. As the system is a Four-Wheel-Drive (FWD) we attached the wheels with four dc motors. The image of the wheels are attached for further convenience. 2.8 DC Gear Motor: For Four wheel drive operation we have used for DC gear motors. The speed of the motor is 140 RPM. The outer structure of the motor is made with plastic. The model number is DG01D.

6

Fig. 2.8: DC Gear Motor

2.9 Lithium-Polymer Battery: For the purpose of power supply to the motors we have used Lithium-Polymer 900mAh battery. For speeding up the vehicle we needed to supply high amount of power to the dc motors thus we used powerful battery. The images are inserted in the description.

Fig. 2.9: Lithium-Polymer Battery

7

Chapter 3 Wireless Communication Wireless communication is the transfer of information between two or more points that are not connected by an electrical conductor. The most common wireless technologies use radio. With radio waves distances can be short, such as a few meters for television or as far as thousands or even millions of kilometers for deep-space radio. 3.1 Radio Frequency Technology: Radio frequency (RF) is any of the electromagnetic wave frequencies that lie in the range extending from around 3 kHz to 300 GHz, which include those frequencies used for communications or radar signals. 3.1.1 Description: RF signals are high frequency alternating current (AC) signals composed of electromagnetic energy. RF propagation occurs at the speed of light and does not need a medium like air in order to travel. RF waves occur naturally from sun flares, lightning, and from stars in space that radiate RF waves as they age. Humankind communicates with artificially created radio waves that oscillate at various chosen frequencies. RF communication is used in many industries including television broadcasting, radar systems, computer and mobile platform networks, remote control, remote metering/monitoring, and many more. 3.1.2 Properties of RF: All radio frequency signals have the following properties:  Amplitude: The change in RF energy is known as “Amplitude” of a signal. Amplitude is the most basic quality of an RF signal. The higher the amplitude of an RF signal the further it will travel before becoming weakened to the point of being un-receivable  Frequency: Since amplitude is the most basic quality of an RF signal, information is conveyed by changing the amplitude of the RF signal over time. Transmission and reception are easier when the signal oscillates with a more or less regular rhythm. The time between one peak in the signal’s amplitude and the next peak is constant from peak to peak. The number of times per second that the signal’s amplitude peaks is the frequency of the signal.  Wavelength: The wavelength of an RF signal is a function of the signal’s frequency and its speed through space. If a signal’s wave front it traveling through space at a certain speed, and we know the amount of time between each peak, then we can calculate how far the signal will have traveled from one peak to the next. That distance is the signal’s wavelength.  Phase: Phase is a method of expressing the relationship between the amplitudes of two RF signals that have the same frequency. Phase is measured in degrees (like the degrees of a compass). To the Wireless Lan Engineer, phase is important because two signals that are 8

in phase add their energy together, resulting in a stronger signal. Two signals that are 180 degrees out of phase, completely cancel each other out.  Polarity: A radio wave is actually made of up of two fields:- One electric, One magnetic, The sum of these two field is called the “electromagnetic field”, when energy is transferred back and forth from one field to the other it is called “Oscillation”.  Reflection: Reflection occurs when a propagating electromagnetic wave strikes an object that has very large dimension in comparison to the wavelength of the propagating wave.  Refraction: Refraction describes the bending of a radio wave as it passes through a medium of different density.  Diffraction: Diffraction occurs when the radio path between the transmitter and receiver is obstructed by a surface that has sharp irregularities or another wise rough surface.  Absorption: Absorption occurs when the RF signal strikes an object and is absorbed into the material in such a manner that it does not pass through, reflect off, or bend around the object. 3.1.3 Advantages and Disadvantages of RF:  Advantages: wide bandwidth, small dimensions, used for designing high directive antennas.  Disadvantages: RF or Microwave works between 3 KHz to 300 GHz, needs special care to design circuits. Additional cable length takes into account.

9

Chapter 4 Over-speed Control System We will be controlling the speed of the vehicle by varying the speed of the DC motor. Basically there are three ways to vary the speed of DC motors. These ways are briefly described below:  



Mechanical Gears: With the use of mechanical gears to achieve the desired speed. Series Resistor: Reducing the motor voltage with series resistor. However this is inefficient as energy s wasted in the resistors and reduces torque. The current drawn by the motor increases as the load on the motor increases. More current means a larger voltage drop across the series resistor and therefore less voltage to the motor. The motor now tries to draw even more current resulting in the motor “stalling”. Pulse Width Modulation (PWM): By applying Full voltage supply to the motor in bursts or pulses, eliminating the series drop effect. This is called pulse width modulation (PWM). Shorter the pulses means the motor runs slowly, longer pulses make the motor run faster.

DC motors have been used in variable speed devices for a very long time. The versatile characteristics of dc motors can provide high starting torques which is required for traction drives. Control over a wide speed range, both below and above the rated speed can be very easily achieved. The methods of dc motor speed control are simpler and less expensive than those of alternating current motors. In this project Speed control is attained using PWM technique and PWM generation is done using microcontroller. Pulse Width Modulation: Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a modulation technique used to encode a message into a pulsing signal. Although this modulation technique can be used to encode information for transmission, its main use is to allow the control of the power supplied to electrical devices, especially to inertial loads such as motors. In addition, PWM is one of the two principal algorithms used in photovoltaic solar battery chargers. Thus for sending the signal in pulses we use radio frequency technology (RF) which is described in the previous chapter. To control the speed of the motor, all we need to do is to replace digitalWrite function on L293D enable pins to analogWrite. The speed of the motor depends on the value that was passed to the analogWrite function. We can only pass between 0 to 255. If we pass 0, then the motor will stop and if we pass 255 then it will run at full speed. If we pass value between 1 and 254, then the speed of the motor will vary accordingly. Working Principle of PWM: Pulse width modulation (PWM) is a method for binary signals generation which has 2 signal periods- high and low. The width (W) of each pulse varies between 0 and period (T). The main 10

principle is control of power by varying the duty cycle. Here the conduction time to the load is controlled. Let for a time t1 the input voltage appears across the load i.e. ON state and for t2 time the voltage across the load is zero. • The average voltage at output is given by Va = Vmax × Ia Here, TON

=Time period for Pulse ON,

TOFF

=Time period for Pulse OFF

• The average load current Ia = Va/R = kVs/R Total time period, T =t1 + t2, Duty cycle, k = t1/T • The duty cycle can be varied from 0 to 1 by varying t1, T or f. Therefore, the output voltage V0 can be varied from 0 to Vs by controlling k, and the power flow can be controlled. • As the time t1 changes the width of pulse is varied and this type of control is called pulse width modulation (PWM) control. For better understanding of PWM these diagrammatic representations can be used. These figures represent the waveforms obtained as output at different voltage requirements.

Fig. 4: PWM output voltage waveforms

11

Chapter 5 Accident Control System 5.1 Description: Driving is a compulsory activity for most people. People use their car to move from one place to other place. The number of vehicle is increasing day by day. It is produced tacked tightly and risk to accident. Nowadays, the numbers of accident is so high and uncertainly. Accident will occurs every time and everywhere and cause worst damage, serious injury and dead. Accidents are caused mostly due to the delay in applying of brakes. This work is designed to develop a new system that can solve this problem where drivers may not brake manually but the vehicles can stop automatically due to obstacles. 5.2 Ultrasonic sensor: Widely used sensors that are mainly used for the measuring of distances are Ultrasonic sensors (US). Since these ultrasonic sensors have provided a reliable source of obstacle detections. As ultrasonic sensors are not vision based they can be used very efficaciously under the conditions of poor lighting and objects which are transparent in nature Ultrasonic sensor (US) can provide the initial information on distance to obtain the parameters for further methods to perform task. They are signals that are almost like audible sound waves except those frequencies are higher. The ultrasonic transmitter has a piezoelectric crystal that resonates up to a required frequency. 5.3 Working principle: Ultrasonic sensors transmit ultrasonic waves from its sensor head and again receives the ultrasonic waves reflected from an object. By measuring the length of time from the transmission to reception of the sonic wave, it detects the position of the object.

Fig. 5: Working Principle of Ultrasonic sensor

12

5.4 Specification:           

Trigger Pin Format Sound Frequency Echo Pin Output Echo Pin Format Measurement Range Measurement Resolution Measurement Angle Measurement Rate Supply Voltage Supply Current Connector

: 10 µS digital pulse : 40 kHz : 0-Vcc : Output is DIGITAL and directly proportional with range. : 2cm ~ 4.5m : 0.3cm : up to 15 degree. : 40 Hz : 4.5V to 5.5V : 10 to 40mA : Standard 5-pin male connector.

Although Ultrasonic sensors are widely used for speed control technology but there comes some Advantages and disadvantages associated with it. Some of these are described below: 5.5 Advantages and Disadvantages: Advantages: 1. An ultrasonic sensor's response is not dependent upon the surface color or optical reflectivity of the object. 2. Ultrasonic sensors with digital (On/off) outputs have excellent repeat sensing accuracy. 3. The response of analog ultrasonic sensors is linear with distance. Disadvantages: 1. Ultrasonic sensor must view a surface (especially a hard, flat surface) squarely to receive ample sound echo .Also, reliable sensing requires a minimum target surface area, which is specified for each sensor type. 2. While ultrasonic exhibit good immunity to background noise, these sensors are likely to falsely respond to some loud noises, like the "hissing" sound produce by air hoses and relief valves. 3. Temperature, pressure, humidity, air turbulence affect ultrasonic sensor.

13

Chapter 6 Overview of working model An overview of the working model is described in this chapter keeping in focus the working principle of the vehicle. Working Principle: The RF transmitting circuit consist of a RF transmitter module. We used virtualWire library for which encoder was not needed. The voltage regulator circuit is obtains power from a 12 volt(1 A) battery which provides the motor with unregulated 12 volt supply and whereas arduino, motor driver and the receiver module receives a 5 volt regulated supply. DC motors are interfaced through a motor driver. When the RF transmitter is turned on, the data set by the user is encoded and sent to the Receiver module. The receiver module decodes the data and sends it to the arduino to compare the data embedded in it. If the speed of the DC motor is less than the limit zone, then arduino commands the motor driver to take no actions and the speed of the DC motor remains same. If the speed exceeds the set speed limit, the arduino instructs the motor driver to limit speed according to the zone thus preventing accidents. The representation below shows how the proposed system can be implemented

Fig. 6: Over-speeding vehicle approaching speed limit zone

14

Chapter 7 Circuit Diagram

Fig. 7.1: Flow chart for full working principle of project

Fig. 7.2: Flow chart for RF Transmitter Power Supply

15

Fig. 7.3: Flow chart for motor speed controlling

16

Fig. 7.4: Arduino and RF transmitter connections

17

Fig. 7.5: Arduino and L293D motor driver conncetions

18

Chapter 8 Conclusions and Future Recommendations Conclusions: We worked hard throughout the semester to make the project run. Although facing much difficulties and frustrating moment we have completed the project within time. We faced several hurdles doing the project. We fired the potentiometer twice. But all our efforts would be materialized if we are one step closer to building a safer road for a better future.

Future Recommendations: We are doing this project with keeping doors open for further modifications and more sophisticated analysis of speed controlling for vehicles. So some future scopes related to this project is given below:  We wish to make a vehicle that can locate its position from the available map of the city and decide by itself about the highest speed limit for any particular road or highway.  An autonomous vehicle is the ultimate target of this project that can run without the help of a driver and keeping the opportunity of the option from the operator of the car whether he or she would like to run the vehicle by himself/herself or run the vehicle by autonomous system.  In future we would like to recommend to introduce security system within the car and vehicle tracker with GPS data and speed of that vehicle from remote places.  In future we would like to work on a vehicle that would be able to detect speed limits of roads and highways from signboards along the road.

19

References 1. Aciatore, D.G, Histant, M.B, 2012, Introduction to Mechatronics and Measurement System, 4th ed, McGraw-Hill, NewYork, NY. 2. Robotics, Mechatronics and Artificial Intelligence, Newton C. Braga 3. For Motor Driver and Arduino Circuit Analysis, http://www.instructables.com/ 4. Troubleshooting, http://www.engineersgarage.com/ 5. For PWM generation and controlling, http://www.circuitstoday.com/ 6. For Practical instruction and troubleshooting, Youtube

20

Appendices Appendix A: Codes Code for Transmitter #include const int transmit_pin = 12;

void setup() { // put your setup code here, to run once: Serial.begin(9600); vw_set_tx_pin(transmit_pin); vw_setup(2000);

// Bits per sec

pinMode(13, OUTPUT);

}

void loop() {

char *msg2 ="1"; digitalWrite(13, HIGH); // Flash a light to show transmitting vw_send((uint8_t *)msg2, strlen(msg2)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(13, LOW);

}

21

Code for Receiver

#include

void setup() { Serial.begin(9600); // Debugging only Serial.println("setup"); pinMode(13,OUTPUT);//set pin as output pinMode(4,OUTPUT);//set pin as output vw_set_rx_pin(12); // Initialise the IO and ISR vw_setup(2000); // Bits per sec vw_rx_start();

// Start the receiver PLL running

}

void loop() { uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; if(vw_wait_rx_max(100))//(wait for msg from transmitter) { if (vw_get_message(buf, &buflen)) // Non-blocking { int i;

22

digitalWrite(13, true); // Flash a light to show received good message // Message with a good checksum received, dump it. Serial.print("Got: ");

for (i = 0; i < buflen; i++) { Serial.print(buf[i]); Serial.print(" "); if (buf[i]=='1') { digitalWrite(4,HIGH);

}

} Serial.println(""); digitalWrite(13, false); delay(300);

} } else digitalWrite(4,LOW);

}

23

Code for Motor #include

#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor. #define ECHO_PIN

11 // Arduino pin tied to echo pin on the ultrasonic sensor.

#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. int leftmotorforward =10; int leftmotor2forward=9; int rightmotorforward=6; int rightmotor2forward=5; NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. void setup() { // put your setup code here, to run once:

pinMode(13,OUTPUT);//set digitalpin 13 as output pinMode(4,INPUT);//set digitalpin 4 as intput pinMode(leftmotorforward,OUTPUT);//set digitalpin 10 as output pinMode(leftmotor2forward,OUTPUT);//set digitalpin 9 as output pinMode(rightmotorforward,OUTPUT);//set digitalpin 6 as output pinMode(rightmotor2forward,OUTPUT);// set digitalpin 5 as output

}

void loop() {

unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS). 24

long distance= uS / US_ROUNDTRIP_CM ;//distance calculated as cm

if(digitalRead(4)==HIGH && distance>25) { digitalWrite(13,LOW); speedcontrol();

}

else{ if(distance

Suggest Documents