Difference between revisions of "Multi-Input Analog Reading with Arduino Uno"

From ESE205 Wiki
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
+
Project page: [[Smart Blinds]]
==Group Link==
 
This tutorial was created by Sam LaSota from [[Smart Blinds]]<br />
 
 
 
 
==Overview==
 
==Overview==
This tutorial takes the reader through a step-by-step solution to the problem of reading multiple analog inputs "simultaneously" with an Arduino Uno.  
+
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==
 
==Justification==
The Arduino Uno is equipped with only one ADC (analog-to-digital converter). Thus, it is not possible to achieve simultaneous readings. The ADC multiplexer needs time to switch and the voltage needs to stabilize.  
+
The Arduino Uno is equipped with only one ADC (analog-to-digital converter). Thus, it is not possible to achieve simultaneous readings.<ref>Arduino Forum - [https://forum.arduino.cc/index.php?topic=549]</ref> The ADC multiplexer needs time to switch and the voltage needs to stabilize.
  
 
==Materials Needed==
 
==Materials Needed==
Line 32: Line 29:
 
delay(10);<br/>
 
delay(10);<br/>
 
Input2Reading = analogRead(Input2);<br/>
 
Input2Reading = analogRead(Input2);<br/>
delay(10);</code>
+
delay(10);</code><br/>
 +
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<br/>
 
2) Read Inputs Separately<br/>
Line 38: Line 36:
 
[[File: ReadTemp.PNG |400px|Read temperature]]
 
[[File: ReadTemp.PNG |400px|Read temperature]]
 
[[File:SeparateRead.JPG |400px|Call read functions]]<br/>
 
[[File:SeparateRead.JPG |400px|Call read functions]]<br/>
The first two images represent the light and temperature readings respectively. The final piece of code represents the times which the temperature and light read functions are called.  
+
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==
 
==Authors==
 
Fall 2018
 
Fall 2018
Line 46: Line 46:
  
 
==References==  
 
==References==  
*https://forum.arduino.cc/index.php?topic=549
+
 
  
  
 
[[Category:HowTos]]
 
[[Category:HowTos]]
 
[[Category:Arduino]]
 
[[Category:Arduino]]

Latest revision as of 21:03, 11 December 2018

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]