Arduino Basics With Night Light




Introduction: Arduino Basics With Night Light

About: I've been on instructables just short of a year now. , I'm 13 years old and like to build and create. I like lego, building wooden toys, k-nex, gravitrax, programming, and have recently started playing wi…

Recently I have been playing around with Arduino.

Arduino is really cool and is a great way to learn electronics.

In this Instructable I will teach you the basics of Arduino including:

  • LED's
  • Buttons
  • Potentiometers
  • Resistors
  • Tinkercad
  • And a project with this knowledge.

Step 1: The Board

The controller can be broken down into a few simple parts. The colours correspond to the image.

  • The green box provides power to the Arduino and this is plugged in to a USB cable.
  • The orange provides the power to the bread board either 5v or 3.3v as well as ground.
  • The red port is a port to power the Arduino without USB at 7-12v.
  • Purple is a reset button for the microcontroller.
  • Pale blue is the brains of the operation.
  • Yellow are the digital pins.
  • Navy is analog in.
  • Turquoise is the power LEDs that indicates if there is power.
  • Finally cyan is TX and RX LEDs They will flash rapidly when you upload a sketch/code.

You don't have to remember all the names but its good have a vague idea of what everything is.

Step 2:

A component is anything that is included in a circuit. This could be a light, a motor or potatoes!

Components have different ways of being presented:-

Realistic illustrations are images or drawings of the component that look like the component.

Schematic diagrams use symbols to represent components.

In this section I will run through some of the basic components that will be used in our project at the end.

Step 3: LED

On the left is the schematic diagram and on the right is the realistic illustration.

You will notice that one leg of the LED is longer than the other. The longer leg is called anode and connects to power and the shorter leg is called cathode.

Tip - (The black - is usually ground in circuits and red + is power.)

What is an LED?

An LED is a diode that lights up when electricity passes through it.

LED = Light Emitting Diode

Step 4: Pushbuttons

Push buttons are switches that will continue the circuit if pressed. The buttons can also be read in your program, allowing you to start sequences with the push of the button.

How it works?

A push button works by having two pieces of conductive metal apart from each other. In the middle of these there is another sprigged piece of metal that if pushed down will complete the circuit.. This allows electricity to flow through.

How is it detected?

When the electricity flows through you can channel it into digital, in which current can be read.

Step 5: Resistors

A resistor resists the flow of electricity and decreases the output voltage.

How it works

Electricity is a type of energy. Like all energy, you can turn it into a different type of energy. A resistor works by heating up very slightly therefore converting the electricity into heat (another energy.)

Why we need it.

We need resistors, as not all components will run on the same current as it will simply be too much.

On a resistor there are lots of different colours!

What are these? The colour on a resistor is a code that tells us how much energy they are going to soak up from our circuit.

Here is a Resistor decoder to help you discover this.

Step 6: Potentiometers

A potentiometer is a component that you can twist to angles you can read.

How it works

Inside the potentiometer is a circular disk of metal going between the front two legs. The middle knob is a piece of metal that touches the ring at the point it is facing.

Finally, the third leg reads the resistance between the two legs and the knob.

All of this results in us reading the angle of the knob.

Step 7: Bread Board

A bread board is excellent for prototyping and requires no soldering.

A bread board has lots of horizontal strips of wire. When components are put in, they act as connecters.

In the image above you can see that the circuit will only continue when a component is between two strips.

Step 8: Tinkercad!

Tinkercad has a circuit designer on board. Just head over to circuits on the left of your projects.

Once you are in, you can build and create prototypes before making them physically.

You can even code your circuits!

Lets create a button and LED

(you can use tinkercad circuits if you don't have an Arduino)

Step 9: Getting Started

Pull out the Arduino and bread board and lay them out on the work plain.

Next wire 5v to +/positive and then ground to -/negative.

You can colour the wires, but it won't affect your circuit if you don't.

Step 10: The Button

You then need to wire a 220 ohm resistor to the a push button.

Without the resistor the 5v would be too much for the button and the LED.

The resistor must also be wired to positive, as that has the electricity going to it.

You can change the resistance of the resistor in the top right as shown.

Step 11: The LED!

In this step, add an Led to the board rotating it, so that the long leg(anode) is connected to power.

You can rotate the LED at the top left corner.

Put a wire between the push button and the anode leg and then from cathode to negative(ground)

Tinkercad allows you to explore Arduino without the risk of frying your circuit!

Now we are all done.

Click on the run simulation and what your LED illuminate as you press the push button!


Step 12: The Practical 🔨

Now it's time for the fun bit!

We are going to create a night light that uses most of what we have learnt so far.

(this will require some programming, but I will explain it simply)


Step 13: The Circuit

Above is the circuit setup in Tinkercad, as it is easier and more crisp to see the circuit. ↑

The LEDS don't have to be green. I have white and yellow LEDs, so it's like a night light.

Remember to keep the cathode to positive and the resistors to ground.

Step 14:

Now it's time for the code.

To start, you have have to know what serial is.

Serial is an extension that can print the information that you give or receive so that you know what is happening.

Serial monitor(the extension that prints)can be found in the top right of the Arduino app.

Step 15: The Setup

Without us telling the Arduino it has no clue what is plugged in where.

( // = notes that are not read by the program just us)

As it is a variable, if you tell the code about the variable at the beginning it will remember it for later.

int pushButton =3;
int LED = 4;
int LEDY = 5;
int val = 0;
//int (is a variable)'...'  (is the new name of the variable)  = '...'  (declaring what port it is connected to) <br>

Step 16: What the Variable Is

We still haven't told the code what the variable is. It could be an OUTPUT or an INPUT>

An OUTPUT is a component that receives data such as an LED (It gives light if it is receiving electricity.)

An INPUT is a component that gives data such as a pushbutton(it gives information whether it is being pushed.)

The void setup is where you setup the definitions of the variables and Serial.

void setup() {
  pinMode(LEDY, OUTPUT);
  pinMode(LED, OUTPUT);
  pinMode(pushButton, INPUT); 

// if its inside {} then it will correspond with the other code inside those {}.
// {} = curly brackets
//LEDY = my yellow LED      LED = my white LED
// We have now labelled the LEDs as outputs and push buttons as inputs as well as setup the serial port.

Step 17: Reading the Buttons State

For this project to work we have to know if the button is being pressed. When a button is pressed electricity can pass through so by understanding this we can read whether there is a current let past (On).

void loop() {
  int buttonState = digitalRead(pushButton);  // new variable is always what the button is 0/1 

  if (buttonState > 0){                       // if the button is pressed/ > 0 ( 1 ) continue
    val = digitalRead(LED);                   //new variable is now reading if the LED is on/off
    Serial.print("buttonState = ");           //print buttonState ready to make sense of on/off.
    Serial.print(buttonState);                //print in Serial if button on or off (1 or 0).
    Serial.print("  val  = ");                //print val ready for LED on/off 
    Serial.println(val);                      //print if LED on or off (1 or 0)

Step 18: On or Off?

This code will turn off the LED if it is on and vice versa.

      if (val == 1){                      // if the first led is on then continue if not pass. 
          digitalWrite(LED, LOW);         // turn the LED that's on off
          digitalWrite(LEDY, HIGH);       // turn the other LED that's off on.    
      }                                   // end this if loop
      else if (val == 0){                 // if first LED is off then continue if not pass. 
          digitalWrite(LED, HIGH);        // turn the first LED that's off on
          digitalWrite(LEDY, LOW);        // turn the other LED that's on off
      }                                   //end this else loop

// this code turns one light on and the other off according to one of the LEDs state.

Step 19: Wait Until Button Not Pressed

We don't want the loop to restart until the finger is off other wise the LED will flash.

    do                                            // it will do code whilst doing another code
    {delay(1);                                    // wait 0.1s
    } while (digitalRead(pushButton) == 1);       // wait 0.1s whist's button is pressed 
  }                                               // end a loop
}                                                 // end the main loop

// by clicking on the curly bracket you can see where its origins are/ start of the loop.

Step 20: Now You Have Finished!

This is an awesome build and is easy to change or edit.

I hope you enjoyed this Arduino tutorial. If so, please consider voting for me

Here's the tinkercad model and some of my pictures ↴↴

Step 21: Portfolio


Microcontroller Contest

Participated in the
Microcontroller Contest

Be the First to Share


    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Chocolate Challenge

      Chocolate Challenge
    • Tinkercad to Fusion 360 Challenge

      Tinkercad to Fusion 360 Challenge



    1 year ago

    Nice first project, very good


    1 year ago

    when i go to verify the code in the 'do' section it says pushButton was not declared in this scope? Any suggestions please? I even copied and pasted the whole sketch and it just seems to be filled with errors


    Best Answer 1 year ago

    If you are doing the sketch in Tinkercad than you will want to get rid of all the notes.
    (beginning with //)
    If you need any more help just ask ッ
    Here is a blank copy without comments:
    int pushButton =3;
    int LED = 4;
    int LEDY = 5;
    int val = 0;
    void setup() {
    pinMode(LEDY, OUTPUT);
    pinMode(LED, OUTPUT);
    pinMode(pushButton, INPUT);
    void loop() {
    int buttonState = digitalRead(pushButton);
    if (buttonState > 0){
    val = digitalRead(LED);
    Serial.print("buttonState = ");
    Serial.print(" val = ");
    if (val == 1){
    digitalWrite(LED, LOW);
    digitalWrite(LEDY, HIGH);
    else if (val == 0){
    digitalWrite(LED, HIGH);
    digitalWrite(LEDY, LOW);
    } while (digitalRead(pushButton) == 1);


    Answer 1 year ago

    Did you copy the first part of the sketch where the variables are declared?


    1 year ago

    This is great! Thank you for sharing so many details :)


    1 year ago

    Nice first project, well done