Arduino UNO stops reading Analog pins in

Hi

i am reading a voltage in on pin0, the voltage comes from a Vibration MEMS sensor (CN0532) then thru a voltage divider (as output voltage from sensor is 12v +-2v) if there is no vibration then the voltage doesnt change and the arduino outputs a reading of 12v as expected, however when i add vibration and voltage changes the arduino crashes.
i have checked connections, nothing loose (the arduino isnt subject to the vibration)
Any idea on what my problem is?
Perhaps the arduino is not able to output fast enough?
thanks

// Define analog input
#define ANALOG_IN_PIN A0
 
// Floats for ADC voltage & Input voltage
float adc_voltage = 0.0;
float in_voltage = 0.0;
 
// Floats for resistor values in divider (in ohms)
float R1 = 10000.0;
float R2 = 4700.0; 
 
// Float for Reference Voltage
float ref_voltage = 5.0;
 
// Integer for ADC value
int adc_value = 0;
 
void setup(){
   // Setup Serial Monitor
   Serial.begin(9600);
   //Serial.println("DC Voltage Test");
}
 
void loop(){
   // Read the Analog Input
   adc_value = analogRead(ANALOG_IN_PIN);
   
   // Determine voltage at ADC input
   adc_voltage  = (adc_value * ref_voltage) / 1024.0; 
   
   // Calculate voltage at divider input
   in_voltage = adc_voltage / (R2/(R1+R2)); 
   
   // Print results to Serial Monitor to 2 decimal places
  //Serial.print("Input Voltage = ");
  Serial.println(in_voltage, 2);
  
  // Short delay
  delay(500);
}

How are you supplying 5 V to the UNO?

Hi,
Welcome to the forum.
Thanks for using code tags.

Are you using the sensor on its own, or on a premade module?

Do you have a DMM?

Can you please post a circuit diagram of your project?
Can you please post a picture of your project so we can see component layout?

Thanks.. Tom... :slight_smile:

horsebox:
when i add vibration and voltage changes the arduino crashes.

Sounds like a loose power connection to me.

Hi,

arduino outputs a reading of 12v as expected

How??
Edit.. derrrrr didn't read subject close enough, need more coffeeee...
They are only 5V or 3v3 type outputs.

What controller are you using?

Tom.... :slight_smile:

TomGeorge:

horsebox:
the arduino outputs a reading of 12v as expected,

How??

"Outputs" as in "displays on Serial Monitor". The voltage is read with a voltage divider.

Hi Folks, thanks for replies and sorry for delay in replying back.
Did some more work on this and here is summary.
The vibration sensor outputs voltage (12v) into voltage divider and then into analog pin A0 of the Arduino, then data is sent via serial port into Labview.
Previously i was using Labview to download code into Arduino UNO and I didnt realise this....guess this was causing things to freeze up..
Anyway i changed Labview code so it reads in from serial port from Arduino UNO, so all good there.

My issue now is to find out often the Arduino outputs through the serial port, or what is the sampling rate, i need this to create a frequency domain chart in Labview.
Read up a bit about it but not too clear on a method to figure this out.

Here is my code:
indent preformatted text by 4 spaces

// Define analog input

#define ANALOG_IN_PIN A0

// Floats for ADC voltage & Input voltage
float adc_voltage = 0.0;
float in_voltage = 0.0;

// Floats for resistor values in voltage divider (in ohms)
float R1 = 10000.0;
float R2 = 4700.0;

// Float for Reference Voltage
float ref_voltage = 5.0;

// Integer for ADC value
int adc_value = 0;

void setup(){
// Setup Serial Monitor
Serial.begin(115200);

}

void loop()
{
// Read the Analog Input
adc_value = analogRead(ANALOG_IN_PIN);

// Determine voltage at ADC input
adc_voltage = (adc_value * ref_voltage) / 1024.0;

// Calculate voltage at divider input
in_voltage = adc_voltage / (R2/(R1+R2));

// Print results to Serial Monitor to 2 decimal places
//Serial.print("Input Voltage = ");
Serial.println(in_voltage, 2);
}

Looks like the answer is by the USB port. That is OK.

Just do not use "Vin" or the "barrel jack".

The problem your breadboard is that if the connection to 0v from the voltage divider is bad/loose/falls out , you will put 12v ( or so) into the analog input and maybe destroy or at least crash the Arduino.
I’d solder something up

1 Like

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