Question

Using Arduino coding perform the following program and present flowchart A  program that averages two arrays of...

Using Arduino coding perform the following program and present flowchart


A  program that averages two arrays of N elements where N is a whole number. A temperature control process has two temperature sensors A and B. From each sensor N samples are taken and stored in a different array. You need to average the values ​​of the two sensors in another array and print it on the screen. The voltage range of the sensors ranges from 0 to 5 Volts (0 ⁰C to 100 ⁰C).

Example;

For N = 10

Array samples sensor A: 1.4 1.2 1.3 1.2 1.3 1.1 1.4 1.2 1.1 1.4

Array samples sensor B: 1.4 1.2 1.1 1.4 1.5 1.7 1.8 1.0 1.1 1.4

Array average: 1.4 1.2 1.2 1.3 1.4 1.4 1.6 1.1 1.1 1.4

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

Answer:

The program the above question is given below :

#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
void setup() {
// start serial port
Serial.begin(9600);
Serial.println("Temperatuur sensor by MAI©: 1min");
// Start up the library
sensors.begin();
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}
void loop() {
// subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = digitalRead(2);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
// if we're at the end of the array...
if (readIndex >= numReadings) {
// ...wrap around to the beginning:
readIndex = 0;
}
// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
Serial.println(average);
delay(1000); // delay in between reads for stability
}

Add a comment
Know the answer?
Add Answer to:
Using Arduino coding perform the following program and present flowchart A  program that averages two arrays of...
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
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