hi. i am new to arduino. i want to make the arduino print this on serial monitor:
-> ..................................
-> 1
-> 1
-> ..................................
when i connect pin 5v to pin 2 and pin 3
-> ..................................
-> 0
-> 0
-> ..................................
when i did not connect anything
-> ..................................
-> 1
-> 0
-> ..................................
when i connect pin 5v to pin 2 only
-> ..................................
-> 0
-> 1
-> ..................................
when i connect pin 5v to pin 3 only
this is the code:
#include <SoftwareSerial.h>
int aa = 0;
int ab = 0;
void setup() {
// initialize the pushbutton pin as an input:
pinMode(2, INPUT);
pinMode(3, INPUT);
Serial.begin(9600);
}
void loop() {
delay(100);
aa = digitalRead(2);
ab = digitalRead(3);
Serial.println("..................................");
Serial.println(aa);
Serial.println(ab);
Serial.println("..................................");
}
but what happen to me is the serial monitor show me this:
-> ..................................
-> 1
-> 1
-> ..................................
when i connect pin 5v to pin 2 and 3
-> ..................................
-> 1
-> 0
-> ..................................
when i did not connect anything
-> ..................................
-> 1
-> 0
-> ..................................
when i connect pin 5v to pin 2 only
-> ..................................
-> 1
-> 1
-> ..................................
when i connect pin 5v to pin 3 only
sometime when i try to connect this according to method at above, the arduino did not read the pin* and give the aa and ab variable a random number either 0 or 1.
*(but when i test the digital input 1 by 1 and all ok)
Can you help me solve this problem?
i'm using this code on arduino uno and arduino mega 2560.
thank you very much