ADC voltage level checking

High, I would appreciate some guidance regarding ADC voltage sampling. I'm monitoring a proximity sensor which outputs signals (motion detection) from between 0.8v >3.3v my ADC input is set to >= 2.5v threshold. I have no problem with a simple code sketch for sensing movement, however to avoid false triggers, I want to take four consecutive readings
including a short time delay between each. If each reading returns a high threshold signal level, then the detection is reliable, an output will then flag up a high or else remain low, until the next motion is detected. Can anybody help with advice and may be a sample code snippet please. regards Jevray.

create a bool flag variable. Before each analog read sequence, set the flag to true.
Use a for loop and read the analog value
Convert the analog reading to voltage
Compare the reading to your voltage reference, x >= 2.5
If the compare fails, set flag = false
continue for loop.

When the for loop completes, flag will be true if all readings met the test condition, or flag will be false if one or more failed.

@ mrburnette
Thanks for your prompt reply, I will post up my code as stands. I may need some guidance as my programming knowledge is very basic. I will see how I get on with your suggestion

@mrburnette
Further to my reply, this is my basic code that I need to work on.

// Basic code sketch
//
float volt, voltage; // output voltage from motion detector op amp
int ledPin = 10;     // led for testing detection
void setup() {
  pinMode (ledPin, OUTPUT);
}

void loop() {

  voltage = map(volt, 0, 1023, 0, 10);   // 0, 1023, 0, 10);
  volt = analogRead(A0);  // read signal from motion detector
  if (voltage >= 4.5) {   //  = 3 volts  // set threshold
    digitalWrite(ledPin, HIGH); // reached detector voltage output
    delay (100);
  }
  else {
    digitalWrite(ledPin, LOW);
  }
  delay(100);
}

I've altered my ideas slightly with the movement detection method. The changing rate of time in relation to the analogue movement (A0) returns a value from the equation. By setting a working value, (70) < > in my example code, will result in a true or false output. My code has took me hours to put together with my very limited knowledge, it compiles ok but I have no means of simulating, but making progress with a bread board mock up. I would appreciate help and advice by going over my code please.

#define motionAnalogPin A0
//#define readAnalog A0  // not used for  this sketch
int ledPin = 10;     // led detecting movement

void setup() {
  Serial.begin(9600);
  pinMode (ledPin, OUTPUT); // led for motion detection.

}     
void loop() {
  long sum = 0;
  int i, t;

  for (i = 0; i < 8; i++) {  // number of samples( trial 2 > 8 loops)
    t = analogRead(motionAnalogPin);    // detected motion levels from sensor opamp out = (0v>3.3v)
    delay(100);
    t = abs(t - analogRead(motionAnalogPin));
    sum += t;
  }
  Serial.println(sum / i);

  if (sum / i >= (70)) {
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
    delay(100);
  }
}

Please report on that before we move forward... it would be a good time to reveal more about that. For example, we have no idea how the sensors would normally behave because you didn't tell us anything about them at all, except the output voltage range. So please post a link to some detailed specifications.

It looks like your original question is premature, you're currently working on using only just one sensor. So the current question is really, "how do I interface this unknown sensor?". Understand, it's really hard to comment on the code for that, not knowing what it is.

Thank you for your reply, I have a radar motion sensor module type HCWL_0156 which will become part of a control system for detecting movement. The module is quite common and outputs a logic HIGH when motion is detected. However this module can present false trigger for several reasons, power line spikes_noise etc.
Delving into the schematic and taking some scope readings, directed my attention to the motion signal processing ic’s feedback point. The signal output here varies in amplitude dependant on what the sensor receives “doppler effect” from a moving target in it’s range. Signal pulse amplitudes vary from around 0.5v > 3v dependant on the moving targets distance, hence amplitude values depend on how near or far motion was detected.
My basic sketch was just a means of (a) setting a threshold point for the ADC input pulse signals of <> 2.8 volts HIGH / LOW. The question of spurious noise and short duration spikes can still cause unwanted triggering however. By calculating the duration and rate of change of the pulse samples (A0) offers a better method of adjustment to the samples and easier identification for genuine motion. I can’t claim originality for this idea or code snippet, but as to how successful it works will depend largely on how I have presented it in my sketch, so far it compiles ok.

Evaluating your code requires an exact understanding of the nature of the sampled signal, and algorithm(s) that you use to analyze it. You haven't yet provided either.

The signals on the ADC input (A0) vary in amplitude and time duration. They are +ve voltage pulses created by movement detected via the sensor. The function returns the time rate of change of the analog output (dy/dt) the value that I have set is greater than 70 (experimental value)
I have made up a jig using the motion sensor and in conjunction with the serial monitor, I'm able to make adjustments as required. My code seems to be functioning satisfactorily.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.