Go Down

Topic: Mini Aref (Read 2261 times) previous topic - next topic

Urioste

Feb 08, 2013, 09:41 am Last Edit: Feb 08, 2013, 10:31 am by Urioste Reason: 1
Hello:

Sorry for my English,

I have a arduino mini with 4 sensors, two temperature and two humidity, they come trough a demultiplexer M74HC4051, but I think that's not the problem, the arduino starts in sleep mode power down, then wake up and reads the sensors, this time it is ok, go sleep again but when wake up and reread sensors values ​​are not well, it's like the Aref would have changed.

Help please, I tried to put before measurements   analogReference(DEFAULT); but it´s the same.

Some sugestions?


02/08/2013   09:15:05   17.8   61.84   17.6   60.76 this are ok
02/08/2013   09:16:05   33.6   64.18   33.2   63.22 from here not
02/08/2013   09:17:05   36.9   64.93   36.5   64.60
02/08/2013   09:18:05   37.6   65.23   37.1   63.94


Here is the code
Code: [Select]

#include <avr/sleep.h>
#include [color=#006699]"HumidityHIH4030.h"[/color]
#include <[color=#CC6600]Wire[/color].h>
#include <[color=#CC6600]Rtc_Pcf8563[/color].h>
#include <[color=#CC6600]SD[/color].h>
#include <SoftwareSerial.h>

const byte LED = 13;

HumidityHIH4030 Humidity;
Rtc_Pcf8563 rtc;              // AÑADIR EL RELOJ
int alarma = 15;              // VALOR PARA INICIAR ALARMA
int intervalo = 1;           // INTERVALO DE REGISTROS
volatile int registrar = 1;   // VARIABLE QUE ACTIVA LA ALARMA
float humidity1;              // AÑADIR HUMEDAD 1
float humidity2;              // AÑADIR HUMEDAD 2
float tempvmin = 97.185;      // MINIMO VOLTAJE TEMPERATURAS PARA ESCALAR
float tempvmax = 672.7248;    // MAXIMO VOLTAJE TEMPERATURAS PARA ESCALAR
int temp1;                    // AÑADIR TEMPERATURA 1
int temp2;                    // AÑADIR TEMPERATURA 2
float Tempvalue1;             // AÑADIR TEMPERATURA 1 EN GRADOS
float Tempvalue2;             // AÑADIR TEMPERATURA 2 EN GRADOS


                      // ESTO SOLO ES PARA DESPERTAR
void wake ()
{
  sleep_disable();    // DESACTIVAR EL SLEEP
  registrar = 1;      // ACTIVA EL REGISTRO DE MEDIDAS
}                     // AQUI ACABA EL DESPERTAR
                       
                       

                      // EMPIEZA EL SETUP
void setup ()
{
  pinMode (2, INPUT);                  // PIN 2 COMO ENTRADA
  digitalWrite (2, HIGH);              // ACTIVA EL PIN D2 COMO DESPERTADOR
  rtc.setAlarm(alarma, 99, 99, 99);    //PONEMOS LA ALARMA POR PRIMERA VEZ PARA COMENZAR EL CICLO
}                   
                      // ACABA EL  SETUP
                     
                      // EMPIEZA EL LOOP
void loop ()   
{
    //EMPIEZA EL PROCESO  DE DORMIR.
  pinMode (LED, OUTPUT);
  digitalWrite (LED, HIGH);
  delay (50);
  digitalWrite (LED, LOW);
  delay (50);
  pinMode (LED, INPUT);
 

 
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);      // MODO DE SLEEP
  sleep_enable();                            // ACTIVAR MODO
  // will be called when pin D2 goes low 
  attachInterrupt (0, wake, FALLING);        // AÑADE EL A0 COMO DESPERTADOR
  sleep_cpu ();                              // AQUI SE DUERME Y SIGUE AL DESPERTAR
                                             // EJECUTA EL WAKE QUE PONE registrar A 1

  if (registrar == 1)                        // SI REGISTRAR ES IGUAL A 1 ENTONCES EJECUTA EL TOMAR_DATOS
  {
    tomar_datos();                           // VOID DE REGISTRO
  }
}
                    // ACABA EL LOOP
                   
                    // EMPIEZA TOMAR_DATOS
                   
void tomar_datos()
{
   detachInterrupt (0);         // QUITAR EL A0 COMO DESPERTADOR
   
   pinMode (4, OUTPUT);         // RELE DE ALIMENTACION SENSORES Y SD
   pinMode (5, OUTPUT);         // s2 CANAL CONTROL MULTIPLEXOR SALIDA
   pinMode (6, OUTPUT);         // s1 CANAL CONTROL MULTIPLEXOR SALIDA
   pinMode (7, OUTPUT);         // s0 CANAL CONTROL MULTIPLEXOR SALIDA
   
   digitalWrite (4, HIGH);      // ACTIVAMOS EL RELE
   
   digitalWrite (5, LOW);       // CANAL 0 DEL DESMULTIPLEXADOR
   digitalWrite (6, LOW);
   digitalWrite (7, LOW);
   delay (5000);
   temp1 += analogRead (A0);    // LEE TEMPERATURA 1 5 VECES Y HACE LA MEDIA
   delay (20);
   temp1 += analogRead (A0);
   delay (20);
   temp1 += analogRead (A0);
   delay (20);
   temp1 += analogRead (A0);
   delay (20);
   temp1 += analogRead (A0);
   temp1 /= 5;
 
   digitalWrite (5, LOW);        // CANAL 2 DEL DESMULTIPLEXADOR
   digitalWrite (6, HIGH);
   digitalWrite (7, LOW);
   delay (100);
   temp2 += analogRead (A0);     // LEE TEMPERATURA 2 5 VECES Y HACE LA MEDIA
   delay (20);
   temp2 += analogRead (A0);
   delay (20);
   temp2 += analogRead (A0);
   delay (20);
   temp2 += analogRead (A0);
   delay (20);
   temp2 += analogRead (A0);
   temp2 /= 5;
 
   Tempvalue1 = map (temp1, tempvmin, tempvmax, -400, 850);  // ESCALA TEMPERATURA 1
   Tempvalue2 = map (temp2, tempvmin, tempvmax, -400, 850);  // ESCALA TEMPERATURA 2
   Tempvalue1 = Tempvalue1/10;                               // PONE DECIMALES A TEMPERATURA 1
   Tempvalue2 = Tempvalue2/10;                               // PONE DECIMALES A TEMPERATURA 2

   digitalWrite (5, HIGH);        // CANAL 1 DEL DESMULTIPLEXADOR
   digitalWrite (6, LOW);
   digitalWrite (7, LOW);
   delay (100);
   Humidity.begin(A0);                           // ARRANCA LIBRERIA HUMIDITY EN A0
   Humidity.setTemperature (Tempvalue1);         // PONE TEMPERATURA 1  DE CORRECION
   humidity1 = Humidity.getHumidityPercentage(); // RECOJE HUMEDAD 1 CON CORRECION DE TEMPERATURA

   digitalWrite (5, HIGH);        // CANAL 3 DEL DESMULTIPLEXADOR
   digitalWrite (6, HIGH);
   digitalWrite (7, LOW);
   delay (100);
   Humidity.setTemperature (Tempvalue2);         // PONE TEMPERATURA 2 DE CORRECION
   humidity2 = Humidity.getHumidityPercentage(); // RECOJE HUMEDAD 2 CON CORRECION DE TEMPERATURA
 
 
   pinMode(10, OUTPUT);         // ACTIVA LA TARJETA SD
   SD.begin(10);                // ARRANCA LA TARJETA
 
   File dataFile = SD.open("datalog1.txt", FILE_WRITE);  // ABRE DATALOG.TXT O LO CREA SI NO EXISTE
 
   if (dataFile)                // SI ESTA YA ABIERTO, ESCRIBE
   {                             
     dataFile.print(rtc.formatDate());          // FECHA
     dataFile.print("\t");                     
     dataFile.print(rtc.formatTime());          // HORA
     dataFile.print("\t");
     dataFile.print(Tempvalue1,1);              // TEMPERATURA 1
     dataFile.print("\t");                   
     dataFile.print(humidity1,2);               // HUMEDAD 1
     dataFile.print("\t");                     
     dataFile.print(Tempvalue2,1);              // TEMPERATURA 2
     dataFile.print("\t");         
     dataFile.println(humidity2,2);             // HUMEDAD 2

     dataFile.close();                          // CIERRA EL ARCHIVO
    }
   
         /*A ELIMINAR EN LA VERSION FINAL DEL PROGRAMA*/
         /**/
         /**/
          Serial.begin (9600);
          Serial.print(rtc.formatDate());          // FECHA
          Serial.print("\t");                     
          Serial.print(rtc.formatTime());          // HORA
          Serial.print("\t");
          Serial.print(Tempvalue1,1);              // TEMPERATURA 1
          Serial.print("\t");                   
          Serial.print(humidity1,2);               // HUMEDAD 1
          Serial.print("\t");                     
          Serial.print(Tempvalue2,1);              // TEMPERATURA 2
          Serial.print("\t");         
          Serial.println(humidity2,2);
          delay (1000);
         /**/
         /**/
   
   
   /*PONEMOS TODOS LOS CANALES COMO LOW Y COMO INPUT PARA DORMIR.*/   
   digitalWrite (4, LOW);
   digitalWrite (5, LOW);
   digitalWrite (6, LOW);
   digitalWrite (7, LOW);
   digitalWrite (10, LOW);
   
   pinMode (4, INPUT);
   pinMode (5, INPUT);       
   pinMode (6, INPUT);         
   pinMode (7, INPUT);   
   pinMode (10, INPUT);
     
   alarma = alarma + intervalo;     // AJUSTAMOS EL INTERVALO DE LA PROXIMA ALARMA
   if (alarma >= 60)                // CORREGIMOS A 0 MINUTOS
   {
      alarma -= 60;
   }
   rtc.setAlarm(alarma, 99, 99, 99);     //PONEMOS LA ALARMA DE NUEVO       
   registrar = 0;                        // PONEMOS EL REGISTRO A 0 DE NUEVO 
}

Regards

pylon

What kind of temperature sensors do you use?

How is your Arduino powered? Batteries? Power supply? What other components are powered from that source?

Urioste


pylon

Have you tried inserting the following line after waking up?

Code: [Select]
analogReference(DEFAULT);

Urioste

Yes, I try it, just before the measurements, but it's the same problem.

Thanks

pylon

Have you measured the voltage between the GND and 5V pins of the Arduino after waking up? Is it the same as before going to sleep?

Urioste

I have just measured, and in the first wake up I have 4,9 and go down to 4,7 but in the second one go down to 4,2 or minus, so I think that the capacitors discharge in the first one and dont have time to recharge, so in the second one they drops the voltage!!!

What do you think?

Thanks for help.

Regards

pylon

It looks like it's a hardware problem (a power problem to be exact). Can you make a picture showing all your wiring? Or do you have schematics showing all hardware of your project?

If you have a power supply I would try to power it by that and see if you still have these voltage drops.

Do you ever try to use external power supply? USB power only supply your system under 500 mA.

Urioste

Sorry for my late answer, this is that i'am doing now, trying to put a external power supply, because now i have another problem, arduino resets on his own, I disconect all, and only whit the microrelay, when relay change to off, it rests, the relay consumes 10mA and it is powered by digital output, but maybe it is to much change for USB.

Tomorrow I try to put the schematic.

Thanks

pylon

Do you have the free-run diode over the relay contacts?

retrolefty


Do you have the free-run diode over the relay contacts?


Contacts? Do you mean to ask the OP if he has a free-run diode across the coil terminals?

Which if not could be the cause of the OP's reset problem.

Lefty

pylon

Quote
Do you mean to ask the OP if he has a free-run diode across the coil terminals?


That's what I meant. Sorry for my English, I'm not a native speaker.

Urioste

I dont have time today,:(

What do you mean with free-run diode?

Regards.

pylon

#14
Feb 12, 2013, 02:39 am Last Edit: Feb 12, 2013, 02:42 am by pylon Reason: 1
The relay includes a solenoid which drives a mechanical switch. The solenoid is an inductor and as such gives back current when turn off. The free-run diode is a diode between the coil terminals which is normally blocking. When the power on the terminals is switched off, the inductor is returning it's "stored" energy into the circuit, the other way round as it was driven. Because the diode is conducting in this direction, the power is discharged without negative influences on other parts of the circuit.

I hope, my English is understandable.

http://www.arunet.co.uk/tkboyd/ec/ec1relay.htm has a schematics of the simplest usage.

Go Up