0

I want to build a program which identifies logic gates connected to Arduino, by testing the output with changing the input voltage...

Here is the code:

int output1 = 0; //Change output pins HERE 
int output2 = 1; //and HERE 
int input = 2; //Change the input pin HERE, where we will read the data (0 or 1) 
void setup() { 
 pinMode(output1, OUTPUT); 
 pinMode(output2, OUTPUT); 
 pinMode(input, INPUT); 
 Serial.begin(9600); // Start serial communication at 9600 bps 
}
void loop() { 
 int result[12]; 
 for(int i = 0; i < 2; i++) // For failure test, it runs 3 times 
 { 
 digitalWrite(output1, LOW); 
 digitalWrite(output2, LOW); 
 delay(1000); //Wait for 1sec 
 result[i * 4] = digitalRead(input); 
 digitalWrite(output1, LOW); 
 digitalWrite(output2, HIGH); 
 delay(1000); //Wait for 1sec 
 result[i * 4 + 1] = digitalRead(input); 
 digitalWrite(output1, HIGH); 
 digitalWrite(output2, LOW); 
 delay(1000); //Wait for 1sec 
 result[i * 4 + 2] = digitalRead(input); 
 digitalWrite(output1, HIGH); 
 digitalWrite(output2, HIGH); 
 delay(1000); //Wait for 1sec 
 result[i * 4 + 3] = digitalRead(input); 
 } 
 if(result[0] != result[4] && result[0] != result[8] && result[1] != result[5] && result[1] != result[9] && result[2] != result[6] && result[2] != result[10] && result[3] != result[7] && result[3] != result[11]) // See if the results don't matches... 
 { 
 Serial.println("Input read error, please try again!"); 
 } 
 if(result[0] == 0 && result[1] == 0 && result[2] == 0 && result[3] == 1) // AND gate 
 { 
 Serial.println("This is an AND gate"); 
 } 
 else if(result[0] == 0 && result[1] == 1 && result[2] == 1 && result[3] == 1) // OR gate 
 { 
 Serial.println("This is an OR gate"); 
 } 
 else if(result[0] == 1 && result[1] == 1 && result[2] == 1 && result[3] == 0) // NAND gate 
 { 
 Serial.println("This is a NAND gate"); 
 } 
 else if(result[0] == 1 && result[1] == 0 && result[2] == 0 && result[3] == 0) // NOR gate 
 { 
 Serial.println("This is an NOR gate"); 
 } 
 else if(result[0] == 0 && result[1] == 1 && result[2] == 1 && result[3] == 0) // EXOR gate 
 { 
 Serial.println("This is an EXOR gate"); 
 } 
 else if(result[0] == 1 && result[1] == 0 && result[2] == 0 && result[3] == 1) // EXNOR gate 
 { 
 Serial.println("This is an EXNOR gate"); 
 } 
 else // If there is no match... 
 { 
 Serial.println("This is not even a gate"); 
 } 
} 

It always gives back 1s... I have tested with leds, it works perfectly by changing the input, but as soon as serial.begin is declared in setup, it fails to work, the just stays on and I said, the program just gives back 1s.

What I'm missing?

Thanks!

asked Jul 29, 2017 at 10:17

1 Answer 1

1

Arduino uses pins 0 and 1 for Serial. Use other pins in your sketch

answered Jul 29, 2017 at 10:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.