• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino pompka 12V i odwrotne działanie
#1
Hej, jestem w trakcie robienia sprzetu do podlewania moich truskawek  Rolleyes
Jestem totalnie zielony wiec licze na wasza pomoc, mam juz sketch tylko działa mi to odwrotnie, jak wyßwietla komunikat ze nie trzeba podlewac to podlewa. 
Moze mi ktos podpowiedziec co mam zle ? Pompa podlaczona pod relay dziala ale odwrotnie. Plz help newbie...
Kod:
// read the value from a soil moisture sensor
   
   // PIN in Option "easy"
   // GND to GND
   // VCC to 5 Volt
   
   // PIN in Option "anti_oxidation"
   int soilMoisturePin1 = 4;    // VCC not to 5 Volts - in this Option to Digital Output 4
   int soilMoisturePin2 = 3;    // GNG not to GND - in this Option to Digital Output 3
   int soilMoisturePin3 = A0;   // SIGNAL an einen Analog Pin vom Arduino Board
   int baudrate = 9600;
   
   // 1023 = 100% RAW-Wert is between 0 wet and 1023 dry on 5 Volt
   //  901 = 100% RAW-Wert is between 0 wet and  903 dry on VIN Volt
   //  672 = 100% RAW-Wert is between 0 wet and  672 dry on 3,3 Volt
   // The sensor returned 18% with RAW 188 when fully sunk into the water and light wave movements.
   const int dry = 1023;
   
   const int relayPin = 6;  // SIGNAL from Relay
   int pump_threshold = 60; // it soil DRY >=60% then activate a pump
   
   void setup()
   {
     Serial.begin(baudrate);
     while(!Serial); //Waiting for Serial connection
     pinMode(soilMoisturePin1, OUTPUT);
     pinMode(soilMoisturePin2, OUTPUT);
     pinMode(relayPin, OUTPUT); //Set pin 6 as an OUTPUT
     digitalWrite(relayPin, LOW); // Relay off - no pump at start
   }
   
   int readSoilMoisture()
   // Das größte Problem eines Feuchtigkeitssensors ist Oxidation. Der Korrosion wird durch Elektrolyse entgegengewirkt mit dieser Funktion.
   // Diese Funktion aktiviert unseren Soil Moisture Sensor für 500ms, liest den aktuellen Wert aus, dreht die Polarität um und deaktiviert den Sensor wieder.
   // The biggest problem of a moisture sensor is oxidation. Corrosion is counteracted by electrolysis with this function.
   // This function activates our Soil Moisture Sensor for 500ms, reads the current value, rotates the polarity, and deactivates the sensor.
   
   {
   int value;
   digitalWrite(soilMoisturePin1, HIGH);
   digitalWrite(soilMoisturePin2, LOW);
   delay(500); // es wird jede 0,5 sec gemessen - dies könnte auch deutlich seltener eingestellt werden
   value = analogRead(soilMoisturePin3);
   digitalWrite(soilMoisturePin1, LOW);
   digitalWrite(soilMoisturePin2, HIGH);
   delay(500);
   digitalWrite(soilMoisturePin2, LOW);
   return value;
   }
   
   void loop()
   {
     // Option "easy": int value_water = analogRead(soilMoisturePin3);
     int value_water = readSoilMoisture();
     String water = String((int)((((double)value_water/dry)*100.0)));//Convert Raw value to percentage. This is a generic calculation, depending on raw values from 0 to 1023.
     Serial.print("Soil moisture: ");
     Serial.print(water);
     Serial.print("% Raw value: ");
     Serial.println(value_water);
     
     //Change String2Integer and check if threshold is reached
     if (water.toInt() >= pump_threshold) //
     {
     Serial.println("Too dry, we should water it.");
     digitalWrite(relayPin, HIGH);
     }
     else
     {
     Serial.println("It is wet enough, no need to water it.");
     digitalWrite(relayPin, LOW);
     }

   }
Relay podpiety do pinu 6, 5V i GND.
Help madrzy ludzie  Huh
Milego dnia Smile
 
Odpowiedź
#2
Witam,
Zamień wszystkie digitalWrite(relayPin, LOW); na digitalWrite(relayPin, HIGH);
a digitalWrite(relayPin, HIGH); na digitalWrite(relayPin, LOW);
i delektuj smakiem truskawek.
Pozdrawiam.
 
Odpowiedź
#3
Dzięki za szybką odp Smile
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości