# [SOLVED]Help with mikroC program of US 100 ultrasonic sensor please?

Status
Not open for further replies.

#### cheerio

##### Newbie level 6
Yellow all! I am asking for help regarding an unfinished project. My partner and I would like to use US- 100 ultrasonic sensor and PIC16f84a to trigger an alarm which would just be a buzzer. Sadly, though we can't seem to figure out the programming using the mikroC. All help is very, very much appreciated. Thanks and Godbless to all :smile:

CHEERIO
tell me prblm

cheerio

### cheerio

points: 2

#### cheerio

##### Newbie level 6
Thanks. This is very much appreciated!
actually we're really stuck on the programming part. Big time. :--)

#### Tahmid

Where exactly are you stuck? What are you having difficulties in while programming? Is there something that is unclear to you?

#### cheerio

##### Newbie level 6
To be honest, it is not clear to us what the function of the PIC16f84a is. . :-(
Pardon me for the late replies.

Last edited:

#### internetuser2k12

##### Banned
If you have an algorithm for your project post it and I will try to code in mikroC Pro.

#### cheerio

##### Newbie level 6
actually, i dont know how the sensor works. so, i might have the wrong algorithm. but here it goes...

supply voltage to VCC of sensor (using microcontroller) > transmitter on > receiver on > if obstacle is in range receiver sends signal to microcontroller > microcontroller tells buzzer to buzz

Thanks!

#### T3STY

##### Full Member level 4
What the...?? that's no algorithm, not even a little bit. Cheerio, you have no programming knowledge/experience, right? Then I assume you're *not* pretending someone to do the whole job but someone to put a pen in your hand and give you some paper... right?

Here's some help for starting...
whatever the ultrasonic sensor is the big steps are not really the ones you described. By fast examining your problem steps should be: send pulse to the sonar > start checking for the echo return > when echo arrives start buzzing > when echo ends stop buzzing. It should not be such a difficult task... You can use the RB0 pin as external interrupt and connect it to the echo pin of the ultrasonic sensor. When interrupt on RB0 is triggered you know there is echo so you start counting. When there's no more echo you check the count (probably you'd need some calculations) and you've got the distance of the object.

If you confirm my suppositions then you'll probably get helped better. Otherwise, people will keep asking which are your difficulties in programming assuming you have at least some programming knowledge.

p.s.
The ultrasonic sensor you're using is this one?
http://www.e-gizmo.com/KIT/images/ultrasonicsonar/ultrasonic sonar module 1r0.pdf

Last edited:
cheerio

### cheerio

points: 2

#### cheerio

##### Newbie level 6
What the...?? that's no algorithm, not even a little bit. Cheerio, you have no programming knowledge/experience, right? Then I assume you're *not* pretending someone to do the whole job but someone to put a pen in your hand and give you some paper... right?

Here's some help for starting...
whatever the ultrasonic sensor is the big steps are not really the ones you described. By fast examining your problem steps should be: send pulse to the sonar > start checking for the echo return > when echo arrives start buzzing > when echo ends stop buzzing. It should not be such a difficult task... You can use the RB0 pin as external interrupt and connect it to the echo pin of the ultrasonic sensor. When interrupt on RB0 is triggered you know there is echo so you start counting. When there's no more echo you check the count (probably you'd need some calculations) and you've got the distance of the object.

If you confirm my suppositions then you'll probably get helped better. Otherwise, people will keep asking which are your difficulties in programming assuming you have at least some programming knowledge.

p.s.
The ultrasonic sensor you're using is this one?
http://www.e-gizmo.com/KIT/images/ultrasonicsonar/ultrasonic sonar module 1r0.pdf
thank you so much mister.

i admit that my programming background to make this project is not that good and i think the steps you said were very accurate to what this project should be. so, thanks again!

#### T3STY

##### Full Member level 4
OK, so we know what's the situation at this time.
Now, I've never worked with any of those devices, I'd make some code for you but I'm sure it's almost useless if I don't have the device for testing.
Although, in the link I gave you at the bottom of the PDF there's an example code for gizDuino (a Lite version of Arduino). You might want to give it a look and also, people here who already worked with arduino and similar MCUs will be able to help you better with that code.

cheerio

### cheerio

points: 2

#### cheerio

##### Newbie level 6
actually, i cant afford to buy gizduino right now. i know it's already the economically friendly version of the arduino but still im kinda short of penny. life's hard, you know. so, i kind of decided to use pic16f84a.

i badly need all help i can get. any codes for this project in any programming language is a great help. thanks a lot guys.

Last edited:

#### Tahmid

What is the condition for alarming the buzzer?

Use the external interrupt feature. You can find it on page 31 of the 16F84A datasheet.

Set external interrupt on rising edge. Send a pulse to trigger the sensor. The pulse width should be ≧ 5µs. Upon interrupt start counting. Then, set external interrupt on falling edge. Upon interrupt stop counting. Now, from the count you need to calculate the time.

actually, i cant afford to buy gizduino right now. i know it's already the economically friendly version of the arduino but still im kinda short of penny. life's hard, you know. so, i kind of decided to use pic16f84a.
There are many PICs cheaper than PIC16F84A. You could use one of them as well.

From your previous posts, I think you will turn the buzzer on as long as the obstacle is within the sensor's range (2cm to 350cm). You don't need to actually calculate the range. Or do you?

cheerio

### cheerio

points: 2

#### cheerio

##### Newbie level 6
From your previous posts, I think you will turn the buzzer on as long as the obstacle is within the sensor's range (2cm to 350cm). You don't need to actually calculate the range. Or do you?
Yes exactly, I don't need to measure the distance between the obstacle and the sensor. All I wanted is for the buzzer to turn on while the obstacle is in range of the sensor. Wow, Im actually learning from you guys. Thanks so much.

By the way, what do you mean exact requirement?

#### Tahmid

That's part of what I meant: if you need measurement or not. The other thing I need to know is, how frequently are you going to check if obstacle is within sensor's range. Or will it be done continuously?

I'm guessing that if the obstacle is beyond the sensor's range, there will be no echo (signal back) from the sensor.

#### cheerio

##### Newbie level 6
The other thing I need to know is, how frequently are you going to check if obstacle is within sensor's range. Or will it be done continuously?
I wanted it to be continuously checking if there's an obstacle as long as the power supply is on.

#### Tahmid

First, let's not take any range calculation.

Just detection.

So, you could use something like this:

Code:
sbit TRIGGER at RB2_bit;
sbit BUZZER at RB7_bit;
void main() {
PORTA = 0;
TRISA = 0;
PORTB = 0;
TRISB = 1; //RB0 input for EXTERNAL INTERRUPT
INTF_bit = 0;
OPTION_REG = 0xC0; //RBPU disabled, rising edge interrupt
while (1){
TRIGGER = 1;
delay_us(6);
TRIGGER = 0;
delay_ms(100);
if (INTF_bit == 1){
BUZZER = 1;
INTF_bit = 0;
}
else{
BUZZER = 0;
}
}
}
You could even set external interrupt for falling edge to detect the "end" of the echo instead of the "beginning".

That should be clear enough. Now you can tweak it as necessary.

Hope this helps.
Tahmid.

cheerio

### cheerio

points: 2

yes! perfect.

#### cheerio

##### Newbie level 6
thank you so much for the help
really really appreciate it!

Status
Not open for further replies.