Question: Hi can i get help on this code for arduino uno? ______________________________________ int analogPin = 0; int raw = 0; int Vin = 5; float

Hi can i get help on this code for arduino uno?

______________________________________

int analogPin = 0; int raw = 0; int Vin = 5; float Vout = 0; float R1 = 10000; float R2 = 0; float buffer = 0;

unsigned long time; unsigned int timeStep = 10000 ; // Collect sample every 10,000 microseconds (100 Hz) unsigned long int nextSampleTime ; // Time of next ADC sample int adcSample ;

void setup(){ Serial.begin(9600); nextSampleTime = micros() + timeStep ; // Time of first sample }

void loop(){ raw = analogRead(analogPin); if(raw){ buffer = raw * Vin; Vout = (buffer)/1024.0; buffer = (Vin/Vout) - 1; R2= R1 * buffer; if (micros() >= nextSampleTime) { adcSample = analogRead(analogPin) ; Serial.println(adcSample) ; nextSampleTime = nextSampleTime + timeStep ; // Next sample is current time plus step time } } time = micros();

}

________________________

Ive tried to get this code to detect the lowest resitance peaks and a time stamp since started and i cant seem to get it to do either. As i have a pendulum of light set up. so the light is swinging above the photoresitor and i need to print the real time resitance with a time stamp but i cant. Any corrections and tweaks to my code will be welcome

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!