Question

Turn in a cleanly formatted version of the code, and a sample print-out of at least 10 readings. HINT: Use the Auto Format

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION : To write an Arduino program to measure the output of the salinity sensor. So, here the average is a measure of cen​​​​​​

void salinity_reading_stats( int power_pin, int input_pin, int nave, float *ave, float *stdev )

{

int i, n=15;

float sum; // Use a float to prevent overflow

float reading[BUFFER_LENGTH]; // Array to store readings

n = min( nave, BUFFER_LENGTH ); // Make sure we don't over-run the data buffer

// -- Store readings in an array

for ( i=0; i<n; i++ ) { // First array index is 0, last is n-1

digitalWrite( power_pin, HIGH ); // Turn on the sensor

delay(100); // Wait for sensor to settle

reading[i] = analogRead( input_pin ); // Add reading to the running sum

reading = analogRead( input_pin ); // Read voltage

digitalWrite( power_pin, LOW ); // Turn off power to the sensor

delay(100); // wait between readings

}

// -- Compute average and standard deviation.

for ( sum=0.0, i=0; i<n; i++ ) {

sum += reading [i];

}

*ave = sum/float(nave);

for ( sum=0.0, i=0; i<n; i++ ) {

sum += pow(reading[i] - *ave, 2);

}

*stdev = sqrt( sum/float(n-1) );

}

Add a comment
Know the answer?
Add Answer to:
Turn in a cleanly formatted version of the code, and a sample print-out of at least...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in arduino Improved Sensor Readings a. The name of this program will be lab3p2. Copy the...

    in arduino Improved Sensor Readings a. The name of this program will be lab3p2. Copy the program from lab2p1, as that is the most similar to this program. b. Readings from sensors are prone to noise. A typical way to reduce the noise and hence, improve the accuracy of a reading is to take multiple readings and average! From statistics we learn that the accuracy improves with VN, where N is the number of reading. c. If you want to...

  • I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED str...

    I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT