Hello, I would really appreciate help for my beginner school project

This Image is a representation of the circuit I am supposed to build for a project for school. However, I have little to no knowledge over how to use circuits, build them, etc. All I have so far is a code for the Arduino UNO that seems shaky at best (it works in the simulation, but I don't know if it also works IRL?) and I would really, really appreciate some help.

If anyone is knowledgeable in this field, please, do respond to this thread. The main things I'm confused about is what components would we actually need? I've made a basic list so far, yet there are topics such as capacitors etc. which just confuse me more. All I would need to know are what components I would need to fully make this a functioning circuit, as well as maybe some hints as to if my code would truly work IRL.

The following is the code:

int LEDR=11;
int pir=2;
int buzzer=5;
int r=11;

void setup()
{
  pinMode(pir,INPUT);
  pinMode(LEDR,OUTPUT);
  pinMode(buzzer,OUTPUT);  
}

void loop()
  
{
  int val= digitalRead(pir);
  Serial.println(val);
  if(val==HIGH){
    digitalWrite(LEDR,r);
}
  
  if (val==HIGH){
    digitalWrite(buzzer,HIGH);
}
  
  else{
  digitalWrite(LEDR,LOW);
  digitalWrite(buzzer,LOW);
}
  
  delay(10);
  
}

Please do let me know if this would work. Any help would be much appreciated. Thank you to anyone who takes the time to respond in advance.

Looks like it would work.

One improvement could be that you place digitalWrite(LEDR,r); in the second if just above digitalWrite(buzzer,HIGH); and get rid of the first if.

What makes you say that?

You will have to test; as they say, "the proof of the pudding is in the eating".

1 Like

the ones from the drawing...

where do you see one?

1 Like

Is there a question hidden somewhere?

They asked you to build an electronic circuit knowing that you know nothing about electronics.
What kind of school is this?
Why don't you ask your teachers for help?

3 Likes

Hello rizhi

Welcome to the best Arduino forum ever. :slight_smile:

My advice run some examples provided by the IDE to gain the knowledege about electronics and coding first.

2 Likes

I read online that apparently capacitors are also needed to "smooth" out the voltage's fluctuations.

I don't know, this was my first go at coding something and all I did was mix and match the codes form different circuits on Tinkercad till something fit, and I called it a day due to the due date being ridiculously close to when we got the assignment assgned.

The testing thing is, again, difficult to do as the due date for the documentation is tomorrow. I am supposed to provide date like which currents and which voltage certain components will be provided with, yet I can't do that in my current circumstances. The teacher really knows how to make life hard😭

I would truly love to do that, however the time our teacher gave us for this project, specifically the assignment I'm currently working on, is extremely short. I don't think it'd be possible for me to gain a basic understanding of coding and electronics, and then also be able to submit my assignment till tomorrow. :sob:

No books, tutorials, videos, no classroom instructions or class notes?

I assumed you studied this in class, didn't you?

Reformatting your code (CTRL-T in the IDE) makes it easier to see structure:

int LEDR = 11;
int pir = 2;
int buzzer = 5;
int r = 11;

void setup()
{
  pinMode(pir, INPUT);
  pinMode(LEDR, OUTPUT);
  pinMode(buzzer, OUTPUT);
}

void loop()
{
  int val = digitalRead(pir);
  Serial.println(val);
  if (val == HIGH) {
    digitalWrite(LEDR, r);
  }
  if (val == HIGH) {
    digitalWrite(buzzer, HIGH);
  }
  else {
    digitalWrite(LEDR, LOW);
    digitalWrite(buzzer, LOW);
  }
  delay(10);
}

The things that look weird to me is missing a Serial.begin(115200); in setup and the use of "r".

I'd use a Serial.print(val); instead of a println() to make the diagnosing less frantic, but if the pir is wired up right, you should see useful diagnostics on the serial monitor.

1 Like

Looks like the teacher was so annoyed by a bunch of smombies that don't want to read any books that he resignated :ghost:

For the confusing "r" and the buzzer, maybe you should look into digitalWrite(), analogWrite(), and tone().

If you are confused, then you can test each part in the setup() function.
Let the led blink, make the buzzer buzz, and show something on the Serial Monitor.
Here is my own interpretation in the Wokwi simulator:

2 Likes

I would love to, except I have no idea what those lines actually do :sob:

I apologize for my lack on knowledge and I know this is probably annoying, but what is a serial monitor?
If it has something to do with code, I've made my entire code in Tinkercad so I'm not really too sure about what it means. Thank you, though, I'll replace this piece of code with the original one. :heart_hands:

so you have not studied Arduno, programming in C++, basic components and wiring, etc during your school year?

sounds surprising you get such an assignment unless this is to test how self sufficient you are...

what kind of school is that?

I'm sorry if I phrased my post weirdly, I'm in a hurry and I didn't get the chance to critically go over the phrasing. I basically would like to know what components I would need to build the project because looking on the internet just confused me more because what I saw did not correlate yet apparently somehow had something to do with my project. :sob:

Here's documentation for the words in those lines:

https://docs.arduino.cc/programming/

And @Koepel's excellent advice to "test each part in the setup()" and his simulation in #16 show what they can do.

1 Like