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

From ESE205 Wiki
Jump to navigation Jump to search
Line 14: Line 14:
 
*Multiple analog inputs  
 
*Multiple analog inputs  
  
==Process==
+
==Solutions==
 
Two solutions are available to us depending on the context.<br/>  
 
Two solutions are available to us depending on the context.<br/>  
 
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) <br/>
 
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) <br/>
 
2) Otherwise create separate read functions that operate at different times (to allow the voltage to stabilize) <br/>
 
2) Otherwise create separate read functions that operate at different times (to allow the voltage to stabilize) <br/>
  
==Solutions==
+
==Process==
 
1) Read inputs together <br/>
 
1) Read inputs together <br/>
 
[[File:TutorialCode.JPG|400px|]]<br/>
 
[[File:TutorialCode.JPG|400px|]]<br/>

Revision as of 19:09, 11 December 2018

Group Link

This tutorial was created by Sam LaSota from Smart Blinds

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.

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.

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);

2) Read Inputs Separately
Read luminosity Read temperature Call read functions
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.

Authors

Fall 2018

  • Sam LaSota
  • Toby Liu

References