Need beginner help making a project

Hey, just to note out first, I’m an absolute beginner in Arduino so forgive me if I’m being too general on how I’ll interpret things. I started it recently for school and I have only learnt till Arithmetics and Logical operators, and recently I’m assigned to do a project from imagination about a “computational” project that likely involves use of math operators.

The thing is, I have no idea how to code the project I have in mind being an newbie in Arduino. I’m planning to make a project where if I assign some variables or numbers to be compared, they’ll either go to a TRUE or FALSE. Then, on the breadboard depending on whether or not the compared result of the two variables is wrong, will then let an LED lighten up. So technically, if the comparison is wrong it should light out an red LED and otherwise a green one. I also am planning to make it operate continuously till it gets the correct answer and lights up the proper LED, but I’m unsure how can I make this work.

Any tips or starting recommendations for me to get an idea on how I could code this would be a huge help since I’ve only started learning this month. Thanks!

This link includes an entire range of Arduino hardware and software items.

Suggest you try each link that makes sense to you.

If you know the basics of arithmetic and comparison in c++ language , you just have to write an algorithm -> it helps visualizing your project and it get a good structure .

Int pinRed= 6;  // pin 6 used for red led 
Int pinGreen= 5; // pin 5 used for green led 


Setup ()
{
Serial.begin (9600);   // communication speed 

pinMode (pinRed , OUTPUT);   //define either output or input 

pinMode (pinGreen , OUTPUT);
Int Value 1 ;    // set your variables 
Int value 2 ;

}
Loop()
{

/* For this part check how to read values from Serial */

If (Value1==Value2 ) {
digitalWrite (pinRed ,LOW);  // turn off Red led 
digitalWrite (pinGreen ,HIGH);  // Turn on green led
}
else { 
digitalWrite (pinGreen,LOW);
digitalWrite (pinRed ,HIGH);
}
 Delay (1000) ; 

}

This is approximately how your code will look like , don't forget to include libraries

Try to start from here

1 Like

Hello, thanks for the help! I’m trying your code out but the LEDs don’t seem to light up for some reason in my breadboard. Here’s an image of how I circuited it on Tinkercad, but I tried beforehand on a real breadboard,


Could I be doing some small mistake?
Here’s also the code I did from your help, with slight changes:

const int pinRed = 6;  
const int pinGreen = 5;

void setup ()
{
Serial.begin (9600); 

pinMode (pinRed , OUTPUT); 

pinMode (pinGreen , OUTPUT);
int a = -107;
int b = 36;
}
void loop()
{


if ( -107 > 36 ) {
digitalWrite (pinRed ,LOW);
digitalWrite (pinGreen ,HIGH);  
}
else { 
digitalWrite (pinGreen,LOW);
digitalWrite (pinRed ,HIGH);
}
 delay (1000) ; 
}

So far, the only issue is that the LED lights are not lighting up. I’m also thinking of what can I add onto the code you made to make it more functional to my preferences, thanks!

Seriously?

1 Like

Your resistors are not connected to gnd....

Thanks! This worked out. Only one LED is lighting up, but I think that was my intention for the project anyway.

Sorry, can I know which wasn’t right?

Serious about what , I never told him to compare raw values

Do you compare two random values or values that you insert with keyboard?

If you define variables in setup(), you cannot access them in loop().

Do you want to compare Arduino generated random numbers to a number you enter?
I put some code together to do that. Here is the output when I entered 22.

Follow Post#3 of the below link to learn how to enter numbers. Ask for help if you have questions

Thanks, I was wondering what I did wrong in the code :sweat_smile:

Not necessarily, but this was interesting so I might give it a try

Yeah, kind of unfortunate I missed that for a few hours, thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.