Project

So i got this project for school, and i start arduino 2 days ago.
I have to make an anti-theft alarm with these specs:
i have a button,lcd display, 2 sensors a magnetic one and a vibration one,and 3 leds(Green,Red)

The system must have a on/off option on the button, if on the green led on, if the alarm is off the green led is off.
If the alarm is on, and there is a breach in the house the RED led should be on, and display a message on the screen, but if there is no breach the red and blue led must be on and off alternatively
If the alarm is off and there is a breach the Blue led is on and display a message on the screen.
I build this code,it compiles it but when i upload it to the bord it’s not working properly.Please help me get this trough:D

The code i build is in the txt file

cod engleza.txt (1.27 KB)

How is your switch wired?

What does the sketch do? What do you expect it to do? How do they differ?

What kind of vibration sensor do you have? It seems unlikely that it is a digital device.

You turn the Green LED off at the beginning of loop().

The button is only on as long as you have it held down (which will then turn the Green LED on until the beginning of the next trip through loop()).

You assign the vibration sensor to an analog input, but then try to use a digitalRead() with it.

I can't tell you how the button is wired,the hole project it was assembled by the teacher, we just have to write the code for it.And the vibration sensor i think it is a piezo vibraton sensor.

If my code is corect(not 100% sure it is) it should do smthing like this: If the alarm is on, and there is a breach in the house the RED led should be on, and display a message on the screen, but if there is no breach the red and blue led must be on and off alternatively If the alarm is off and there is a breach the Blue led is on and display a message on the screen.

but if i upload it to the board, the green and red leds are always on, and on the display it show constantly some weird message.

I can’t tell you how the button is wired,the hole project it was assembled by the teacher

Go flap your lips at the teacher, then, and ASK!

i think it is a piezo vibraton sensor.

Which is an analog device. You connect it to an analog pin, and use analogRead() to read it.

What is stareButon ?

You use pin 5 as an input for the magnetic sensor and also as a pin for the LCD?

evanmars: What is stareButon ?

It is the state of the button, if pushed or not

evanmars: What is stareButon ?

You use pin 5 as an input for the magnetic sensor and also as a pin for the LCD?

As i said i can't take the board home and i don't know the numbers,so i put some random values.Those values will be changed with the right values from the board.

Sorry, I see where stareButon is defined now.

You do realize that the code in loop() will be executed thousands of times every second, right?

You are always turning the Green LED off, then deciding if you should turn it back on again.

How can you write code for a button if you don't know how it is wired to work? It appears that they may be wired to be HIGH when not pressed, and go LOW when pressed.

You didn't get any information on the circuit or instruction other than "Make these lights go on and off under these circumstances"?

You can't hope to write working code when you don't even know what you're writing the code for! You can't just pick random numbers for the pins and expect every thing to work.

You definitely need to get more information from your instructor.

Something like that....and he was like "wirte the code home and the next time you'll test it,if you have troubles search it on google, there are lots of videos and tutorials"

You need to write the code one section at a time. Connect the switch to the Arduino. Learn to read the switch state. If it seems to be random, you probably have a floating pin. Turn the internal pullup resistor on, and try the code again.

Then, connect the LED(s). Learn to turn them on and off.

Then, connect the LCD. Learn to write to it.

Then, connect the vibration sensor. Learn to read it.

Then, connect the magnetic sensor, Learn to read it. It, too, may need the internal pullup resistor enabled.

When you know how to connect each piece, you can connect them all, and run the individual sketches again, to make sure that there are no pin conflicts. If there are, correct them.

Then, you can use the ideas from each program to build the final program.

If you don't have the board and chip with you, maybe you could try Autodesk Circuits or something like that. You can build "virtual boards" and test code on them.

Try to build one that looks like your teacher's board.

https://circuits.io/ go to "create" and then "electronics lab".

That works for me anyway. You might have to sign up for an account.