You are on page 1of 11

instructables

Arduino Basics With Night Light

by sigritom

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.
Arduino Basics With Night Light: Page 1
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 ash 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 Schematic diagrams use symbols to represent
could be a light, a motor or potatoes! components.

Components have di erent ways of being presented:- In this section I will run through some of the basic
components that will be used in our project at the end.
Realistic illustrations are images or drawings of the
component that look like the component.

Step 3: LED

Arduino Basics With Night Light: Page 2


On the left is the schematic diagram and on the right is What is an LED?
the realistic illustration.
An LED is a diode that lights up when electricity passes
You will notice that one leg of the LED is longer than the through it.
other. The longer leg is called anode and connects to
power and the shorter leg is called cathode. LED = Light Emitting Diode

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


power.)

Step 4: Pushbuttons

Push buttons are switches that will continue the circuit if is another sprigged piece of metal that if pushed down
pressed. The buttons can also be read in your program, will complete the circuit.. This allows electricity to ow
allowing you to start sequences with the push of the through.
button.
How is it detected?
How it works?
When the electricity ows through you can channel it
A push button works by having two pieces of conductive into digital, in which current can be read.
metal apart from each other. In the middle of these there

Step 5: Resistors

Arduino Basics With Night Light: Page 3


A resistor resists the ow of electricity and decreases the heating up very slightly therefore converting the
output voltage. electricity into heat (another energy.)

How it works Why we need it.

Electricity is a type of energy. Like all energy, you can We need resistors, as not all components will run on the
turn it into a di erent type of energy. A resistor works by same current as it will simply be too much.

On a resistor there are lots of di erent colours! Here is a Resistor decoder to help you discover this.

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.

Step 6: Potentiometers

A potentiometer is a component that you can twist to of metal that touches the ring at the point it is facing.
angles you can read.
Finally, the third leg reads the resistance between the
How it works two legs and the knob.

Inside the potentiometer is a circular disk of metal going All of this results in us reading the angle of the knob.
between the front two legs. The middle knob is a piece

Step 7: Bread Board


Arduino Basics With Night Light: Page 4
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.

Arduino Basics With Night Light: Page 5


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

You can colour the wires, but it won't a ect 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.

Arduino Basics With Night Light: Page 6


Step 11: The LED!

In this step, add an Led to the board rotating it, so that of frying your circuit!
the long leg(anode) is connected to power.
Now we are all done.
You can rotate the LED at the top left corner.
Click on the run simulation and what your LED
Put a wire between the push button and the anode leg illuminate as you press the push button!
and then from cathode to negative(ground)

Tinkercad allows you to explore Arduino without the risk

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.

Arduino Basics With Night Light: Page 7


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>

Arduino Basics With Night Light: Page 8


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 de nitions of the variables and Serial.

void setup() {
pinMode(LEDY, OUTPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
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 o 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


Arduino Basics With Night Light: Page 9
We don't want the loop to restart until the nger is o other wise the LED will ash.

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

・。・。・。・。・。・。・。・。・。・。・。・。・・。・。・。・。・。・。・。・。・。・。・。・。
・・。・。・。・。・。・。・。・。・。・。・。・。・・。・。・。・。・。・。・。・。・。・。・。・。

Arduino Basics With Night Light: Page 10


Download

https://www.instructables.com/ORIG/FHK/Q46C/KLGLANWA/FHKQ46CKLGLANWA.brd

Arduino Basics With Night Light: Page 11

You might also like