ADC Value Problem

Hello guys,

I have a problem with the attached source code. It is actually working with a Sensor DHT22.
Now I try to implement a weather sensor wich is connected via ADC.
The communication protocol is working, but the ADC values are not correct. I have checked the power connection and I also have checked the AGND but is not working, also when I put the ADC to GND it doesnt send me 0 back...

FYI
STX;Arduino-ID;YYYY-MM-DD%HH:mm:ss;TMP=20;ETX
STX == start bit
Arduino-ID
YYYY-MM-DD%HH:mm:ss== time stamp
TMP=20 == command
ETX== stop bit

this is the SendMeasurment string of the arduino protocoll, it will be connected to xbee´s

used Hardware:
arduino micro

thanks for your help

Arduino_weather.txt (16.3 KB)

what is not actually working there ?

It's a very long sketch that tries to do lots of different things.

I would suggest writing a very simple sketch that just tests reading the ADC input.

You don't need to do all the malloc/free of 19 bytes and you'd be a lot better off if you didn't too. Just declare dateANDtime to be a 20 byte character array.

if (sensorValueA2 == 5)

This is a rather strange value to look for. Do you actually mean to check that the ADC value is 5 or did you intend to check for an ADC voltage of 5V (sensorValueA2 == 1023 or Niederschlag == 5.0)?

Pete

  //Imput am Pin A2 einlesen
  int sensorValueA2 = analogRead(A2);
  //Den Analogen Wert (welcher von 0 - 1023 reicht) in eine Spanung (0 - 5V) umrechnen
  float Niederschlag = sensorValueA2 * (5.0 / 1023.0);
  if (sensorValueA2 == 5)
	{
		//Serial.print(Niederschlag);
		//Serial.println("0");
		return 0;

what do you want to do ? the sensorValueA2 is range from 0 to 1023, and it is not stable, so it is very likly not equal to 5, and the function return 0..

  //Imput am Pin A2 einlesen
  int sensorValueA2 = analogRead(A2);
  //Den Analogen Wert (welcher von 0 - 1023 reicht) in eine Spanung (0 - 5V) umrechnen
  float Niederschlag = sensorValueA2 * (5.0 / 1023.0);
  if (sensorValueA2 == 5)
	{
		//Serial.print(Niederschlag);
		//Serial.println("0");
		return 0;

what do you want to do ? the sensorValueA2 is range from 0 to 1023, and it is not stable, so it is very likly not equal to 5, and the function return 0..