I am hoping someone can help me with a my code. I am inputting ac voltage into an analog input on the arduino and I am trying to take 64 samples from the ac wave and store it in an array. I am looking to start readying the sine wave at the 1.56 value as the wave is shifted to the positive axis and it goes from 0-3.2. Now I think I might be close but not quite there yet with the logic.
Thanks in advance.
int readings[64]; // the readings from the analog input
int readingvalue =1.56; //the value of which the array should start storing samples
int inputPin = A0; // A0 is the input pin
This puts the value into the 65th location of "readings[]" which does not even exist. Counting array entries starts with 0. You need to read up on arrays, but something like this will work:
for (int i=0;Â i < 64; i++)
{
  readings[i] = analogRead(inputPin);
}
This puts the value into the 65th location of "readings[]" which does not even exist. Counting array entries starts with 0. You need to read up on arrays, but something like this will work:
for (int i=0; i < 64; i++)
{
readings[i] = analogRead(inputPin);
}
I have 120 vac stepped down to 1.55vrms and 4.4v peak to peak. output to my arduino with a DC offset of 2.2volts. Frequency is 60hz.
I'm multiplying voltage by current to read power and want to read the incoming voltage and multiply it by the current.
I see other people already helped you with your array indexing problem.
TomorrowsWorld:
int readingvalue =1.56; //the value of which the array should start storing samples
This line shows you don't understand what values the analogRead() function returns, however. They are "int"s, or integers that can not contain decimal numbers like 1.56.
Normally an Arduino int can have any value between 0-65535 because it is 16bits long. In the case of analogRead(), however, it is returning a 10bit number that can range between 0-1023.
The method to convert an analog value in volts to the analogRead() value is analog_voltage/5V1023 (for example, 1.56/5V1023= 319).
float Voltage = A5;
//int vvalue=0;
long int Vtest[64];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
for(int i =0; i < 64; i++){
Vtest = analogRead(A5);
//vvalue = analogRead(A5);*
_ //float test = (vvalue/5)*1023;_
_ Serial.println(Vtest*);_
_ delay(500);_
_}_
_}*_ This is what I have so far. I think now I somehow have to use TTRCO and OCRA to get the exact time of one cycle of my sin wave and then compare that to my voltage into my arduino which is 1.55vrms don't I? Sorry for posting to much guys, we were never taught arduino in school and my teacher asked me to do this project, so the only help I can find is in the forums. It's all a new language to me. Even when I understand what I'm trying to do I can't even type in the code correctly to accomplish what I want. It's very frustrating.