analog reading a noisy voltage

Hey!
I have this voltage
click here for the image or download it from the attachments

A is the voltage I want to keep (it indicates the button I need to press)
B is the voltage that I don’t need

How do I make it so if the button I need is clicked a led will be turned on?

int smooth(int sensor){
  int i;
  int value = 0;
  int numReadings = 10;

  for (i = 0; i < numReadings; i++){
    // Read light sensor data.
    value = value + analogRead(sensor);

    // 1ms pause adds more stability between reads.
    delay(1);
  }

  // Take an average of all the readings.
  value = value / numReadings;

  // Scale to 8 bits (0 - 255).
  value = value / 4;

  return value;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int smootha = map(smooth(A1),0, 307, 2, 150);
  Serial.println(smootha);
  delay(1);
}

if someone could help me to filter it right and get only the A voltage (like) state I’ll be thankful so much!

Thanks for anyone who helps

Where does the signal in the B box originate? Is that on the power supply?

Is that really 43 volts (with a voltage divider?) or are those the raw readings?

Why are you scaling down to 8-bits? You're throwing-away resolution.

It's also not clear what you're doing with map() which is also throwing-away resolution.

And, your main loop does the same thing over-and-over with the same-old data...

And what's the time scale? You might be making it worse (harder to detect) by smoothing/averaging. You need to look for the "positive" and "negative" peaks.

The logic doesn't seem too hard - A goes above and below the nominal and B only goes above the nominal. Anything below nominal (by a certain amount) is A (and then you don't need to check if it's going above).

If it's not below nominal, you can check if it's above (by a certain amount), and if so you've got B.

The only thing is, it doesn't go much above nominal (as a percentage), maybe about 5%, so hopefully the nominal voltage is very-stable.

DVDdoug:
Is that really 43 volts (with a voltage divider?) or are those the raw readings?

Why are you scaling down to 8-bits? You’re throwing-away resolution.

It’s also not clear what you’re doing with map() which is also throwing-away resolution.

And, your main loop does the same thing over-and-over with the same-old data…

And what’s the time scale? You might be making it worse (harder to detect) by smoothing/averaging. You need to look for the “positive” and “negative” peaks.

The logic doesn’t seem too hard - A goes above and below the nominal and B only goes above the nominal. Anything below nominal (by a certain amount) is A (and then you don’t need to check if it’s going above).

If it’s not below nominal, you can check if it’s above (by a certain amount), and if so you’ve got B.

The only thing is, it doesn’t go much above nominal (as a percentage), maybe about 5%, so hopefully the nominal voltage is very-stable.

No, I got a calculator that I want to hack, and theres terminals for every column and row, and as I connected the third row, when I click a button that isn’t in the third row it shows me the B signal and if I click a button in the third row it gives me A signal

What voltage are you sensing? Not the column or row lines? You are seeing a tiny analog voltage variation, suggesting you are monitoring the power rail only.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom... :)

MarkT: What voltage are you sensing? Not the column or row lines? You are seeing a tiny analog voltage variation, suggesting you are monitoring the power rail only.

I've changed the code,

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.println(voltage);
}

currently A0 pin is connected K02(the second column from left) and when I click a button from this column it shows me that: http://prntscr.com/rd01sg

TomGeorge: Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom... :)

I can't make a circuit for this because it contains a device I can't import to the cad just imagine that, GND of the arduino to the GND of the calculator's battery VIN of the arduino to the (+) terminal of the calculator's battery A0 of the arduino to the K02(second column) of the calculator

Hi, Who needs CAD? Pen/Pencil and paper, all the component devices are in you hands, you don't need to import.

Tom... :)

TomGeorge: Hi, Who needs CAD? Pen/Pencil and paper, all the component devices are in you hands, you don't need to import.

Tom... :)

http://prntscr.com/rd1ant

Hi,
OPs circuit;


Tom... :slight_smile:

Hi, What do you exactly want to do in the end?

To get the Arduino to control the keypad? OR To get the Arduino to record the key presses?

Tom... :)

Are you sure the calculator has a voltage regulator? You might see voltages greater than 5V on A0. That can easily fry the Arduino pin.

TomGeorge: Hi, What do you exactly want to do in the end?

To get the Arduino to control the keypad? OR To get the Arduino to record the key presses?

Tom... :)

To get the Arduino to record the key presses :)

aarg: Are you sure the calculator has a voltage regulator? You might see voltages greater than 5V on A0. That can easily fry the Arduino pin.

The voltage of the calculator is 2v at max, so I don't think it'll fry the Arduino pin

mlirang: No, I got a calculator that I want to hack, and [u]theres terminals for every column and row[/u], and as I connected the third row, when I click a button that isn't in the third row it shows me the B signal and if I click a button in the third row it gives me A signal

You need to look at the all the column and row terminals individually, the keypad is multiplexed so you cannot just look with a single connection. How the calculators keypad is multiplexed will make it difficult for you to read, as you do not have control of the calculators multiplexer to sync any readings you take. Tom... :)

Invert the signal and use a diode. That will get rid of part you don't want.

noweare: Invert the signal and use a diode. That will get rid of part you don't want.

How do I invert the signal?

mlirang:
I’ve changed the code,

void setup() {

Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.println(voltage);
}




currently A0 pin is connected K02(the second column from left) and when I click a button from this column it shows me that:
http://prntscr.com/rd01sg

What are the units on the vertical scale? Volts?

The voltage of the calculator is 2v at max, so I don’t think it’ll fry the Arduino pin

The diagram shows 7.5V battery in the calculator though…

I suspect the keyboard multiplexing is too quick for analogRead(). Some analysis with a 'scope would
allow the actual waveform to be determined for certain - then perhaps a comparator could be
used to convert to digital signal (readable in < 1µs) rather than relying on the 110µs response
time of the analog pins.