Guys please help i cant get anything to work i just simpely want a button i press then timer counts down and after relay activates but nothing i do work and with everything i add it gets worse with more problems this is the code so far anything else i added i could not upload on arduino

int buttonPin = 12;
int relayPin = 13;

void setup() {
// put your setup code here, to run once:

void loop() {
if (digitalRead(buttonPin) == HIGH)
digitalWrite(relayPin, HIGH);
if (digitalRead(buttonPin) == LOW)
digitalWrite(relayPin, LOW);

Guys please help i cant get anything to work

It helps if you make a practice or reading the instructions.

In this case you first need to go and read the forum instructions so that you can go back and modify your original post - the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output) from the IDE and click the icon. In fact, the IDE has a “copy for forum” link to put these markings on for you so you then just paste it here in a posting window.

It is inappropriate to attach it as a “.ino” file. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

But don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code”, it can be quite garbled and is always more difficult to read.

…with everything i add it gets worse with more problems …

Post your code within code tags </>

Start simple, get it working then add things keeping it working all the time.
So to begin with just read state of buttonPin and print it out.
Once that works read the state of buttonPin and output it to relayPin.
Once that works add in a delay.
Always include print statements so that you know exactly where your code is, what it is doing and why.

How is the button switch wired? Do you have a pulldown resistor on the button switch input? Post a schematic of your circuit.


What is the f doing there?

Read the how to use this forum-please read stickies to see how to post code properly and hints on how to get the most from the forum.

Try this way of using if: