INFO: Dieses Forum nutzt Cookies...
Cookies sind für den Betrieb des Forums unverzichtbar. Mit der Nutzung des Forums erklärst Du dich damit einverstanden, dass wir Cookies verwenden.

Es wird in jedem Fall ein Cookie gesetzt um diesen Hinweis nicht mehr zu erhalten. Desweiteren setzen wir Google Adsense und Google Analytics ein.

Antwort schreiben 
 
Themabewertung:
  • 0 Bewertungen - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Mehrstufige Schaltung
29.06.2015, 20:06 (Dieser Beitrag wurde zuletzt bearbeitet: 29.06.2015 20:06 von bash42.)
Beitrag #1
Mehrstufige Schaltung
Hallo Gemeinde Smile

ich bin dabei eine temperatuabhängige mehrstufige Schaltung zu bauen.

Im Prinzip soll verschiedenen Tempearaturen (32/30/28/26/24 Celsius) eine Relay-Logik zugeordnet werden.

Als Temperatursensor verwende ich einen AM2302 / DHT22

Ich hab nun das Problem, das die bisher eingetragen Temperaturstufen auf einmal schalten wollen Sad

Sieht dann so aus

Code:
Humidity: 62.70 %    Temperature: 23.90 *C
Humidity: 61.70 %    Temperature: 24.00 *C
Humidity: 91.80 %    Temperature: 28.80 *C
Temperature: 28.80 *C is over 28 *C. Ventilator runs at 130 Volts.
Temperature: 28.80 *C is over 26 *C. Ventilator runs at 100 Volts.
Temperature: 28.80 *C is over 24 *C. Ventilator runs at 80 Volts.
Humidity: 99.90 %    Temperature: 33.30 *C
Temperature: 33.30 *C is over 32 *C. Ventilator runs at 230 Volts.
Temperature: 33.30 *C is over 30 *C. Ventilator runs at 170 Volts.
Temperature: 33.30 *C is over 28 *C. Ventilator runs at 130 Volts.
Temperature: 33.30 *C is over 26 *C. Ventilator runs at 100 Volts.
Temperature: 33.30 *C is over 24 *C. Ventilator runs at 80 Volts.
Humidity: 99.90 %    Temperature: 31.60 *C
Temperature: 31.60 *C is over 30 *C. Ventilator runs at 170 Volts.
Temperature: 31.60 *C is over 28 *C. Ventilator runs at 130 Volts.
Temperature: 31.60 *C is over 26 *C. Ventilator runs at 100 Volts.
Temperature: 31.60 *C is over 24 *C. Ventilator runs at 80 Volts.
Humidity: 99.90 %    Temperature: 30.00 *C
Temperature: 30.00 *C is over 28 *C. Ventilator runs at 130 Volts.
Temperature: 30.00 *C is over 26 *C. Ventilator runs at 100 Volts.
Temperature: 30.00 *C is over 24 *C. Ventilator runs at 80 Volts.
Humidity: 99.90 %    Temperature: 28.90 *C
Temperature: 28.90 *C is over 28 *C. Ventilator runs at 130 Volts.
Temperature: 28.90 *C is over 26 *C. Ventilator runs at 100 Volts.
Temperature: 28.90 *C is over 24 *C. Ventilator runs at 80 Volts.
Humidity: 99.90 %    Temperature: 28.10 *C
Temperature: 28.10 *C is over 28 *C. Ventilator runs at 130 Volts.
Temperature: 28.10 *C is over 26 *C. Ventilator runs at 100 Volts.
Temperature: 28.10 *C is over 24 *C. Ventilator runs at 80 Volts.
Humidity: 99.90 %    Temperature: 27.60 *C
[code]

Was mache ich falsch ?

Hier der komplette Quellcode:

[code]#include <DHT.h>

/* Arduin*/

/*-----( Import needed libraries )-----*/
#include <DHT.h>

/*-----( Declare Constants )-----*/
#define RELAY_ON 0
#define RELAY_OFF 1

#define DHTTYPE DHT22// DHT 22
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

/*-----( Declare Variables )-----*/
#define Relay_1  2  // Arduino Digital I/O pin number
#define Relay_2  3  // Arduino Digital I/O pin number
#define Relay_3  4  // Arduino Digital I/O pin number
#define Relay_4  5  // Arduino Digital I/O pin number
#define Relay_5  6  // Arduino Digital I/O pin number
#define DHTPIN 12 // Arduino Digital I/O pin number

/*-----( Declare objects )-----*/
DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold. It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value. The default for a 16mhz AVR is a value of 6. For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);

void setup()   /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, RELAY_OFF);
  digitalWrite(Relay_2, RELAY_OFF);
  digitalWrite(Relay_3, RELAY_OFF);
  digitalWrite(Relay_4, RELAY_OFF);
  digitalWrite(Relay_5, RELAY_OFF);

  
//---( THEN set pins as outputs )----
  pinMode(Relay_1, OUTPUT);
  pinMode(Relay_2, OUTPUT);
  pinMode(Relay_3, OUTPUT);
  pinMode(Relay_4, OUTPUT);
  pinMode(Relay_5, OUTPUT);    
  delay(4000); //Check that all relays are inactive at Reset

//---( DHT Setup )----
  Serial.begin(9600);
  Serial.println("Arduino");
  dht.begin();

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
//---( Wait a few seconds between measurements )---
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float Humidity = dht.readHumidity();
  float Temperature = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(Temperature) || isnan(Humidity))
  {
    Serial.println("Failed to read from DHT");
  }
  else
  {
    Serial.print("Humidity: ");
    Serial.print(Humidity);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.println(" *C");
  }

  if (Temperature > 32)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_2, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_3, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_4, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 32 *C. Ventilator runs at 230 Volts.");
  }

  if (Temperature > 30)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
    digitalWrite(Relay_2, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_3, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_4, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 30 *C. Ventilator runs at 170 Volts.");
  }
  
  if (Temperature > 28)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
    digitalWrite(Relay_3, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_4, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 28 *C. Ventilator runs at 130 Volts.");
    
    if (Temperature > 26)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_2, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
    digitalWrite(Relay_4, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 26 *C. Ventilator runs at 100 Volts.");
  }
  if (Temperature > 24)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_2, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_3, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 24 *C. Ventilator runs at 80 Volts.");
  }

  }  
  /*
  //Test Section
  digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
  delay(20000);
  digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
  delay(20000);
  */

}//--( end main loop )---


//*********( THE END )***********


Würd mich über hilfe freuen :blush:

Grüße
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
29.06.2015, 20:50
Beitrag #2
RE: Mehrstufige Schaltung
Hi,
schreib vor alle ifs außer dem ersten noch ein "else".
Gruß,
Thorsten

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
29.06.2015, 21:26
Beitrag #3
RE: Mehrstufige Schaltung
Hallo Thorsten,

danke für deinen Tip.

Leider bekomm ich nun beim Überprüfen folgende Meldung

_0.3.ino: In function 'void loop()':
_0.3.ino:127: error: expected `}' before 'else'
_0.3.ino: At global scope:
_0.3.ino:163: error: expected declaration before '}' token

Grüße
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
29.06.2015, 22:31
Beitrag #4
RE: Mehrstufige Schaltung
Zeig bitte den kompletten Sketch.

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
30.06.2015, 05:37
Beitrag #5
RE: Mehrstufige Schaltung
Guten Morgen,

hier der Sketch

Code:
#include <DHT.h>

/* Arduino*/

/*-----( Import needed libraries )-----*/
#include <DHT.h>

/*-----( Declare Constants )-----*/
#define RELAY_ON 0
#define RELAY_OFF 1

#define DHTTYPE DHT22// DHT 22
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

/*-----( Declare Variables )-----*/
#define Relay_1  2  // Arduino Digital I/O pin number
#define Relay_2  3  // Arduino Digital I/O pin number
#define Relay_3  4  // Arduino Digital I/O pin number
#define Relay_4  5  // Arduino Digital I/O pin number
#define Relay_5  6  // Arduino Digital I/O pin number
#define DHTPIN 12 // Arduino Digital I/O pin number

/*-----( Declare objects )-----*/
DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold. It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value. The default for a 16mhz AVR is a value of 6. For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);

void setup()   /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, RELAY_OFF);
  digitalWrite(Relay_2, RELAY_OFF);
  digitalWrite(Relay_3, RELAY_OFF);
  digitalWrite(Relay_4, RELAY_OFF);
  digitalWrite(Relay_5, RELAY_OFF);

  
//---( THEN set pins as outputs )----
  pinMode(Relay_1, OUTPUT);
  pinMode(Relay_2, OUTPUT);
  pinMode(Relay_3, OUTPUT);
  pinMode(Relay_4, OUTPUT);
  pinMode(Relay_5, OUTPUT);    
  delay(4000); //Check that all relays are inactive at Reset

//---( DHT Setup )----
  Serial.begin(9600);
  Serial.println("Arduino");
  dht.begin();

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
//---( Wait a few seconds between measurements )---
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float Humidity = dht.readHumidity();
  float Temperature = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(Temperature) || isnan(Humidity))
  {
    Serial.println("Failed to read from DHT");
  }
  else
  {
    Serial.print("Humidity: ");
    Serial.print(Humidity);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.println(" *C");
  }

  if (Temperature > 32)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_2, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_3, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_4, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 32 *C. Ventilator runs at 230 Volts.");
  }

  else if (Temperature > 30)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
    digitalWrite(Relay_2, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_3, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_4, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 30 *C. Ventilator runs at 170 Volts.");
  }
  
  else if (Temperature > 28)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
    digitalWrite(Relay_3, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_4, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 28 *C. Ventilator runs at 130 Volts.");
    
   else if (Temperature > 26)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_2, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
    digitalWrite(Relay_4, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 26 *C. Ventilator runs at 100 Volts.");
  }
  else if (Temperature > 24)
  {
    //---( Turn relay ON )---
    digitalWrite(Relay_1, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_2, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_3, RELAY_OFF);// set the Relay ON
    digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
    digitalWrite(Relay_5, RELAY_OFF);// set the Relay ON
    Serial.print("Temperature: ");
    Serial.print(Temperature);
    Serial.print(" *C");
    Serial.println(" is over 24 *C. Ventilator runs at 80 Volts.");
  }

  }  
  /*
  //Test Section
  digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
  delay(20000);
  digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
  delay(20000);
  */

}//--( end main loop )---

//*********( THE END )***********
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
30.06.2015, 06:12 (Dieser Beitrag wurde zuletzt bearbeitet: 30.06.2015 06:19 von torsten_156.)
Beitrag #6
RE: Mehrstufige Schaltung
n(" is over 28 *C. Ventilator runs at 130 Volts.");

else if (Temperature > 26)
{
//---( Turn relay ON )---

Vor dem else fehlt ne Klammer.

Gruß Torsten

Hallo,
die Relays schalten alle weil ja bei 30* auch fast alle Bedingungen eintreffen. Du musst in den if's nicht nur mit > abfragen sondern auch mit <.
Ungefähr so:

if TEMP >28 and <29 then...

Gruß
Torsten
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
30.06.2015, 08:06
Beitrag #7
RE: Mehrstufige Schaltung
(30.06.2015 06:12)torsten_156 schrieb:  die Relays schalten alle weil ja bei 30* auch fast alle Bedingungen eintreffen. Du musst in den if's nicht nur mit > abfragen sondern auch mit <.
Ungefähr so:

if TEMP >28 and <29 then...
Nein, muss man nicht. Genau das erledigen die "else".

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
30.06.2015, 10:52
Beitrag #8
RE: Mehrstufige Schaltung
Sorry, stimmtBlush
Wichtig ist dabei aber, dass er mit den Werten von Hoch nach Tief abfragt. Und das macht er jaBig Grin

Gruß
Torsten
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
Antwort schreiben 


Möglicherweise verwandte Themen...
Thema: Verfasser Antworten: Ansichten: Letzter Beitrag
  Telefon-Nummer erkennen - Schaltung auslösen harryba 4 261 13.10.2016 10:12
Letzter Beitrag: hotsystems

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste