Multi-Input Analog Reading with Arduino Uno

From ESE205 Wiki
Jump to: navigation, search

Project page: Smart Blinds

Overview

In our project, we use analog readings in Arduino programming to achieve our goal of measuring the temperature and the light intensity. In our original design, we coded the program to take in two analog inputs at the same time. However, our testing shows that the changes in one measurement, for example the temperature, will also affect analog readings of a another input, which stays unchanged in physical world. This tutorial takes the reader through a step-by-step solution to the problem of reading multiple analog inputs "simultaneously" with an Arduino Uno.

Justification

The Arduino Uno is equipped with only one ADC (analog-to-digital converter). Thus, it is not possible to achieve simultaneous readings.[1] The ADC multiplexer needs time to switch and the voltage needs to stabilize.

Materials Needed

  • Arduino Uno
  • Arduino's IDE
  • Multiple analog inputs

Solutions

Two solutions are available to us depending on the context.
1) If taking readings close together is important: create a delay between readings and take two readings per input and discard the first (to get a more accurate reading)
2) Otherwise create separate read functions that operate at different times (to allow the voltage to stabilize)

Process

1) Read inputs together
TutorialCode.JPG
The code here represents a sequential light and temperature reading. Notice how each input is read twice with a delay of 10 microseconds between each reading. The first reading of each input is overwritten by the second and the delay allows time for the voltage to stabilize.

For the general case your code should look something like this:
Input1Reading = analogRead(Input1);
delay(10);
Input1Reading = analogRead(Input1);
delay(10);
Input2Reading = analogRead(Input2);
delay(10);
Input2Reading = analogRead(Input2);
delay(10);

The problem of this method is that the delay() function will interfere with the delta timing we implemented in the loop, causing unintended timing problems in the program.

2) Read Inputs Separately
Read luminosity Read temperature Call read functions
The first two images represent the light and temperature readings respectively. In each function, only one parameter is processed. The final piece of code represents the times which the temperature and light read functions are called. Notice that the ReadTemp() function is called after ReadLight(). By doing so, the ADC channel will only process only one voltage input during a certain amount of time and the readings are stabilized.

Conclusion

Both solutions can be implemented in any program, with the same time complexity of big theta (n). However, since the delay method will interfere with our delta timing in the loop, we decided to use the second method.

Authors

Fall 2018

  • Sam LaSota
  • Toby Liu

References

  1. Arduino Forum - [1]