Easy IF function and Fail :-(

Hi Guys,

I need some help as I really don't understand what is wrong.


Im going to program a arduino for my digital printing press. When toner is empty on the hardware i will activate a signal that is high. From that point on our software starts counting pulses. Until a certain amount of pulses is reached the machine will give a 'toner fill warning'.

My goal is to program the arduino to setup a TV monitor with the toner condition so there is no need to stay near the machine.

The above I wil try to duplicate via 2 push buttons.

Button 1 is the hardware state
Button 2 i use for counting > so every time the button is pushes it will increase a count (not implemented yet)

I started easy to make sure that if button 1 is pushed a red LED goes on > so far so good..

I tried to add the button 2 > if only BOTH are pushed the red LED goes on.

Result: in my programming the RED LED goes already on when only button 1 is pushed and I can't understand what I'm doing wrong.

PLEASE HELP ASAP... :slight_smile:


int dosLevelSensorButton = 4; //push button for dosLevelsensor
int countPulsesButton = 7; //push button for counting pulses

int ledDosLevel = 8; //LED for DOS level empty
int ledPulses = 2; //LED for puls count

//int countedPulses = 0; //puls counter
int dosLevelState = 0; //state check DOS level sensor
int countPulsState = 0; //state check count puls button

void setup() {


pinMode(dosLevelSensorButton, INPUT);
pinMode(countPulsesButton, INPUT);

pinMode(ledDosLevel, OUTPUT);
pinMode(ledPulses, OUTPUT);


void loop() {

//dosLevelState = digitalRead(dosLevelSensorButton);
//countPulsState = digitalRead(countPulsesButton);

if ((digitalRead(dosLevelState) == HIGH) && (digitalRead(countPulsState) == HIGH)) {

digitalWrite(ledDosLevel, HIGH);
Serial.println("DOS level sensor active");


else { digitalWrite(ledDosLevel, LOW); }


  pinMode(dosLevelSensorButton, INPUT);
  pinMode(countPulsesButton, INPUT);

How are the buttons sewn on? Using INPUT_PULLUP makes wiring switches easier, and more reliable.