Hi all,
Apologies as this is a little long and I am quite new to this -- I followed this tutorial (electrojoystick.com) to get a Maxbotix LV-EZ1 sensor sending data via analog output to an Uno board connected via USB to a Macbook Pro. I get accurate data into the serial monitor and can read it in Max/MSP (final goal) -- this part is working!
I would like to know how many of these sensors I can use with one Uno board. Right now I have two connected in parallel but only one is reading with any accuracy; the other is printing to the serial bus correctly, but always 6 inches. Both are powered by the single 5v pin, each connected to separate GND pins and into analog 0 and 1 respectively. I have been trying to get values from each in alternation by repeating the code from the tutorial with each analog pin:
int configPin = 13; //Set the sonar Calibration Pin
void setup() { //begin of program
Serial.begin(9600); //serial baud rate 9600
pinMode(configPin,OUTPUT); //make Calibration pin output
}
void loop(){ //looping of program
digitalWrite(configPin,HIGH); //raise the reset pin high
delay(200); //start of 1st calibration ring
float sensorvalue1 = analogRead(0); //get analog sensor value from pin 0
float inchvalue1 = (254.0/1024.0) 2.0 sensorvalue1; //convert to inches
Serial.print("01 "); //print inch text
Serial.println(inchvalue1); //print inch value
delay(100); //optional delay 100 ms
digitalWrite(configPin,LOW); //turn off 1st Calibration ring and sensor
delay(200); //delay between cycles
digitalWrite(configPin,HIGH); //raise the reset pin high
delay(200); //start of 2nd calibration ring
float sensorvalue2 = analogRead(1); //get analog sensor value from pin 1
float inchvalue2 = (254.0/1024.0) 2.0 sensorvalue2; //convert to inches
Serial.print("02 "); //print inch text
Serial.println(inchvalue2); //print inch value
delay(100); //optional delay 100 ms
digitalWrite(configPin,LOW); //turn off 2nd Calibration ring and sensor
delay(100); //delay 100 ms
}
Is the code wrong, or do I have to change how things are connected? Do I need all of this code toggling the configuration pin? Do I need to establish separate configPin for each analog pin I'm using? I have tried without it and it seems to make the readings more accurate, but I don't understand how it works exactly. For the wires coming out of the same pin on the Uno, I just have the exposed copper wrapped together, no resistors or anything like that.
If I am posting in the wrong place please re-direct me.
Thanks!