Programs in Arduino are know as “sketches”, to create a new sketch go to File –> New. You should now have a blank sketch that looks like the picture on the left. The first part of a sketch is setup. The setup code runs only once at the start, this is where you set up variables, ports, sensors, … The second part of a sketch is loop, the loop code runs continuously.
On the left you can see an example of a simple sketch, let’s look at all the code … Let’s start with the setup, in setup we are telling Arduino that we are going to use pin 10 as an output, that means that we can tell the Arduino to send information to pin 10. Whenever you want to use a port you have to tell Arduino which ports you want to use and if they will be inputs or outputs.
The first command in loop tells Arduino to turn on port 10 (digitalWrite), what this means is that the port will go from 0V to 5V (HIGH) and if you have an LED connected to this port it will light up. The next command (delay) tells the Arduino to do nothing for 1000 milliseconds or 1 second. Then we turn port 10 off, it will go back to 0V (LOW) and the LED will turn off as well. Lastly we have another wait command. After the wait command the program will go back to the start of loop and the program will start again. The result is an LED that will blink with a 1 second interval.
Things to try:
Change the delays and see what happens
Connect an LED to port 7 and change the code accordingly
Connect 2 LEDs to 2 different ports and make both blink at the same time
Now you’re ready to start building your own circuits …
You need to know how a breadboard works. This image shows how all the holes in the breadboard are connected. Breadboards provide an easy way to build circuits without having to do any soldering.
This is an example of a basic electronic circuit. On the left you see the power source, the long line represents + and the short line represents -. If you would connect the + directly to the – you would create a short-circuit and could damage your power source. The resistor “resists” current flowing through the circuit and prevents a short-circuit. More resistance = less current.
In any circuit you need to have an uninterrupted path from + to – before any current can flow.
Above is an example of a circuit with an LED. You can see a power source, an LED and a resistor in the circuit. You can also see that there is an uninterrupted path for the current to flow, the current will pass through the LED and through the resistor. You should be able to build this circuit using a breadboard and components.
What will happen if you change the value of the resistor?
What will happen if you put the resistor in front of the LED?
What will happen if you turn around your LED (switch + and -)?
What will happen if you add a second LED after the first one?