Getting Started with Arduino, Chapter 4: Really Getting Started with Arduino
Anatomy of an interactive device
An interactive device senses the environment using sensors and interacts with the real world using actuators.Sensors and Actuators
Sensors and actuators are components that allow a piece of electronics to interact with the world. Micro controllers can only process electric signals. Our eyes are an example of a sensor. They convert light into signals that are then processed by the brain. In electronics, we can use an LDR (light-dependent resistor) or a photoresistor.Blinking an LED
The first thing we are going to build is a blinking LED to test our newly installed Arduino. The Arduino board is equipped with an LED on pin 13. You can also connect your own LED to pin 13 on the board.LED components:
- K = cathode (negative) the shorter leg.
- A = anode (positive) longer leg
![]() |
| Anatomy of an LED |

If you don't get the "Done Compiling" message, you will need to make sure everything is typed correctly. Once the code is compiled, you can upload it to the board. The Arduino will start running the code once it has been uploaded. If all the steps were correct, you will see the LED blink on and off as shown below.
Pass Me the Parmesan
The curly braces {} are used to group code together, much like asking someone to pass the Parmesan cheese while at the dinner table. The main difference is of course, all the steps needed to get the Parmesan cheese from one end of the table to the other must be explicitly spelled out inside the curly braces.void setup() gives a name to the code contained within the curly braces. The arduino can only execute one line of code at at a time.
Arduino is not for quitters
Arduino requires two functions setup() and loop(). Without these two functions, your code won't compile. setup() contains all the instructions needed to start up your program, and loop() is a special function that runs forever without stopping. The only way to stop arduino from running the instructions is to turn it off.Real tinkerers write comments
Comments are lines of code that star with double slashes // and will not be executed by your arduino. It is always advisable to include comments in you code, so that you or others can understand what you were doing at some point in the future.The code, step by step
A few notes on the code:- const: is a piece of memory that can not be changed later.
- OUTPUT: tell the pin to write the data out
- pinMode(): is a special function, it takes a pin number, and whether to use that pin as an input or output
- digitalWrite(): function that takes two arguments, a pin number and whether to set the voltage to high or low
- delay(): tells the arduino how long to wait until it runs the next line of code, in milliseconds
What we will be building
In chapter 5 and 7, we will be building an interactive lamp.What is electricity
Voltage is a the amount of pressure that a "pump" can produce. Current is the amount of flow of electricity. The formula for this relationship isR = V / Iwhere:
- R = resistance
- V = Voltage
- I = Current
Using a Pushbutton to Control the LED
By using the digitalRead() we are connecting a pushbutton to make our LED stay on.How does this work?
There are two new ideas introduced here, the if statement and functions that return values. The if statement is one of the most important statements in all of programming. If statements ask a question. When true the first part is executed, when false the second part is executedif(answer is true) {The digitalRead() returns a value and we are storing it in the variable val. One thing to make note of:
do this
} else {
do this instead
}
- = (single equal sign) means to assign the item on the right to the item on the left (int val = 0)
- == (double equal sign) means to check if two things are equal (1 == 1)
One circuit, a thousand behaviors
Variables are introduced again in this section. A variable unlike a constant can be changed later in our code. Either by taking input from the outside world, or some other condition in your code. Just by changing your code, we have now changed how our circuit works.Note
If you run into an error, make sure you have put a semicolon at the end of the line.All variables are stored in RAM. RAM is cleared when your arduino is turned off. The author goes through several iterations to show off different ways to make the board work better.
This is a very useful skill for moving forward in working with Arduino and programming in general. You can star with a simple design or sketch, and make it better or more complicated as you go, and the needs are better defined. It is almost always better to get something to work as a proof of conecpt, and then you can see what needs to be done from there.


Comments
Post a Comment