Please post your best efforts at reading the 2 inputs
Please follow the advice given in the link below when posting code , use code tags when posting code here to make it easier to read and copy for examination
The line of code that you posted below the line where you do the thing, is wrong.
What code would you like help with?
The best would have been to post the code you have tried, with your original post, in code tags. Then write about what your code is supposed to do and what you code is doing.
Hi my code is not good so i was hoping for a fresh code.
i have inserted the code below:
void setup()
{
Serial.begin(9600);//Set Baud Rate to 9600 bps
}
void loop()
{
uint16_t val;
double dat;
val=analogRead(0);//Connect LM35 on Analog 0
dat = (double) val * (5/10.24);
Serial.print("Tep:"); //Display the temperature on Serial monitor
Serial.print(dat);
Serial.println("C");
delay(500);
int val;
val=analogRead(1);//Read Gas value from analog 0
Serial.println(val,DEC);//Print the value to serial port
this is the serial monitors error:
C:\Users\Stuart\Documents\Arduino\sketch_aug06b\sketch_aug06b.ino: In function 'void loop()':
sketch_aug06b:17:7: error: conflicting declaration 'int val'
int val;
^~~
C:\Users\Stuart\Documents\Arduino\sketch_aug06b\sketch_aug06b.ino:8:14: note: previous declaration as 'uint16_t val'
uint16_t val;
^~~
exit status 1
conflicting declaration 'int val'
uint16_t val;
double dat;
byte TempPin = A0;
byte GasPin = A1;
void setup()
{
Serial.begin(9600);//Set Baud Rate to 9600 bps
Serial.println("Setup complete");
}
void loop()
{
val = analogRead(TempPin); //Connect LM35 on Analog 0
val = analogRead(TempPin); // Read twice to let ADC read selected channel
dat = (double) val * (5 / 10.24);
Serial.print("Temp:"); //Display the temperature on Serial monitor
Serial.print(dat);
Serial.println("C");
delay(500);
val = analogRead(GasPin); //Read Gas value from analog 0
val = analogRead(GasPin); // Read twice to let ADC read selected channel
Serial.println(val, DEC); //Print the value to serial port
delay(100);
}
Hi,
The analog pin is read twice because there is only ONE ADC and it is switched from channel to channel.
The ADC circuit has an input capacitor that has to charge to the input voltage, this takes a little time, reading twice makes sure that the second read has allowed the capacitor and hence the ADC to acquire the new input voltage.
You can find details of all of the Arduino specific functions in Arduino Reference - Arduino Reference but as the Arduino runs C++ then any C++ reference will give you details of more general functionality