I'm currently try to connect a DS18S20 temperature sensor to the atmega328p. I have wired AVCC and AGRD to the same power rail on my breadboard as normal VCC/GRD and AREF is not connected.

When I try to connect the data pin of the temperature sensor to the first channel of port A, the value changes to zero and stays zero. Before connecting the data pin, the value jumps around randomly. I have the following code:

volatile uint16_t vOutADCReading = 0U;

void setupAnalogDigitalConversion(){
  ADMUX |= 1<<REFS0;
  ADCSRA |= 1<<ADEN;
  ADCSRA |= 1<<ADPS0 | 1<<ADPS1 | 1<<ADPS2;
  ADCSRA |= ( 1 << ADSC );

void adc_read(uint8_t channel){
  ADMUX &= 0xf0;
  ADMUX |= channel;
  ADCSRA |=  (1<<ADSC);

  while(ADCSRA & (1<<ADIF));
  // Set voltage output
  vOutADCReading = ADC;
  // Clear ADIF flag
  ADCSRA |= ( 1 << ADIF );

void main(){


Are there any errors in this code?


1 Answer 1


The DS18x20 series are digital thermometers using the One-Wire protocol on their data pin. Look up any of the Dallas/Maxim DS18b20 libraries to use this one.

If, on the other had, you want an analog thermo-sensor, try the LM34/LM35 series of analog sensors (Fahrenheit/Celsius, respectively) which put voltage, proportional to temperature, on their data pin.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.