Final Project

I have noticed a critical issue that faces visually impaired people living in the Middle East region, the lack of visually impaired facilities such as tactile paving makes it impossible to them to live a normal life. At the begging I thought of attaching an ultrasonic sensor to a stick, however after a further research I decided to allocate the senor to the belt. My product consist of an ultrasonic sensor (SR-04) which measures distance, this sensor is connected to a AA tiny44, when an object is 1 meter to 3 meters close from the user a buzzer would create some kind of sound to alert the user, thus the user will immediately change his/her location in order to avoid the object.

First iteration

Design

I started by designing a simple prototype using card board to asses my design, below is an image of the first prototype. SR-04 sensor dimension: 452015 mm, the echo and trigger cylinder are 8mm radius.Thus, I have decided to create a box 505050 mm.

###### ADD image for first prototype

My cube was extremely huge which will make it impractical to have it on placed on your belt, thus I decided to remove the battery from the box and place it in the user pocket.

ADD image of 2nd prototype

3D design

I decided to use free cad software to design my product, the images below clearly describe the method I used to design.

ADD free cad images

I have used the Ultimaker 3, where I have uploaded free cad exported as mesh stl file to Cura.

Constrains: 1. I set the object up-side-down which made the printer print on empty space.( ultimaker 3 did a good job doing that) 2. The opening cylindering were very tiny, thus had to increase the diameter

Circuit design

The first step was to carefully review all your input and output and device data sheets and working principles. My input device is the sr-04 sensor, where my output devices are a LED and a buzzer. I ll be using a 9 volts battery, thus a 5v regulator must be added the circuit

SR-04 Ultrasonic sensor:

  1. 5v DC input
  2. Current 15 mA
  3. Measuring angle: 15 degree
  4. Accuracy: up to 3 mm
  5. Measuring distance: between 2 cm and 400 cm

The sr-04 sensor consist of a trigger and echo, where the you only need to supply a short 10uS pulse to the trigger input to start the ranging, an d then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a distance object that is pulse width and the range i n proportion .You can calculate the range through the time interval between sending trigger signal and receiving echo signal. Formula: uS / 58 = centimeters or uS / 148 =inch; or: the range = high level time velocity (340M/S) / 2; we suggest to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.''from the date sheet''.

In short a trigger would send a signal of 10-15 us, and the echo will be ready to recieve this signal, once this signal is received at the echo the time of this signal is used to get the distance in meters , you ll have to multiply the time of the echo signal by 340 m/s (speed of sound) divided by 2.

Kokopelli:

To design this circuit I will be using Kokopelli software. I used AA tiny 44 cad file designed by Neil and I modified it.

  1. I deleted the XCAL 1
  2. I added the 5v regulator LM3480 package number SOT 23
  3. I connected the regulator input and output to 0.1uf capacitor and to ground
  4. Added Pad by the regulator input for the battery
  5. Connected the regulator output to the aa tiny 44 Vcc
  6. Added a buzzer pad between PB3 and Vcc
  7. Added a LED pad between PA3 and Vcc (connected to 100 ohms resistor)
Add image here of Kokopelli design
Add image of the board after milling
add image of the board after soldering

Code:

  1. Set trigger, buzzer and LED as output
  2. set Echo as input
  3. set 5 v to trigger for 12us in order to send the signal
  4. Interrupt echo input pin when changed from low to high
  5. if echo receives high signal start the counter by setting the pre-scaler to 1
  6. Else ( if echo receives low signal) stop the counter by setting all the pre-scaler pins to 0
  7. then start measuring the time in seconds by dividing the TCNT 1 ( where the counter is saved ) by 1,000,000 (clock speed)
  8. Measure the distance in cm by multiplying the time by 0.034 and dividing it on 2.
  9. Finally if distance above 200 cm and below 400 cm turn on the buzzer
  10. The buzzer is turned on by setting the PB2 to zero as its connected to Vcc

Note: I have used register number 1 (16 bit register) TCNT1. Moreover, prescaler 1 has been used as the sr-04 maximuim distance is 4 meter which is 23,200 us = 0.0232 seconds. 16 bit (65536 value) divided by clock speed (1,000,000 hz) would equal to 0.065536 seconds till the counter overflows.

Constrains

  1. I mistakenly was reading the echo pin using Port instead of Pin
  2. I had the Mcros typo errors, I have added an extra bracket after register

Final code:

// 7th sense product
//
// HC-SR04 sonar sensor and buzzer code
//    
// when the distance is above 200 cm and below 400 cm the buzzer will turn on to alert the user
//
// Murad Mousa Saadeh
// 18/12/2017
//
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose. Copyright is
// retained and must be preserved. The work is provided
// as is; no warranty is provided, and users accept all
// liability.

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>


#define setbit(register,bit) (register |= (1 << bit))
#define clearbit(register,bit) (register &= ~(1 << bit))
#define testbit(register,bit) (register & (1 << bit))


int myTime=0;
int Distance=0;



ISR(PCINT0_vect){

if (testbit(PINA, PA0)){
  TCNT1 = 0;
  TCCR1B |= (0<<CS11);
  TCCR1B |= (1<<CS10); // These 2 register will set the prescaler to 1 and start the counter
 }
else
{
//stop counter and measure time
TCCR1B |= (0<<CS11);
TCCR1B |= (0<<CS10); // These 2 register will set the prescaler to 0 and stop the counter

myTime= TCNT1/1000000; // measure time in seconds
Distance= myTime*340/2; //distance in m

if (TCNT1 < 5000){
  clearbit(PORTA, PA3);// LED on
}
else {
setbit(PORTA, PA3); // LED off
}

}

}




int main(void) {



  setbit(DDRA,PA1);// set trig as output
  clearbit(DDRA,PA0);// set echo input
  setbit(DDRA,PA3); // set LED as output
setbit(PORTA,PA3);//set LED OFF

  sei(); //activate global interrupt
  GIMSK |= (1<<PCIE0); // interrupt in port A, could be done using mcros (GIMSK, PCIE0);
  PCMSK0 |= (1<<PCINT0); // interrupt in pin 0, could be done using mcros (PCMSK0, PCINT0);


   // main loop
   //
   while (1) {
      //
      // trigger pulse
      //

      clearbit(PORTA,PA1);

      setbit(PORTA,PA1);

      _delay_us(12);

      clearbit(PORTA,PA1);

      _delay_ms(1000); // increases time between measures


}
}