if you could explain this to me, or point me towards tutorials that could answer this that would help.
basically I am using four HC-SR04 rangefinders(call them A,B,C,D. or North,South,East,West.) on a ground station, have a button that records the random measurements, and if those measurements change then it sends a signal via transceivers to another station.
anyway what I am really asking is how do you take the random measurements from the four senors that you saved with the button press, and use the readings from all four independently?
it has the sonar only code under "Code for Just Reading Sonar Value:"
the sonar reading code is:
//send a trigger signal
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
//receive the trigger signal echo, and calculate cm to the object
valueSensor= pulseIn(echo, HIGH);
dist= valueSensor/58; //converts raw to cm, valueSensor/74/2 = inches
Serial.println(dist);
so you could do:
//the following four lins for each of the A,B,C,D
#define trig 7 //trigger pin on sonar module
#define echo 6 //echo pin
int dist; //how far the object is away from the module(cm)
int valueSensor = 0; //see here, just added this line
const int buttonPin = 2; // the number of the pushbutton pin
// Variables will change:
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
digitalWrite(trigA, HIGH);
delayMicroseconds(10);
digitalWrite(trigA, LOW);
valueSensorA= pulseIn(echoA, HIGH);
distB= valueSensorA/58;
digitalWrite(trigB, HIGH);
delayMicroseconds(10);
digitalWrite(trigB, LOW);
valueSensorB= pulseIn(echoB, HIGH);
distB= valueSensorB/58;
digitalWrite(trigC, HIGH);
delayMicroseconds(10);
digitalWrite(trigC, LOW);
valueSensorC= pulseIn(echoC, HIGH);
distC= valueSensorC/58;
digitalWrite(trigD, HIGH);
delayMicroseconds(10);
digitalWrite(trigD, LOW);
valueSensorD= pulseIn(echoD, HIGH);
distD = valueSensorD/58;
buttonState = reading;
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}