Post a new topicPost a reply Page 1 of 6   [ 56 posts ]
Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Sensor HC-sr04
PostPosted: Wed May 09, 2012 12:48 am 

Joined: Sun Feb 12, 2012 3:10 pm
Posts: 127
Hello,

I got to test this sensor a called HC-sr04, and I was wondering why it does not work!
It has vcc-gnd-trigger-echo.

this is the sample of the program for arduino:

#define CM 1 //Centimeter
#define INC 0 //Inch
#define TP 8 //Trig_pin
#define EP 9 //Echo_pin

void setup(){
pinMode(TP,OUTPUT); // set TP output for trigger
pinMode(EP,INPUT); // set EP input for echo
Serial.begin(9600); // init serial 9600
Serial.println("-------------------Ultra_Demo_Start---------------------------------");
}

void loop(){
long microseconds = TP_init();
Serial.print("ret="); //
Serial.println(microseconds);
long distacne_cm = Distance(microseconds, CM);
Serial.print("Distacne_CM = ");
Serial.println(distacne_cm);
delay(3000);
}

long Distance(long time, int flag)
{
/*

*/
long distacne;
if(flag)
distacne = time /29 / 2 ; // Distance_CM = ((Duration of high level)*(Sonic :340m/s))/2
// = ((Duration of high level)*(Sonic :0.034 cm/us))/2
// = ((Duration of high level)/(Sonic :29.4 cm/us))/2
else
distacne = time / 74 / 2; // INC
return distacne;
}

long TP_init()
{
digitalWrite(TP, LOW);
delayMicroseconds(2);
digitalWrite(TP, HIGH); // pull the Trig pin to high level for more than 10us impulse
delayMicroseconds(10);
digitalWrite(TP, LOW);
long microseconds = pulseIn(EP,HIGH); // waits for the pin to go HIGH, and returns the length of the pulse in microseconds
return microseconds; // return microseconds
}

LIbelium dev, what do I need to add in order to make it work with waspmote? I can't get any readings!
I don't get from teh guide how the digital pins work.. :(

And 1 difference i guess is that we have to set HIGH the vcc (arduino seems like it does it by default..)
This ultrasonic sensor should take 5 V.
Can you please help me out?!


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Wed May 09, 2012 8:28 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7475
maeishoj,

If you want to use this sensor with Waspmote, please take a look at this examples to see how to manage analogue and digital I/O of Waspmote. It will be useful for you.

Analog
Digital I/O

You should adapt your arduino code to Waspmote.

Could you please post a picture showing how are you connecting the sensor?

Best regards.


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Wed May 09, 2012 8:47 am 

Joined: Sun Feb 12, 2012 3:10 pm
Posts: 127
libelium-dev wrote:
maeishoj,

If you want to use this sensor with Waspmote, please take a look at this examples to see how to manage analogue and digital I/O of Waspmote. It will be useful for you.

Analog
Digital I/O

You should adapt your arduino code to Waspmote.

Could you please post a picture showing how are you connecting the sensor?

Best regards.


Hello dev!

I don't have a picture right now, but I can tell you how! :)
VCC I tried to connect it to both 3 and 5 V. GND TO GND. Then I connected Trigger to DIGITAL5 and Echo to DIGITAL7 (EP AND TP in that code).

All it has to do as I see is: First I have to power the sensor, so how would you suggest me to do that?
like this: digitalWrite(SENS_PW_3V3, HIGH); ? What about if I have to use the 5V ?
Then the steps for measuring are:
put down the trigger pin to be sure it's a clean read, wait 2 us, put it high for making a measurement,wait again, put it low again and then read the PulseIn (like i do with the other sensor I was using, that you helped me with):

digitalWrite(TP, LOW);
delayMicroseconds(2);
digitalWrite(TP, HIGH); // pull the Trig pin to high level for more than 10us impulse
delayMicroseconds(10);
digitalWrite(TP, LOW);
long microseconds = pulseIn(EP,HIGH); // waits for the pin to go HIGH, and returns the length of the pulse in microseconds

The example you linked me does not say much about it.. Because who cares in these situations about reading the value of a digital pin? The only thing they are used for is to trigger the measurement to happen, and the actual reading of the value is done with PulseIn right?
can you please try to help me out here?

I appreciate your help!


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Thu May 10, 2012 8:20 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7475
maeishoj,

You can search in this forum a few examples of how to use Waspmote sensors.

In the analogue example we gave to you can see the way to read your sensor output.

Appart of that, you should know if your sensor is powered to 3V3 or 5V and power it correctly.

Use the functions PWR.setSensorPower(SENS_5V,SENS_OFF); for 5V for example.

Hope this helps.

Regards


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Thu May 10, 2012 10:03 am 

Joined: Sun Feb 12, 2012 3:10 pm
Posts: 127
libelium-dev wrote:
maeishoj,

You can search in this forum a few examples of how to use Waspmote sensors.

In the analogue example we gave to you can see the way to read your sensor output.

Appart of that, you should know if your sensor is powered to 3V3 or 5V and power it correctly.

Use the functions PWR.setSensorPower(SENS_5V,SENS_OFF); for 5V for example.

Hope this helps.

Regards


Dear libelium-dev,

If it need 5V to power up do I use the example you gave me? PWR.setSensorPower(SENS_5V,SENS_OFF); --> SENS_OFF OR ON?? OFF shouldn't it power it off?

Also If I have to trigger a digital pin for it to start measuring and then set it low, this pin should be defined as input right? and if I do "digitalWrite(DIGITAL5, HIGH), this should trigger that pin high right? I think my problem is to actually power up the sensor correctly as I get nothing out of it for the moment.

can you please respond to this dev? Thanks a lot!


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Thu May 10, 2012 11:49 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7475
maeishoj,

Yest, it will power off if you use SENS_OFF argument. Take a look into WaspPWR.cpp where setSensorPower is defined. There you can see what does each argument.

maeishoj wrote:
Also If I have to trigger a digital pin for it to start measuring and then set it low, this pin should be defined as input right? and if I do "digitalWrite(DIGITAL5, HIGH), this should trigger that pin high right? I think my problem is to actually power up the sensor correctly as I get nothing out of it for the moment.

Yes. Besides that, you can read about how to use analog and digital I/O in Waspmote technical guide.

Regards


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Fri May 11, 2012 6:11 am 

Joined: Sun Feb 12, 2012 3:10 pm
Posts: 127
libelium-dev wrote:
maeishoj,

Yest, it will power off if you use SENS_OFF argument. Take a look into WaspPWR.cpp where setSensorPower is defined. There you can see what does each argument.

maeishoj wrote:
Also If I have to trigger a digital pin for it to start measuring and then set it low, this pin should be defined as input right? and if I do "digitalWrite(DIGITAL5, HIGH), this should trigger that pin high right? I think my problem is to actually power up the sensor correctly as I get nothing out of it for the moment.

Yes. Besides that, you can read about how to use analog and digital I/O in Waspmote technical guide.

Regards

dear dev,

I tried to use that line for turning on the sensor, and I believe it works as I think something is going one (i see the leds working periodically).
However in the serial monitor I see this if I use 5V : 'IN üIN ü'
The program should print "IN THE LOOP" as soon as the loop() function starts and then I don't know that strange character it outputs!Can you try to help me?
I can't believe it has to be such a hassle to goddamn read from a sensor! xD


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Fri May 11, 2012 9:15 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7475
maeishoj,

which baudrate did you use to open serial port with your serial monitor?

If you use default value, it should be 38400 bd.

Check this and let us know.

Regards.


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Fri May 11, 2012 7:33 pm 

Joined: Sun Feb 12, 2012 3:10 pm
Posts: 127
libelium-dev wrote:
maeishoj,

which baudrate did you use to open serial port with your serial monitor?

If you use default value, it should be 38400 bd.

Check this and let us know.

Regards.


Of course 38400. I also though it was set on a wrong value, but it is 38400. It start writing it correctly "IN .." and then those strange symbol.


Top
 Profile  
 
 Post subject: Re: Sensor HC-sr04
PostPosted: Sat May 12, 2012 5:59 pm 

Joined: Sun Feb 12, 2012 3:10 pm
Posts: 127
If u know what it may be Please let me know, even though rhis is not a priority atm.
Right now i am more focused on trying setting the mote in hybernation, and perform a task everyday at 23:00.

I am having trouble however, i read that in hibernate the jumper has to be off, but can i still have the usb cable attached and read print lines?

Please help me out, this is important.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 6   [ 56 posts ]
Go to page 1, 2, 3, 4, 5, 6  Next


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use