Go Down

Topic: Problem commanding sensors please help (Read 555 times) previous topic - next topic

  Hi everyone

  I have  four sensors , 2 for humidity 1 for temperature and 1 for light , that's for making a garden monitoring system . I command four 12 v relays . First time i made the program for reading the sensors and controlling just one relay and everything was ok , but now after connecting the other 3 relays and finishing the whole system the program doesn't work like before . Please tell me if i have an error in my program or it's a hardware problem. I measured the pin where i should have HIGH and i dont have , i have just 2 V . That's making me belive that i have a code problem. Here is the code i have written :

int tempSensor = 0;
int lightSensor = 1;
int moistureSensor1 = 2;
int moistureSensor2 = 3;

int moisture_val;
int moisture_val2;
int light_val;
int temp_val;

int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;

const int waterIsOnPin = 5;


void setup()
{
  pinMode(waterIsOnPin,OUTPUT);
  Serial.begin(9600); // Deschide portul serial
}


void loop()
{
    moisture_val = analogRead(moistureSensor1); // Citeste valoarea senzorului de umiditate
    Serial.print("Senzor de umiditate: ");
    Serial.println( moisture_val );
    delay(500);
   
    moisture_val2 = analogRead(moistureSensor2); // Citeste valoarea senzorului de umiditate
    Serial.print("Senzor de umiditate2: ");
    Serial.println( moisture_val2 );
    delay(500);
   
    light_val = analogRead(lightSensor); // Citeste valoarea senzorului de lumina
    Serial.print("Senzor de lumina: ");
    Serial.println( light_val );
    delay(500);
   
    temp_val = analogRead(tempSensor); // Citeste valoarea senzorului de temperatura
    Serial.print("Senzor de temperatura: ");
    Serial.println( temp_val );
    delay(1000);
   
    // Transpunerea in grade C si F
    Serial.println("     ");
    for(i = 0;i<=7;i++)
    { // gets 8 samples of temperature
      samples = ( 5.0 * analogRead(tempSensor) * 100.0) / 1024.0;
      tempc = tempc + samples;
      delay(100);
    }

    tempc = tempc/8.0; // better precision
    tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit
   
    if(tempc > maxi) {maxi = tempc;} // set max temperature
    if(tempc < mini) {mini = tempc;} // set min temperature
   
    Serial.print(tempc,DEC);
    Serial.print(" Celsius, ");
   
    Serial.print(tempf,DEC);
    Serial.print(" fahrenheit -> ");
    Serial.print(maxi,DEC);
    Serial.print(" Max, ");
    Serial.print(mini,DEC);
    Serial.println(" Min");
    tempc = 0;
    delay(100);
   
    //Verificam daca este necesar sa deschidem releul
    if (moisture_val==0)
    {
      Serial.println("Plantele au nevoie de apa! Pompa de apa deschisa.");
      digitalWrite(waterIsOnPin,HIGH);
      Serial.println("-----------");
    }
    else
    {
      digitalWrite(waterIsOnPin,LOW);
      Serial.println("-----------");
    }
    delay(1000);
}

Many thanks for help

RuggedCircuits

Sounds more like a hardware problem. If you are setting pin 5 high and only measure 2V then either the pin is damaged or you are drawing too much current from it.

What is D5 connected to? Do you have a schematic?

--
The Rugged Audio Shield: Line In, Mic In, Headphone Out, microSD socket, potentiometer, play/record WAV files

I measured 2 v directly on the arduino board , without being connected to something . the 5 pin is connected to a uln 2003 wich command a 12 v relay to open when he gets HIGH signal from arduino

RuggedCircuits

Hmmm...the pin might be damaged then based on how it was connected earlier. Try the simplest sketch to confirm:

Code: [Select]
void setup(void) {
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);
}
void loop(void) {}


If pin 5 is not near 5V then (with nothing connected!) then it's damaged.

--
The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

when i transfer program from PC to arduino board for 1 or 2 seconds all the relays are working and after that they stop. that time is the only time when they've worked and a time or two after but i dont know what  have done to it . the board it has an atmega 8 . it is possible that i've damaged the atmega outputs ? the code looks ok ?

I tried your code and worked . i had 5 v high and 0.14 on low. And curious that i tried to connect one relay of a time , one after another and  the program is working again , but when all four connected it doesn't work , it doesn't do nothing , i think i've made something wrong on the hardware and maybe it isn't enough current to turn all four relays on . But i'm very glad that my program is working again. I don't have any explanation for this , after i've tried your short write code , it is working again :) . Many thanks. I hope that i will manage to get all four relays working well.

corb

If three relays work and it fails on the fourth it sounds like you may not have enough current.  What model are the relays (how many amps)?  Are they all connected to the WaterIsOn pin?

Go Up