Arduino Basics


Arduino Basics

Simon
Welcome back to our crash course on Arduinos. An Arduino is a small electronic board that can help you build everything from a simple candy dispenser to an interactive robot. The board itself may look complicated, but the basic idea is straightforward: it takes information in, processes it, and makes something happen.

Anna
And that same basic pattern can power a surprising range of projects. You could use one in arcade builds, automatic bowling or dart setups, a nightlight, or a device that responds when someone lifts a lid. So let's unpack the pattern before we get into the wiring and code.

Simon
A useful analogy is a human being. We need energy, our eyes and ears take in information, our brain processes it, and then our muscles act. An Arduino project has a similar arrangement: a power source provides energy, a sensor gathers information, the Arduino acts as the brain, and outputs such as motors carry out its instructions.

Anna
So, in one example, an infrared sensor could detect a signal and send that information to the Arduino. The Arduino processes it, then sends a signal through wires to servo motors. The sensor is an input, and the motors are outputs—also called effectors.

Simon
Exactly. You can see the Arduino processing a signal, and then a motor responds by turning. That electronic system becomes much more interesting when you attach it to moving mechanical parts. Put several servos, a battery pack, and an Arduino together, and you could make a desktop turret that aims in different directions.

Anna
The important point is that the same building blocks can support very different projects. And you don't have to be an experienced programmer to start. There are many examples of code online that you can copy and adapt, and AI chatbots can help explain, write, or debug code.

Simon
That makes this approachable even if you've never taken a coding class. A lot of the challenge is finding a project, connecting the right parts, and making small changes to an existing example. Once you recognize the input, brain, and output, something that first seems like magic becomes easier to understand.

Anna
Before we go further, what is electricity in this simplified picture? It's moving electrons. If the electrons are sitting still, they aren't creating an electric current; when they move, we have electricity. The amount and movement of electrons relate to how much electrical activity is available to power a device.

Simon
You can think of an electrical circuit as a track for electrons, like a Hot Wheels track. When the circuit is complete, electrons can travel around it. In the example of a battery and light bulb, they move from the battery, through the wire and bulb, and back to the battery.

Anna
As current passes through the bulb's resistive part, the bulb gives off light. The battery supplies the energy that keeps the electrons moving, and eventually it runs down. The key idea for building is that the path has to be complete for the circuit to work.

Simon
A switch is like a gate in that track. When the switch is off, the path is broken, so electrons can't move around the circuit and the bulb stays off. Flip the switch on, complete the path, and the bulb lights again.

Anna
Now let's put an Arduino into that picture with a nightlight. A light sensor measures how bright the surroundings are. The Arduino repeatedly checks that input, and when it detects darkness, it tells an LED to get brighter.

Simon
So there are two jobs happening: one part of the circuit lets the Arduino check the sensor, and another part lets it control the light. The Arduino makes the system smarter by using the sensor's information to decide what the output should do. That's the same basic idea behind an automatic nightlight.

Anna
Let's summarize the four parts you'll find in an Arduino build—or in many electronic devices. First are inputs, such as sensors. Second is the brain that processes information. Third are outputs that affect the world, and fourth are the wires that connect everything.

Simon
The human analogy helps here too. Sensors are like eyes and ears, the Arduino is like a brain, outputs are like muscles, and wires are like a nervous system carrying information between them. That framework works for projects ranging from a robot to a washing machine or calculator.

Anna
There are lots of possible inputs. A light sensor detects brightness, a button detects a press, and a microphone picks up sound. A proximity sensor detects whether something is near or far; a knob and joystick provide controls, and a soil-moisture sensor measures how wet the soil is.

Simon
Outputs can be just as varied. A servo motor can move to a position, a small DC motor can spin something such as a fan, LEDs can light up, and a buzzer or speaker can make sound. Kits sold online often bundle a range of sensors and outputs so you can try different combinations.

Anna
Combining them is where project ideas take off. Put a soil-moisture sensor in a plant, for instance, and have it light an LED when the soil is dry—or send a message that the plant needs water. The sensor notices a condition, the Arduino interprets it, and the output alerts you.

Simon
Or use a microphone and a servo to create a locked box that opens only after it hears a secret knock with the right pattern and spacing. A knob could control a fan's speed, or a thermometer could tell the fan when to turn on. A button connected to a jar lid could trigger an alarm if the lid is lifted.

Anna
You can also make a playful device with a proximity sensor, lights, a buzzer, and a secret button. The hardware can be simple; the fun comes from the story you build around what it does. Arduino projects can solve a practical problem, entertain friends and family, or do both.

Simon
Let's talk about changing the instructions—the brain's 'rules'—for a project. The word Arduino can mean a specific brand of microcontroller board, while a microcontroller is the broader category. It's a little like saying Tesla is one car brand, while 'car' describes a bigger category.

Anna
The Arduino Uno is a common board, and its header pins make it convenient to plug wires directly into it. Other projects may use a different microcontroller. The important thing is that the board runs instructions that tell it what to do with its inputs and how to control its outputs.

Simon
For a typical Arduino board, you can download the free Arduino IDE from arduino.cc. Connect the board to your computer, select the correct port, and then you can send a program to it. A program for an Arduino is often called a sketch, and its code is a slightly modified version of C++.

Anna
A sketch has two especially important sections: setup and loop. Setup runs once, when the board starts, and establishes things like which pins the project will use. Then loop runs over and over, checking inputs and responding as needed.

Simon
In a nightlight sketch, setup happens when you turn the device on. After that, loop repeatedly asks whether it's dark. If it is, the code tells the LED to turn on; the board keeps checking, and when the surroundings get bright, the code can turn the light off.

Anna
A simple first test is the Blink example, available in the IDE under File, Examples, and Basics. The sketch includes setup information and instructions in loop that turn the board's built-in LED on and off. Text shown as a comment—often in gray and between special markers—is for people reading the code; the board ignores it.

Simon
Once you've selected the board and port, you can upload the sketch using the upload button. That replaces the instructions the board is running—it's like swapping out its brain. Then you can edit the delay values to change how long the LED stays on and off.

Anna
Those delay values are measured in milliseconds, so 1,000 means one second. In the example, changing one delay to 3,000 and another to 4,000 makes the LED stay off for three seconds and on for four. Uploading the edited sketch lets you see the change immediately.

Simon
That small experiment is a satisfying first step: you changed a program and made hardware behave differently. There are also many online examples that include both the code and a schematic—a diagram showing how to connect the inputs and outputs.

Anna
For example, a 'knob' project can use a knob to control a servo's position. Turn the knob and the motor moves. The wiring diagram shows where each wire goes, while the code tells the board what to do with the knob's value.

Simon
You can then decide what story or useful purpose to give that setup. The servo might wave a small arm, move a switch, or do something else in your build. The hardware and code are a starting point; the creative application is up to you.

Anna
A solderless breadboard makes trying out those connections easier. Instead of soldering wires together, you plug them into the board. Metal connections underneath join certain holes, so parts plugged into the same connected row or strip are electrically connected.

Simon
That makes a breadboard useful for prototyping and testing. When you have a design you like and want a cleaner, repeatable version, you can use a custom printed circuit board, or PCB. A PCB packages the connections and components into one board.

Anna
That's the kind of board you'll find inside many everyday electronics, such as calculators, microwaves, washing machines, and cars. In a sense, it brings the separate components and connections of a breadboard-and-microcontroller setup together in a form designed for a particular device.

Simon
If you find code online, AI tools can help you understand it, fix a compile problem, or make it simpler. You can also describe an idea and ask for help building the code, or ask why two pieces of copied code aren't working together. They're useful as tutors while you experiment.

Anna
The same idea applies to educational robot kits such as HackPack: the robot's microcontroller is its brain, and changing the code can change what the robot does. Its browser-based coding console offers different levels of access.

Simon
At level one, the code is locked down, and you can choose from verified hacks. At level two, you can change selected variables, such as how quickly a barrel turns or how many numbers appear in a passcode. At level three, you can change everything.

Anna
And that's the big picture of an Arduino build: power provides energy, inputs gather information, a microcontroller processes it, and outputs act on the world, all connected into circuits. You can start with an existing sketch and wiring diagram, make a small change, and build toward more original projects.

Simon
You don't need to begin as a coding expert. Start by recognizing the parts, try a simple example such as Blink, and keep experimenting with how different inputs and outputs can work together. Add a useful or funny idea around the hardware, and a small electronics project can become something genuinely memorable.

Ask anything
We've read this whole study set, so questions about it get the best answers.