Sei sulla pagina 1di 24

LEDs

Circuit Schematic
Circuit Schematic

Note: Don’t worry too much about the triangles at the top and bottom! The LED is something
called a “diode,” which is just like a resistor but it only lets current through one way (in the
direction of the arrow).

We put the second resistor there to limit the current; if there is too much current through a
circuit, it will overload it and fry out!
Circuit Schematic

How does it work?

The Arduino can act as a battery that turns on and off according to our code. When it is on,
current flows through the LED and the resistor, and this current causes the light to turn on in the
LED. When the Arduino battery is off, there is essentially no battery connected to the circuit and
so the light turns off.
Building the Circuit
Picture

1. Connect the blue rail to the GND pin on the


Arduino. Connect the red rail to pin 10 on the
Arduino -- we can control the voltage we let
through on this pin.
Schematic
Picture

Building the Circuit


2. Connect a wire from the positive
rail (the red one) to a row in the middle. It
doesn’t matter which row, but in this case I
chose row 15 arbitrarily.
Schematic
Picture

Building the Circuit


3. Connect the positive leg of the LED (that’s the
longer leg) to the row that you just chose.
Again, in my case that is row 15. Connect the
negative leg to a different row -- in this case, I
chose row 18.
Schematic
Building the Circuit
4. Find a 1 kΩ resistor. The colors, in order, are brown → black → red → gold.

Schematic Picture
Picture

Building the Circuit


5. Connect the second row that you
chose -- the one with the negative end of the
LED -- to ground (the blue rail) through a 1 kΩ
resistor. Schematic
Testing Your Circuit
To check if your circuit works, move the wire that is connected to the red rail
from pin 10 to the pin labeled ‘5V’.
Code
Currently, the code is broken. Once you fix it, use the “upload” button (circled
below) to send the code to the Arduino!
Code
We’ll start by using the code provided by Arduino.

Click on Examples → Basics → Blink. Connect the Arduino to your computer


via the cable, and then click the rightward arrow to upload your code.
Code
Hopefully, after a few seconds your LED should start blinking.
Congratulations! You’ve built your first circuit.

If it isn’t working after about 30 seconds, try uploading the code again. If it’s
still not working, let us know and we can help you debug!
Changing the Physical Circuit
Q: What happens if we lower the resistance?
Changing the Physical Circuit
Q: What happens if we lower the resistance?

A: The LED gets brighter! This is because lower resistance means higher
current, and the higher current makes the LED shine more brightly.
Changing the Code
So far our LED can blink at a steady pace, but that’s not very useful.

What if we used it for Morse code?


Code Files
https://tinyurl.com/invent-2019-code

This link will take you to a Google Drive. Look for two files named
“morse_code_led.” Open the text file and copy/paste it into the online editor. If
this doesn’t work, download the other file (ending in “.ino”) and then upload it
to the editor -- we can help you with this.
Future Steps
1. Change the delay and message in the code; feel free to change variables
and add functionality if you want. If it breaks, you can always copy the
code from the drive link again.
2. Add a button to the circuit so that it turns on/off when you hit the button.
3. Add an ultrasonic sensor to the circuit so that it greets you with a
message when you walk up to it.
4. Use a photovoltaic sensor to create a “receiver” circuit that can read and
decode your blinking light back into English.
Button Sensor
Button Sensor
Tips for code:

In setup, set pin 9 as an input pin with the command pinMode(9, INPUT);

Check pin 9’s voltage with readDigital(9);

If the button is pressed (switch is closed) then it will return HIGH

If the button is not pressed (switch is open) then it will return LOW

Use a boolean variable to keep track of whether the light is on already, and
then use if statements to decide whether to turn it on or off

Turn the light on with digitalWrite(10, HIGH); and off with


digitalWrite(10, LOW);
1 2

Button Sensor
3 4
Tips for circuit:

When the button is pressed, it connects its legs diagonally


Above, it would connect 1 to 4 and 2 to 3

Connect the 5V pin to the red rail and GND to the blue rail so you can
use
them for both sensing the button press and powering the LED.
Distance Sensor
Distance Sensor
Coding Tips

● Search “Examples → Sensors → Ping” for an example of how this sensor


works (you can copy some of this code)
● Set a distance threshold and check if the sensed distance is below it;
assign this to a boolean value
● Use the same code as you did for the button sensor to turn the light on or
off
Distance Sensor
Circuit Tips

● The sensor has four pins that you need to connect


○ VSS: 5v Rail (Red)
○ GND: Ground Rail (Blue)
○ TRIGGER: Connect to a digital output pin - you will send a short high pulse to this pin in
order to trigger the sensor to make a measurement
○ ECHO: Connect to a digital input pin - this is where you will receive a pulse that tells you
how far away the sensor has measured

Potrebbero piacerti anche