for my project im trying to make a set of indicators, by basically pressing a button, and the led starts blinking, then pressing the button again, so they stop.

This is my first project with arduino and was wanting some help with coding.

This is what i have so far, but it only kind of works

Any help or guidance is much appreciated!

int button = 3;
int ledPin=13;
int state = 0;
int count = 0;

void setup(){
pinMode(button, INPUT);
pinMode (ledPin, OUTPUT);

void loop(){
state = digitalRead(button);
if(state == HIGH){
count = count + 1;

if(count == 1){
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);

if (count == 2){
digitalWrite(ledPin, LOW);

if (count == 3){
count = 1;


In loop() you increment count as long as the button pin is HIGH. I.e. count is constant only while the pin is LOW, and this is not what you want.

Furthermore make sure that the button pin is LOW when the button is not pressed. Buttons normally are connected from the pin to Gnd (LOW), and the pin is in HIGH state by use of a pullup resistor (to Vcc) or by mode INPUT_PULLUP.

Did you already try a simple example, showing how to debounce an button?

Use button library for debouncing


boolean blinking = false;
int ledpin = 13;
Button button = Button(3,PULLUP);

void setup() {
void loop() {
  if(button.uniquePress()) {
    blinking = !blinking;
   digitalWrite(ledpin, HIGH);   
    digitalWrite(ledpin, LOW);   

Have a look at the demo several things at a time.


Right... What Robin is trying to tell you is that you can't read the button (or do anything else) during the delay() time.