Help with Serial Monitor Read-Outs

I am working on a project to read ac voltages using the Arduino Uno R3.

I would like to increase the number of read-outs on the serial monitor as at the moment I get about five values in each cycle.

I have tried increasing the communication speed but that prints out gibberish
I have also tried changing the delay which doesnt affect the number of reading serial monitor prints out.

Below is my current code.

const float analogInPin = A0;
//const float analogOutPin = A5;
float sensorValue = 0;
float voltage = 0;
float sensor = 0;

void setup()

{
Serial.begin(9600); // initialize serial communications at 9600 bps
}

void loop()

{
sensor = analogRead(0);
voltage = (sensor*5)/1024;// the sensor value divided by the voltage/sensor ratio
//outputValue = map(voltage, 0, 1023);
//analogWrite(analogOutPin, voltage);
Serial.print("AC Voltage = " );
Serial.println(voltage);

delay(3.125*0.000001);
}

The output to the serial monitor is relatively slow. You can increase the speed of the serial link by changing the value in the Serial.begin function (up to 115200) but you must also change the speed to match in the serial monitor window itself - bottom right of the screen. You could also speed up the repeat rate of printing by sending less characters each time.

Whether this will help you display more values I don't know.

The delay calls are pointless - get rid of them. (delay() takes an integer value, not a float; when the float value is cast to an int it will be rounded to zero.)

What do you mean by 'cycle'? I don't suppose you mean a 50Hz AC cycle, since that would have resulted in far more output than you could fit down a 9600bps stream.

Thank you on the note on about the delay. When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.

When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.

In what period? A week? I'm sure the Arduino is capable of more than 5 readings a week.

If the period is 5 microseconds, you may well be SOL.

   voltage = (sensor*5)/1024;// the sensor value divided by the voltage/sensor ratio

Isn't integer math wonderful? It is, but it probably is not what you want. Using 5.0 and 1024.0 will produce results that are closer to what you expect, I'd guess.

I have tried increasing the communication speed but that prints out gibberish

Did you change the speed in the receiver, too?

gmbroh:
When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.

That's no help at all. Let me ask it another way: How long is the 'cycle' or 'period' in milliseconds?

Or, put it another way, at 9600 baud, it takes 1.04ms to transmit a character.
If you want to send ASCII decimal values, and analogRead gives a result with up to four decimal digits, so you need at least five characters (four digits plus separator) per readings.
Five readings per cycle gives 25 characters = 26ms, or a touch over 38Hz.

PeterH:

gmbroh:
When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.

That's no help at all. Let me ask it another way: How long is the 'cycle' or 'period' in milliseconds?

I am working a frequency range of 0 to 60 Hz. at 10Hz for example the period is 0.1 second. Does that help ?

This is the type of data from the serial monitor. I would like to see more values in-between each period.
5
4.03
2.43
5
4.79
2.82
5
5
2.95
3.9
5
3.36
2.51
5
3.69
2.25
5
3.99
2.41
5
4.78
2.81
5
5
2.92
3.93
5
3.36
2.54
5
3.67
2.24
5
3.98
2.4
5
4.77

I have attached the input and output data.

Sampling rate 041212.xlsx (98.5 KB)

PaulS:

When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.

In what period? A week? I'm sure the Arduino is capable of more than 5 readings a week.

If the period is 5 microseconds, you may well be SOL.

   voltage = (sensor*5)/1024;// the sensor value divided by the voltage/sensor ratio

Isn't integer math wonderful? It is, but it probably is not what you want. Using 5.0 and 1024.0 will produce results that are closer to what you expect, I'd guess.

I have tried increasing the communication speed but that prints out gibberish

Did you change the speed in the receiver, too?

Yes I have tried changing the communication speed at the reciever end, but this is in the serial monitor. I changed the communication speed in the code and in the serial monitor to match.

3.69

Six characters, 32Hz maximum at 9600.

AWOL:

3.69

Six characters, 32Hz maximum at 9600.

Sorry but I dont understand what you mean. Is even possible to read/collect/record more that 5 data points when using the ADC ?

I would like to collect at least 20 readingw in each cycle where my maximum frequency is 60Hz. Is that possible ?

I would like to collect at least 20 readingw in each cycle where my maximum frequency is 60Hz. Is that possible ?

20 * 60 = 1200.
Sample rate using standard analogRead is around 9500 samples per second.
So, yes, you can collect that many samples, though you'd be hard-pressed to display them in real-time, and certainly not a 9600 baud.

gmbroh:
I would like to collect at least 20 readingw in each cycle where my maximum frequency is 60Hz. Is that possible ?

Yes, but you would need to collect and store them locally and then send them over the serial port later - the serial port is not fast enough to transfer the sample data in real time.