Thanks for your help all. Here's what I have so far:
And here's my code:
/*
Debounce
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached from pin 2 to +5V
* 10K resistor attached from pin 2 to ground
*/
// constants won't change. They're used here to
// set pin numbers:
const int button1Pin = 2; // the number of the pushbutton pin
const int button2Pin = 3;
const int ledPin = 12; // the number of the LED pin
// Variables will change:
int ledState = HIGH; // the current state of the output pin
int button1State; // the current reading from the input pin
int button2State;
int lastButton1State = LOW; // the previous reading from the input pin
int lastButton2State = LOW;
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can't be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
float AnalogWert;
float Powerwert;
long lastVoltageReadTime = 0;
long lastVoltageReadDelay = 1000;
void setup() {
Serial.begin(9600);
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(ledPin, OUTPUT);
// set initial LED state
digitalWrite(ledPin, ledState);
}
void loop() {
// read the state of the switch into a local variable:
int reading1 = digitalRead(button1Pin);
int reading2 = digitalRead(button2Pin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading1 != lastButton1State || reading2 != lastButton2State) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading1 != button1State || reading2 != button2State) {
button1State = reading1;
button2State = reading2;
// only toggle the LED if the new button state is HIGH
if (button1State == HIGH || button2State == HIGH) {
ledState = !ledState;
if(ledState == HIGH){
Serial.println("Relay OFF");
} else {
Serial.println("Relay ON") ;
}
}
}
}
// set the LED:
digitalWrite(ledPin, ledState);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButton1State = reading1;
lastButton2State = reading2;
if ((millis() - lastVoltageReadTime) > lastVoltageReadDelay) {
lastVoltageReadTime = millis();
AnalogWert = analogRead(A0);
Powerwert = AnalogWert *(15.0/1023); //in case of higher voltage, change the code: powerwert = AnalogWert *(x/1023); x= your new power supply maximum voltage
Serial.println(Powerwert);
}
}