input output flicking light

We are working on a project for an engineering class and we are trying to do a simple input output circuit however the light is flickering on and off even when there is no input. We have tried two different uno boards and a mini. Ultimately we want this code to be able to work on the mini. The code is in the attachment if someone could take a look at it and let us know what we are doing wrong it would be very helpful. Thank you.

Capture code.PNG

I'm guessing from its name that your PNG shows a picture of some text. Don't post pictures of text. Just copy and paste the text and to make it easy for people to help you please use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

If your picture is not text then please display it in your post so we can see it without downloading it. See this Simple Image Guide

...R

When the button state is HIGH you are turning the LED on but then after a short delay turning it off again, hence the flicker.

Why is a button pin called RainSensor? Sensible variable names are a very good idea.

And/or I'm gong to guess the input is floating (no connection at all) when the switch is open.

You need a pull-up or pull-down resistor as shown in the [u]Digital Read Serial Example[/u].

The easiest solution is to use the [u]optional-internal pull-up resistors[/u]. But, you'll have to re-wire the switch so pulls the input down to ground, and you'll have to reverse your program logic so that input-low turns the LED on.

[]BTW -[/b] You don't have to turn the LED off after the delay because the loop is going to immediately start-over, read the switch again and turn the LED on or off depending on buttonState.

...And, do you really need the delay? Or, if you want to blink the LED you'll need another delay after you turn it off (and you'll want more than 10mS).