Fehlersuche, Arduino, Menü, Strommesssensoren

Hallo, ich bin noch nicht ganz so lange dabei und versuche gerade zwei Strom und Spannungssensoren in mein Menü einzufügen.

Was ich nicht ganz blicke ist, wie man die Sensorwerte von einander unterscheidet und das so
aufschreibt. Also dass beide unterschiedliche Werte ausspucken...

LG Felix

Danke!

Code:




#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Stepper.h>
#include <RTClib.h>



LiquidCrystal_I2C lcd(0x27, 20, 4);



const byte upButtonPin = 35;
const byte downButtonPin = 39;
const byte rightButtonPin = 30;
const byte leftButtonPin = 32;


const byte Led_S = 13;

const byte  L_Haus = 41;


const byte  ROT = 24;
const byte  GELB = 22;
const byte  GRUEN = 26;


const byte  F_ROT = 33;
const byte  F_GRUEN = 45;



int SPU = 2048;
int Sensor = A0;
int Sensor2 = A1;
int VpA = 185;
int sensorwert1= 0;
int Nullpunkt = 0;
double SensorSpannung = 0;
double Ampere = 0;
int Sensorwert2;




String MenuItems[9] = {
  "1.Solarenergie",
  "2.Windenergie",
  "3.Garagentor",
  "4.Luftqualitaet",
  "5.Strassenlaternen",
  "6.LED Haus",
  "7.Ampel",
  "8.Akkustand",
  "9.Uhrzeit/Datum",
};


RTC_DS1307 rtc;


template< typename T, size_t NumberOfSize >
size_t MenuItemsSize(T (&) [NumberOfSize]) {
  return NumberOfSize;

}



int numberOfMenuItems = MenuItemsSize(MenuItems) - 1;
int currentMenuItem = 0;
int previousMenuItem = 1;
byte button_flag = 0;
unsigned long previousMillis;
const int note = 4699;




void setup() {
  Serial.begin(115200);
  ///////////////Buttons//////////////////////

  pinMode(upButtonPin, INPUT_PULLUP);
  pinMode(downButtonPin, INPUT_PULLUP);
  pinMode(rightButtonPin, INPUT_PULLUP);
  pinMode(leftButtonPin, INPUT_PULLUP);

  ////LCD/////////////////////////////////////
  lcd.init();
  lcd.backlight();

  ////RealTimeClock///////////////////////////
  while (!Serial) ;
  delay(200);
  Serial.println("RTC Read Test");
  Serial.println("-------------------");
  /////////////////////////////////////////////

  pinMode(Led_S, OUTPUT);

  pinMode(L_Haus, OUTPUT);

  pinMode(ROT, OUTPUT);
  pinMode(GELB, OUTPUT);
  pinMode(GRUEN, OUTPUT);

  pinMode(F_ROT, OUTPUT);
  pinMode(F_GRUEN, OUTPUT);

  pinMode(0, INPUT);

  
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }
}



void menuFunctions(int menu, byte right, byte left) {   
  switch (menu) {


case 1:

        lcd.clear();
        lcd.setCursor(3, 0);
        lcd.print("1.Solarenergie");


    if (right || left == 1) {

        lcd.setCursor(0, 2);
        lcd.print("Stromstaerke=");
        lcd.setCursor(0, 3);
        lcd.print("Spannung=");
        
        }
          break;


case 2:

        lcd.clear();
        lcd.setCursor(3, 0);
        lcd.print("2.Windenergie");


    if (right || left == 1) {

        lcd.setCursor(0, 2);
        lcd.print("Stromstaerke=");
        lcd.setCursor(0, 3);
        lcd.print("Spannung=");
        
        }
          break;


case 3:

        lcd.clear();
        lcd.setCursor(4, 0);
        lcd.print("3.Garagentor");


    if (right == 1) {

        lcd.setCursor(0, 3);
        lcd.print("Close");
        lcd.setCursor(10, 3);
        lcd.print("Open <");
      //  digitalWrite(Motor, LOW);
        delay(1000);
        }


    if (left == 1) {

        lcd.setCursor(0, 3);
        lcd.print("Close <");
        lcd.setCursor(10, 3);
        lcd.print("Open");
        //digitalWrite(Motor, HIGH);
        delay(1000);
      }
          break;


case 4:

      if (right || left == 1) { 

      if (Sensorwert2 >= 50) {

          lcd.setCursor(14, 2);
          lcd.print("SCHLECHT");
            } 


      else {

          lcd.setCursor(14, 2);
          lcd.print("GUT");
        }
      }
          break;


case 5:

        lcd.clear();
        lcd.setCursor(1, 0);
        lcd.print("5.Strassenlaternen");


      if (right == 1) {

        lcd.setCursor(0, 3);
        lcd.print("Off   ");
        lcd.setCursor(10, 3);
        lcd.print("On  <<");
        digitalWrite(Led_S, HIGH);
      }


      if (left == 1) {

        lcd.setCursor(0, 3);
        lcd.print("Off <<");
        lcd.setCursor(10, 3);
        lcd.print("On    ");
        digitalWrite(Led_S, LOW);
      }
          break;


case 6:

        lcd.clear();
        lcd.setCursor(5, 0);
        lcd.print("6.LED Haus");


      if (right == 1) {

        lcd.setCursor(0, 3);
        lcd.print("Off   ");
        lcd.setCursor(10, 3);
        lcd.print("On  <<");
        digitalWrite(L_Haus, HIGH);
      }


      if (left == 1) {

        lcd.setCursor(0, 3);
        lcd.print("Off <<");
        lcd.setCursor(10, 3);
        lcd.print("On    ");
        digitalWrite(L_Haus, LOW);
      }
          break;


case 7:

        lcd.clear();
        lcd.setCursor(6, 0);
        lcd.print("7.Ampel");


      if (right || left == 1) {
        
        lcd.setCursor(0, 3);
        lcd.print("druecken <<");
        delay(3000);
        digitalWrite(GRUEN, LOW);
        digitalWrite(GELB, HIGH);
        delay(1000);
        digitalWrite(GELB, LOW);
        digitalWrite(ROT, HIGH);

        delay(3000);
        digitalWrite(F_ROT, LOW);
        digitalWrite(F_GRUEN, HIGH);
        delay(6000);
        digitalWrite(F_GRUEN, LOW);
        digitalWrite(F_ROT, HIGH);
        delay(1000);
        digitalWrite(GELB, HIGH);
        delay(1000);
        digitalWrite(ROT, LOW);
        digitalWrite(GELB, LOW);
        digitalWrite(GRUEN, HIGH);
      }
          break;


case 8:

        lcd.clear();
        lcd.setCursor(4, 0);
        lcd.print("8.Akkustand");


      if (right == 1) {

        lcd.setCursor(0, 2);
        lcd.print("Akkustand=");
      }
          break;


case 9:
      //showTime;
          break;
  }
}


void print2Digits(int no) {
  if (no >= 0 && no < 10) {
    lcd.print("0");
  }
  lcd.print(no);
}



void showTime() {
  DateTime now = rtc.now();
  lcd.setCursor(0, 2);
  lcd.print("Uhrzeit:");
  print2Digits(now.hour());
  lcd.print(':');
  print2Digits(now.minute());
  lcd.print(':');
  print2Digits(now.second());
  lcd.setCursor(0, 3);
  lcd.print("Datum:");
  print2Digits(now.day());
  lcd.print('/');
  print2Digits(now.month());
  lcd.print('/');
  lcd.print(now.year());
}






void loop() {


if (currentMenuItem+1 == 9)  showTime();



if (digitalRead(rightButtonPin) == LOW && button_flag == 0) {

    menuFunctions(currentMenuItem + 1, 1, 0);
    button_flag = 1;
    previousMillis = millis();
    } 


else if (digitalRead(leftButtonPin) == LOW && button_flag == 0) {

    menuFunctions(currentMenuItem + 1, 0, 1);
    button_flag = 1;
    previousMillis = millis();
    } 


else if (digitalRead(upButtonPin) == LOW && button_flag == 0) {

    currentMenuItem++;

if (currentMenuItem > numberOfMenuItems) {

    currentMenuItem = numberOfMenuItems ;
    }
    button_flag = 1;
    previousMillis = millis();
    } 


else if (digitalRead(downButtonPin) == LOW && button_flag == 0) {

    currentMenuItem--;


if (currentMenuItem < 0) {

      currentMenuItem = 0;
    }
    button_flag = 1;
    previousMillis = millis();
    
  }
  

if (currentMenuItem != previousMenuItem) {
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print(MenuItems [currentMenuItem]);
    menuFunctions(currentMenuItem + 1, 0, 0);
    previousMenuItem = currentMenuItem;
  }

if (millis() - previousMillis >= 400) {
    previousMillis = millis();
    button_flag = 0;

  }




  sensorwert1 = analogRead(Sensor);


  SensorSpannung = (sensorwert1 / 1024.0)*5000;
  //Ampere = ((SensorSpannug - Nullpunkt) / VpA);


  //Seriel.print("Sensorwert = ");
  //Seriel.print("\t Sensorspannung in mV = ");
  //Seriel.print(SensorSpannung,3);
  //Seriel.print("\t Ampere = ");
  //Seriel.print(Ampere,3);
  //delay(1000);
  



  //sensorwert = analogRead(Sensor2);


  //SensorSpannung = (sensorwert / 1024.0)*5000;
 // Ampere = ((SensorSpannug - Nullpunkt) / VpA);


  //Seriel.print("Sensorwert = ");
  //Seriel.print(sensorwert1);
  //Seriel.print("\t Sensorspannung in mV = ");
  //Seriel.print(SensorSpannung,3);
  //Seriel.print("\t Ampere = ");
  //Seriel.print(Ampere,3);
  //delay(1000);
  



Sensorwert2 = analogRead(0);           
      
      Serial.print("Der erfasste Wert lautet : "); 
      Serial.println(Sensorwert2, DEC);         

}

Im englischen Teil des Forum müssen die Beiträge und Diskussionen in englischer Sprache verfasst werden.
Deswegen wurde diese Diskussion in den deutschen Teil des Forums verschoben.

mfg ein Moderator.

Da liest du wieder von A0. Du meinst vermutlich
Sensorwert2 = analogRead(Sensor2);
, falls du den an A1 angeschlossen hast.

So wie Du angefangen hast:

hättest Du hier

weitermachen müssen.

TIPP: Bevor Du den Code postest, einmal alle überflüssigen Leerzeilen löschen.
Das liest sonst kein Mensch.
Die entscheidene Zeile ist:

Das Ding wird zu:

Sensorwert2 = analogRead(Sensor2);

Ich hoffe das ist Gelichstrom den Du da mißt.
Grüße Uwe

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.