Pages: 1 2 [3] 4   Go Down
Author Topic: multiple maxbotix LVEZ on one UNO?  (Read 4214 times)
0 Members and 1 Guest are viewing this topic.
Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

No daisy-chain, I am simply using your code, and separate sonars. If you check your original code
with my editing, you'll see tx,rx are just your same pins:
 
int SonarR = 5;
int TriggerR = 2;
int SonarL = 3;
int TriggerL = 4;
How are your sensors wired? I have only four wires coming from each sensor. For example the right sonic has +, -, RX to pin 2, and PWM to pin 5. Is that how your sensors are connected?

Quote
  pinMode(rxpin, INPUT);
Why is rx pin an input? Shouldn't it be an output just to trigger the sensor into reading?

Quote
    if(countL>prevCountL&countL>maxCountL){

s/b:

    if( countL > prevCountL && countL > maxCountL ) {

or as I prefer:

    if( (countL > prevCountL) && (countL > maxCountL) ) {
Were you going to change this in your code? It seems to work both ways, but it shouldn't since the single "&" is for binary.

Also I'm not getting the nine values in the array that get converted into mode even when I un-comment the "void printArray" part of the code. I am only getting the mode for each of the sensors.
if you could copy and paste the code as you are using it with your modifications it would be a big help. Thanks.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


If you check my code in post #20 you'll see:
Code:
  read_sonar( TriggerR, SonarR, rangevalueR, arraysizeR);
..........

/**********************************************************/
void read_sonar(int txpin, int rxpin, int* ary, int asiz)
{

Also, must be "&&" in the other, I forgot to fix it in post #20 code. It doesn't matter in regards
the 2nd sonar, 1st sample problem.
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do you have TX and RX in your code? Do you have TX wired up to something? And Why is RX an input instead of output? I'm missing something.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Local [temporary] variables are visible only inside the function, call them whatever you like.
I modified this to reflect the other changes I mentioned.

Code:
/**********************************************************/
void read_sonar(int trigpin, int pulsepin, int* ary, int asiz)
{
  pinMode(pulsepin, INPUT);

  for(int i = 0; i < arraysizeL; i++) {    
    digitalWrite(trigpin, HIGH);
    delay(20);
    digitalWrite(trigpin, LOW);
    ary[i] = pulseIn(pulsepin, HIGH) / 147;
    delay(100);
  }
}
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That makes more sense to me now. Thanks. But unfortunately the code only works good for a stationary robot ranging a stationary target (21" x 21" box. There's a 4-5 second lag to change the led's to reflect the change in range if I move the robot closer or farther away.  I changed some of your delays to delayMicroseconds and still get ok results. Still some spikes, though.  I think the main problem is with the inherent limitations of the sensor. It's fairly accurate but the accuracy isn't very repeatable (precise).
Quote
void read_sonar(int trigpin, int pulsepin, int* ary, int asiz)
{
  pinMode(pulsepin, INPUT);

  for(int i = 0; i < arraysizeL; i++) {                         
    digitalWrite(trigpin, HIGH);
    delayMicroseconds(20);
    digitalWrite(trigpin, LOW);
    ary = pulseIn(pulsepin, HIGH) / 147;
    //delay(100);
  }
}

I also tried it with the baud rate set to 57600 got the same results. The data sheet for the Maxsonar says 9600 baud, but it works ok anyway.  
The parallax ping sensor seems to be more accurate and precise, but it's footprint is so narrow that it's worthless for my robot. I might have to rethink my whole approach to my project.
« Last Edit: March 17, 2012, 10:28:56 pm by TeslaIaint » Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


I think the 4-5 sec delay on Leds you mention is simply because your range check covers 14 - 36".

I wouldn't remove the delay, but you might shorten it to 50-msec - per the EZ datasheet.

Also, the Maxsonar 9600 bps is only if you use the RS232 mode output, which you're not using.
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think the 4-5 sec delay on Leds you mention is simply because your range check covers 14 - 36".

Can you elaborate on this?



The following code cuts the delay to about 2 seconds from the longer delay. I don't care about the LED's but at the moment they are simulating motors.

Code:
 for(int i = 0; i < arraysizeR; i++)
  {    
    digitalWrite(TriggerR, HIGH);
    delayMicroseconds(200);
    digitalWrite(TriggerR, LOW);
    pulseR = pulseIn(SonarR, HIGH);
    rangevalueR[i] = pulseR/147;
    delay(50);
    

Do you agree with these delays?

« Last Edit: March 18, 2012, 01:13:14 am by TeslaIaint » Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Delays look good.

Quote
But unfortunately the code only works good for a stationary robot ranging a stationary target (21" x 21" box. There's a 4-5 second lag to change the led's to reflect the change in range if I move the robot closer or farther away.

I guess I didn't understand what this meant.
Logged

Arges, Romania
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!
Logged

Arges, Romania
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello! I am working on a project on human presence detection. I have ordered 2 maxbotix ez3 an arduino uno and a buzzer. I want my sensors to detect presence one at a time so that I can detect when the person is inside a room. I can't find the tutorial where I connect the to sensors to the Arduino Uno. Please, can you help me?
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It depends on what mode you want to connect them.
Read through the Product Documentation links from this link: http://www.maxbotix.com/products/MB1030.htm

And another:  http://www.arduino.cc/playground/Main/MaxSonar

If you just want to detect the presence of a person, passive infrared sensors are made just for that. Ultrasonic sensors are made for sensing distance. What exactly are you trying to accomplish? If you are more specific, we could be of more help.
Logged

Arges, Romania
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to put the two sensors on each side of the door.If a person comes inside the room, sensor 1 will detect motion and then sensor 2. If the person comes out of the room the motion will be detected by sensors 2 1. Unfortunately, I found out late that it was much easier to use a PIR sensor. My coordonator told me to use ultrasonic sensors.So I have to use them for my project. And I can't change the sensors now because I have only 2 weeks until I have to present my project.
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the maxbotix sensors will work, and if they are on opposite sides of the doorway they won't interfere with each each other. check the links from my last post. Get them wired up and write some code. Post a schematic and your code here, and I'll check back to help you.
Logged

Arges, Romania
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is the sketch I've done. I'm not sore if it's correct. I've used daisy chaining.I'll work tonight on the source code. Is the sketch ok?

* Doc1.docx (26.42 KB - downloaded 15 times.)
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

very good sketch! I think you should try to use the pwm mode of the maxbotix sensor. It's not much different from what you are doing now. You don't have to daisy chain it either. They won't interfere. They are on different sides If the door right? I'll walk you through it. Just post some code using the links I gave you. If you don't understand I'll help you. I know it's frustrating, but I'm here to help. We'll make it happen.  
« Last Edit: July 01, 2012, 12:51:35 am by TeslaIaint » Logged

Pages: 1 2 [3] 4   Go Up
Jump to: