Help for analog signal on Arduino

I have an Arduino Leonardo and I need to connect an analog signal to the AD port.

The analog signal comes from an external device.

The device signal has two pins: GND and CONTROL.

The signal basically has two low noise states.

CONTROL - GND
1.1 Volts
0 volts

My program does the following:

When:

CONTROL - GND PROGRAM
1.1 Volts Runs A
0 Volts Runs B

My question is the connection of this signal (device) to the AD port of the Arduino.

In my assembly I connect Device GND to Arduino GND and CONTROL to Arduino A0 port directly.

Would this be the correct way?

Should there be a few more components to protect the circuits or even have an AD port read with less chance of errors?

Att,

Alysson

Assuming the wire lengths are reasonably short & tidy, those connections shoukd be ok.

The next question is : should (a) and (b) run continuously during the high/low states, or only when the input state changes.

Just when input state changes. This signal looks like a "push-button".

This could be a function that acts like a digitalRead().

/*
  read an analogue input pin and return LOW or HIGH
  In:
    pin to read
  Returns:
    LOW if signal below 500 mV, else HIGH
*/
uint8_t readUnknownDevice(uint8_t pin)
{
  // read the ananlog input
  int x = analogRead(pin);

  if (x < 100)
  {
    // if reading below roughly 500 mV, return LOW
    return LOW;
  }
  else
  {
    // if reading not below roughly 500 mV, return HIGH
    return HIGH;
  }
}

You can use it e.g. like

void loop()
{
  Serial.print(F("Unknown device signal "));
  Serial.println(readUnknownDevice(A0) == LOW ? "LOW" : "HIGH");
}

I'll leave the state change detection to you. It can be implemented in loop() or in another function that you can call from loop().

Code compiles, not tested.

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