all of digitalread always high when it double ' if ' statement

int E0 = 8;

void setup()
{
  pinMode(E0, INPUT_PULLUP);

    //we need to specify 2x the desired baud rate
    //as the Arduino lib assumes 16MHz
    //so for 150bps spec 300
    Serial.begin(300);     //we need to spec 2x the desired freq

    noInterrupts();
    CLKPR = (1<<CLKPCE);    //enable prescaler write
    CLKPR = (1<<CLKPS0);    //write CLKPS0 to give 0001 or /2
    interrupts();

}//setup

void loop()
{
  
  if (digitalRead(E0) == HIGH) 

    //write 0x55 and check w/scope
    Serial.write( 0x55 );


    //500mS delay between chars (delay works at half-speed now...)
    delay(1500);

}//loop


}
}

hello, i want to:

5v input. digitalread(1) ---- >serial.write to ( tx) pin 1.
5v input. digitalread(2) ---- >serial.write to ( tx) pin 1.

but i can't do that.. indeed, above code work very good for me. just one digitalread, one serialwrite. it's ok.
it was perpect.

but, when i modified code like below,

all of digitalread always open and they writing serial doesn't matter which pin was high, or low.
(...all of pin always write serial...)

how i understand about this?
please help me.

int E0 = 8;
int E1 = 10;

void setup()
{
  pinMode(E0, INPUT_PULLUP);
  pinMode(E1, INPUT_PULLUP);
  
    //we need to specify 2x the desired baud rate
    //as the Arduino lib assumes 16MHz
    //so for 150bps spec 300
    Serial.begin(300);     //we need to spec 2x the desired freq

    noInterrupts();
    CLKPR = (1<<CLKPCE);    //enable prescaler write
    CLKPR = (1<<CLKPS0);    //write CLKPS0 to give 0001 or /2
    interrupts();

}//setup

void loop()
{
  
  if (digitalRead(E0) == HIGH) 

    //write 0x55 and check w/scope
    Serial.write( 0x55 );

 
  if (digitalRead(E1) == HIGH) 
{

    //write 0x55 and check w/scope
       Serial.write( 0x01 );


    //500mS delay between chars (delay works at half-speed now...)
    delay(1500);

}//loop


}
}

Get rid of the horrible multiple blank lines in your sketch. Format with a ctrl-T in the IDE, and have a look at your {} brackets. I did that and saw the problem right away.

int E0 = 8;
int E1 = 10;



void setup()
{
  pinMode(E0, INPUT_PULLUP);
  pinMode(E1, INPUT_PULLUP);


  //we need to specify 2x the desired baud rate
  //as the Arduino lib assumes 16MHz
  //so for 150bps spec 300
  Serial.begin(300);     //we need to spec 2x the desired freq

  noInterrupts();
  CLKPR = (1 << CLKPCE);  //enable prescaler write
  CLKPR = (1 << CLKPS0);  //write CLKPS0 to give 0001 or /2
  interrupts();

}//setup

void loop()
{

  if (digitalRead(E0) == HIGH) // && digitalRead(11)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
  {

    //write 0x55 and check w/scope
    Serial.write( 0x55 );


  }


    if (digitalRead(E1) == HIGH) // && digitalRead(11)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
    {

      //write 0x55 and check w/scope
      Serial.write( 0x01 );




    }



      //500mS delay between chars (delay works at half-speed now...)
      delay(1500);

    }//loop

I FIXED IT

but, i can't....

You can't, what? You FIXED what?

I FIXED IT

But you decided to leave the code looking horrible I see

This did not translate well. Language problem???
Try a language closer to your native language:
中文 - Chinese
Deutsch - German
Español - Spanish
Français - French
অসমীয়া, বাংলা, बड़ो (India)
Italiano - Italian
Nederlands - Dutch
Português - Portuguese
Русский - Russian
Svenska - Swedish, Suomi - Finnish, Norsk - Norwegian

I have no any clue yet.
Is there Wrong ‘{ }’ position?
Or, need to separate void loop1, 2 ()?
Why not single digitalread but multiples were cannot returning state ‘LOW’? In addition, all of digital read pin they declared are always Writing serial at the same time.

Poor English & translation fail is so sorry

have you ever used

??
this is the list of languages that google can translate

Afrikaans
Albanisch
Amharisch
Arabisch
Armenisch
Aserbaidschanisch
Baskisch
Bengalisch
Birmanisch
Bosnisch
Bulgarisch
Cebuano
Chichewa
Chinesisch
Dänisch
history
Deutsch
history
Englisch
Esperanto
Estnisch
Filipino
Finnisch
Französisch
Friesisch
Galizisch
Georgisch
Griechisch
Gujarati
Haitianisch
Hausa
Hawaiisch
Hebräisch
Hindi
Hmong
Igbo
Indonesisch
Irisch
Isländisch
Italienisch
Japanisch
Javanisch
Jiddisch
Kannada
Kasachisch
Katalanisch
Khmer
Kinyarwanda
Kirgisisch
Koreanisch
Korsisch
Kroatisch
Kurdisch (Kurmandschi)
Lao
Lateinisch
Lettisch
Litauisch
Luxemburgisch
Malagasy
Malayalam
Malaysisch
Maltesisch
Maori
Marathi
Mazedonisch
Mongolisch
Nepalesisch
Niederländisch
Norwegisch
Odia (Oriya)
Paschtu
Persisch
Polnisch
Portugiesisch
Punjabi
Rumänisch
Russisch
Samoanisch
Schottisch-Gälisch
Schwedisch
Serbisch
Sesotho
Shona
Sindhi
Singhalesisch
Slowakisch
Slowenisch
Somali
Spanisch
Suaheli
Sundanesisch
Tadschikisch
Tamil
Tatarisch
Telugu
Thailändisch
Tschechisch
Türkisch
Turkmenisch
Uigurisch
Ukrainisch
Ungarisch
Urdu
Usbekisch
Vietnamesisch
Walisisch
Weißrussisch
Xhosa
Yoruba
Zulu

best regards Stefan

For a further analysis:

300 baud is pretty slow. writing a single byte at 300s baud need 1/300*10 = 33 milliseconds.

So how do the signals connected to IO-pin 8 and IO-pin 10 look like?

Can you post a handdrawn picture of how the signals look lilke
including information how long is the voltage-level HIGH? How long low?
what is the minimum time between E0 goes HIGH and E1 goes high?

And all in all as you still have problems though the code looks good except the really bad formatting
give an overview about your project
best regards Stefan

Thanks. I'll organize the situation so far and upload it soon.

int E0 = 3;
int E1 = 6;

void setup()
{
  pinMode(E0, INPUT);
  pinMode(E1, INPUT);

  //we need to specify 2x the desired baud rate
  //as the Arduino lib assumes 16MHz
  //so for 150bps spec 300
  Serial.begin(300);     //we need to spec 2x the desired freq

  noInterrupts();
  CLKPR = (1 << CLKPCE);  //enable prescaler write
  CLKPR = (1 << CLKPS0);  //write CLKPS0 to give 0001 or /2
  interrupts();

}//setup

void loop()
{

  if (digitalRead(E0) == HIGH) // && digitalRead(11)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
  {

    //write 0x55 and check w/scope
    Serial.write( 0x55 );
  }



  if (digitalRead(E0) == LOW) // && digitalRead(11)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
  {

    //write 0x55 and check w/scope
    Serial.write( 0x88 );
  }

  if (digitalRead(E1) == HIGH) // && digitalRead(11)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
  {
    Serial.write( 0x01 );
  }

  if (digitalRead(E1) == LOW) // && digitalRead(11)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
  {

    Serial.write( 0x02 );
  }

  //500mS delay between chars (delay works at half-speed now...)

  delay(1500);
}//loop

Several tests were conducted.
First, the 5v digital signal has an idle voltage of about 1.2v.
When activated, it is converted to 5.6v. and The serial signal was identified by a logic analyzer.

digitalread Pin #3
It always returns 0x55(HIGH) regardless of whether an active signal line is plugged into the Aduino digital pin or an idle voltage signal line. If you don't pick anything, 0x88(LOW).

digitalread Pin # 6:
It does not return anything, whether it is an active signal or an idle voltage signal. It is just fixed at 0x01(HIGH).
it never 0x02(LOW).

and tested also changed digital pin several times on arduino.
The GND wire is engaged. board UNO.

I don't know if there's enough information.

Put this program to the side temporarily. Load this example and change the input pin number to either 3 or 6, whichever you want to test. You can change the INPUT_PULLUP to INPUT if you like.

This will echo the input pin state on the onboard LED to make the hardware troubleshooting easier.

Thanks. I can test 9 hour later. I will using another UNO too.

If that doesn't work, you need to explain your tests more clearly and in much more detail. In order to do that, I think the suggestion in reply #7 would help enormously.

upload the blueprint.

When I experimented with other Arduino boards, the same symptoms still appear, so I think it is not a mechanical defect.

It recognizes the voltage signal of the smart thermostat and writes a letter.

for example when

digitalread1: tx: 1234
digitalread2: tx: 5678

Y and W are dependent on R (r1, r2) to detect voltage applied and operate as a switch concept.

When the circuit is configured and voltage is measured, the voltage from the output of the 5v converter is 5.5v when Y or W is turned on, respectively.

google translated my language .

Hi coockoos,

the translation is easy to understand and even gramatically good.
though with the small information you have given it is still not clear to me how the whole thing should work.

If your main goal is to distract finishing your project - You could go on posting 20 more short-worded posts
each time making other users ask back for more details and over time loose their patience to answer at all.

If you would like to accelerate finsihing your project you should take ONCE 30-60 minutes of time
to explain EACH and EVERY detail how all the parts shall work together and post a loooooong posting

To help you identify what is important:

There is this smart thermostat with two outputs
This smart thermostat switches on the red wired output if heating shall be switched on?
The blue wired output switches on when cooling shall be switched on?

Your code shall send some data over the serial-interface at 30 baud to something that is called logic analyzer?

If this description is right answer yes. If there is something wrong you have to write a correct and even more detailed description about all parts of your system.

best regards Stefan

coockoos:
Y and W are dependent on R (r1, r2) to detect voltage applied and operate as a switch concept.

When the circuit is configured and voltage is measured, the voltage from the output of the 5v converter is 5.5v when Y or W is turned on, respectively.

What voltage do you read on the input pins when W (Heating) and Y (Cooling) are off? If that voltage is not very close to zero you may be reading "HIGH" even when the W and Y are 'off'.

Rather than using 24VAC to 5VDC converters, you should probably try 24VAC relays. Set the inputs to INPUT_PULLUP and use relay contacts between the pin and Ground to change the input from HIGH to LOW.


there is on of detail.

Add a detail here.

The smart thermostat works in the same way as above.
The smart thermostat applies voltage to one of the Y and W lines along with C.

This will activate the above ac 24 to dc 5v converter.

I've used input_PULLUP, but it just sticks high.

The last picture is an attempt to mount pull-up and pull-down resistors.

Tested with another Arduino Uno board, I connected the ground, but the value fluctuates, repeating high and low.

When I connect the resistor, the floating disappears. But the value is crappy.

When the device is turned off, all values go low.

There is no reaction when the cooling (Y) is turned on.

When heating (W) is turned on, all pins are turned on.

There was no abnormality in the voltage measured by the converter.

What voltage do you read on the input pins when W (Heating) and Y (Cooling) are off? If that voltage is not very close to zero you may be reading "HIGH" even when the W and Y are 'off'.

Rather than using 24VAC to 5VDC converters, you should probably try 24VAC relays. Set the inputs to INPUT_PULLUP and use relay contacts between the pin and Ground to change the input from HIGH to LOW.

Idle voltage is measured below 1.5v.

I will change the relay. There seems to be hope. and can you explain 24v relay wiring for me ?

PLUS for register: they writen just said '220' on the envelope.
I'm not sure how many ohms that means.

internal pullup does only work if you use a relay or a switch.
The internal pull-up-resistor supplies the IO-pin with a 5V = HIGH.
And only in case a pure metallic electrical connection is made from IO-pin to ground
through an electromechanical relay or a switch the voltage goes down to 0,0V.

your SZDULI 24V to 5V converter is an electroncial device that is able to deliver 5V if 24V is connected
to the input. In case of switching the 24V off. The 5V output will stay high maybe even for an hour because big electrolytic capacitors inside are still charged and if you just connect it to an IO-pin the IO-pin needs a so small current that the voltage stays at 5V minimum for minutes.

After that time if it still stays HIGH depends on the inner ciruitry of this 24V/5V converter whch you and I don't know.
You can try to use a 1 kohm resistor as a pull-down-resistor.
You shouldn't go below 1 kohm because then the dissipated heat in the resistor will get to high and maybe burn through the resistor.

This means one end is connected to the IO-pin the other to Ground. And the +5V output of your 24V/5V-converter is then connected to the IO-pin too.

This might work because the 1kOhm resistor will discharge the 24V/5V-converter.

As you can see from this explanation. It IS really important to give a lot of information to narrow down the problem.

best regards Stefan

I am checking the voltage in the circuit every moment with a multimeter. The abnormal voltage was not particularly noticeable to the SDULZI converter. When switched off, they always knew through the multimeter that it was going down 1.5V. And when using only one of these converters, the above is not a problem at all. However, there is a problem when using two converters. Thank you.