ADC doesn't work

When i try this script the serial return me always 0.00 even if i have a voltage in A0, i’ve tried another similar scripts and it works but i can’t find the error in this one, any clue?. Thanks in advance!

int puerto = {2,3};
int adc = A0;
int med, mema=0, memb=0, xabajo=0.10, xarriba=0.10;
float ref;

void setup()
{
Serial.begin(9600); /Configura la velocidad de comunicación/
pinMode(13, OUTPUT); //Configura como salida el pin
pinMode(puerto[0], OUTPUT);
pinMode(puerto[1], OUTPUT);
digitalWrite(13, HIGH); //Pone en alto el pin 13
delay(100);
}
void loop()
{

med=analogRead(adc);
ref=med*(5/1023);
Serial.println(ref);

if(mema=1)
{
ref=ref+xabajo;
}

if(memb=1)
{
ref=ref-xarriba;
}

if(ref<1.12)
{
digitalWrite(puerto[0],HIGH);
memb=1;
}
else
{
digitalWrite(puerto[0],LOW);
memb=0;
}

if(ref>1.29)
{
digitalWrite(puerto[1],HIGH);
mema=1;
}

else
{
digitalWrite(puerto[1],LOW);
mema=0;
}
}

Vakman:   ref=med*(5/1023);

Integer math (5/1023) results in 0.

Should be:

  ref=med*(5.0/1023.0);

[quote author=James C4S link=topic=191003.msg1411985#msg1411985 date=1380586740]

Vakman:   ref=med*(5/1023);

Integer math (5/1023) results in 0.

Should be:

  ref=med*(5.0/1023.0);

[/quote]

Thank you very much sir!

int med, mema=0, memb=0, xabajo=0.10, xarriba=0.10;

Since these are declared as integer variables they will only hold whole numbers; xabajo and xarriba will be initialised to zero. If you want these variables to hold float values you need to declare them as floats.

ref=med*(5/1023);

Since 5 and 1023 are integer literal values, the value of (5/1023) will be zero. Hence ref will always be zero regardless of the result of analogRead(). If you use floating point numbers (5.0 / 1023.0) the intermediate value will be calculated as a float value.

Any time you think your ADC is not working, display the raw value to test it.