ADC Attiny44

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, how to work with 2 analog sensors in a microcontroller. For example, a carbon monoxide sensor and a temperature sensor?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you been to the tutorial section of this site?   https://www.avrfreaks.net/forum/...

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bottom line is that most AVR have ADMUX which is a multiplexer. You can usually connect any one of up to 8 (depending on pin count) analog inputs to the single ADC and read that channel. This does of course mean you cannot make two reading in parallel but as a reading can typically be done in 65us then doing one after the other looks almost instantaneous anyway and it won't matter with slow changing inputs like CO and temp levels.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I read the data from one channel, they are saved, then I install the second channel, and where is this data stored from the second channel?

Last Edited: Thu. Oct 17, 2019 - 01:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are App Notes with code that may also be of help, ADC specifically AVR126 here: https://www.microchip.com/wwwApp...

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, most people have an ADC_Read(n) style function where you pass the number of the channel to be read as an input (and it in turn is used to set ADMUX before making the reading that is returned). So you might have CO on channel 2 (ADC2) and temp on ADC5 so you ADC_Read(2) to read the CO and ADC_Read(5) to read the temp.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The following sketch will demo how to read two analog inputs, save to two variables and output them to the serial port, should get you started.

 

/*
  Analog input from two channels serial output

  Reads two analog input pins, prints the results to the Serial Monitor.

  The circuit:
  - temp sensor connected to analog pin 0.
  - CO sensor connected to analog pin 1

*/

// These constants won't change. They're used to give names to the pins used:
const int TempSensor = A0;  // Analog input pin that the Temperature sensor is attached to
const int COSensor = A1;    // Analog input pin that the CO sensor is connected to

int TempSensorValue = 0;        // value read from the temp sensor
int COSensorValue = 0;          // value read from the CO sensor

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  TempSensorValue = analogRead(TempSensor);
  delay(10);
  COSensorValue = analogRead(COSensor);


  // print the results to the Serial Monitor:
  Serial.print("Temp sensor = ");
  Serial.println(TempSensorValue);
  Serial.print("CO sensor = ");
  Serial.println(COSensorValue);


  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delay(2);
}

Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 and where is this data stored from the second channel?

What are you talking about?  Once you read the sensor ADC, YOU determine where you want to save the values.  Do you want to save one reading or 500 readings?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

thanks for the help