Skip to content

Added Basic Arduino Components Page. #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions _data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ wiki:
url: /wiki/computing/setup-gpus-for-computer-vision/
- title: Ubuntu Dual Boot and Troubleshooting Guide
url: /wiki/computing/troubleshooting-ubuntu-dual-boot/
- title: Basic Arduino Components
url: /wiki/basic-arduino-components
- title: Fabrication
url: /wiki/fabrication/
children:
Expand Down
Binary file added wiki/computing/assets/buzzer_wiring.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wiki/computing/assets/led_wiring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wiki/computing/assets/potentiometer_wiring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wiki/computing/assets/push_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wiki/computing/assets/servo_wiring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wiki/computing/assets/stepper_wiring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
238 changes: 238 additions & 0 deletions wiki/computing/basic-arduino-componets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
---
date: {}
title: Basic Arduino Components
---

Arduino is a widely used platform in robotics and electronics due to its ease of use, affordability, and the wide variety of compatible components. Whether you're building a simple circuit or a complex robot, understanding how to use basic components like LEDs, push buttons, potentiometers, buzzers, servos, and stepper motors is essential. This guide will cover these fundamental Arduino components, explain their functionality, and provide simple examples to get you started to where you can incorporate them in to future robotic projects.

## LEDs

An LED (Light Emitting Diode) is one of the simplest and most commonly used components in Arduino projects. LEDs provide visual feedback and are often used as indicators for status, power, or signals. LEDs work by emitting light when an electric current flows through them in the correct direction. They require a resistor in series to prevent excessive current, which could damage the LED. To wire an LED to an Arduino, connect the long leg (anode) of the LED to a digital pin on the Arduino. The short leg (cathode) should be connected to the ground through a resistor, typically 220 ohms, to limit the current.

A simple wiring setup for an LED can be seen below along with a code snippet. The code will cause the LED to blink on and off.

![LED Wiring Diagram](assets/led_wiring.png)

```
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

```

https://docs.arduino.cc/built-in-examples/basics/Blink/: This official Arduino tutorial provides a step-by-step guide to creating a simple blinking LED circuit. It covers the basic wiring and programming needed to control an LED, making it an excellent resource for beginners starting with Arduino. It provides a more thorough discussion of this wiki on using LEDs with Arduino.

## Push Button

A push button is a simple input device that completes an electrical circuit when pressed. It is commonly used to trigger events or control devices in Arduino projects. When the button is pressed, it allows current to flow, sending a signal to the Arduino. When released, the circuit is open, and no signal is sent. Pull-down or pull-up resistors are often used to ensure the circuit has a defined state (HIGH or LOW) when the button is not pressed. To connect a push button to an Arduino, attach one leg of the button to a digital input pin and the other to the ground. Additionally, use a pull-up resistor or enable the Arduino's internal pull-up resistor to stabilize the input state.

A simple wiring setup for a push button can be seen below along with a code snippet. The code will cause the serial monitor to print "Button Pressed" when the button is pressed, and print "Not Pressed" when the button is not pressed.

![Push Button Diagram](assets/push_button.png)


```
const int buttonPin = 2; // the number of the pushbutton pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600); // Start serial communication
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.println("Button Pressed):
} else {
Serial.println("Not Pressed):
}
}
```

Note: When a push button is pressed, it may generate multiple rapid on/off signals due to the mechanical nature of the button. This is known as "bouncing" and can cause unexpected behavior in your circuit. To address this, you can use a small delay in your code or implement software debouncing techniques. You can read more about debouncing at this link: https://docs.arduino.cc/built-in-examples/digital/Debounce/

https://docs.arduino.cc/built-in-examples/digital/Button/ : This link provides a more thorough overview of pushbuttons in Arduino and can be used to help clarify information about Arduino pushbuttons. The link also discusses wiring a pushbutton and reading its related signals at a more detailed level.

## Potentiometers

A potentiometer is a variable resistor that allows you to adjust resistance by turning a knob or sliding a lever. It is commonly used as an input device for controlling brightness, volume, or speed in Arduino projects. A potentiometer has three terminals: two outer terminals connected to a fixed resistor and one middle terminal (the wiper) that moves along the resistor as you adjust the knob. By reading the voltage at the wiper, the Arduino can determine the position of the potentiometer.To wire a potentiometer, connect one outer terminal to 5V on the Arduino and the other outer terminal to GND. Connect the middle terminal (wiper) to an analog input pin, such as A0. This setup allows the Arduino to read a voltage that corresponds to the potentiometer's position.

An image of a simple wiring for a potentiometer can be seen below along with a code snippet. To read a potentiometer you will need to use an analog pin and the analogRead() Arduino function. The code will print the potentiometer's analog value.


![Potentiometer Wiring Diagram](assets/potentiometer_wiring.png)


```
const int potPin = A0; // Pin connected to the potentiometer

void setup() {
Serial.begin(9600); // Start serial communication
}

void loop() {
int potValue = analogRead(potPin); // Read potentiometer value (0-1023)
Serial.println(potValue); // Print value to serial monitor
delay(100); // Delay for readability
}
```


https://docs.arduino.cc/learn/electronics/potentiometer-basics/ : This resource provies a more detaild discussion of potentiometers to clarify any unaddressed points in this article.

https://docs.arduino.cc/built-in-examples/basics/AnalogReadSerial/ : This link details the analogRead() function in Arduino. This is a very important functin that is required for the analog Arduion pins. It is useful to understand for all Arduino analog inputs.

https://docs.arduino.cc/language-reference/en/functions/math/map/ : A useful function when dealing with analog signals is the map() function. This link details the map function. The function can be used in many ways to connect the inputs/ouptus of different signals to one another, and it is a necessary function to understand when starting Arduino projects.


## Buzzers

A buzzer is a simple electronic component that generates sound when powered, often used in Arduino projects for audible feedback, alarms, or notifications. There are two main types of buzzers: active and passive. An active buzzer generates sound when supplied with power and does not require any signal control, making it straightforward to use. A passive buzzer, on the other hand, requires a signal (such as a PWM signal) to produce sound, allowing for the creation of different tones.

Buzzers work by converting electrical energy into sound through the vibration of a piezoelectric diaphragm. The frequency of the signal determines the tone of the sound produced. To wire a buzzer, connect the positive terminal to a digital output pin on the Arduino and the negative terminal to the ground (GND). For an active buzzer, you can simply turn it on and off using digital signals. For example, you can alternate between HIGH and LOW states to create a beep. A passive buzzer can generate tones of varying frequencies using the Arduino's tone() function.

Buzzers are versatile components with applications in security systems, timers, notification systems, and user interfaces where audible feedback is needed. They provide an effective way to communicate events, warnings, or statuses in a project.

The wiring for a simple piezo buzzer can be seen below along with a code snippet. The code will cause the buzzer to continuously start and stop buzzing.

![Buzzer Wiring Diagram](assets/buzzer_wiring.jpg)


```
const int buzzer = 9; //buzzer to arduino pin 9

void setup(){
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
}

void loop(){
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
```

https://sensorkit.arduino.cc/sensorkit/module/lessons/lesson/04-the-buzzer : This resource is very useful to understand the fundametals of buzzers in Arduino. It explains how buzzers work, different types of buzzers and potential issues.

https://www.ardumotive.com/how-to-use-a-buzzer-en.html : This link is very effective in outlining how to implement a buzzer. It provides more information than in this section and also includes a video that better details Arduino buzzer implementation.

## Servo Motors

A servo motor is a rotary actuator that allows precise control of angular position, speed, and torque. It is widely used in robotics and Arduino projects due to its compact size and ability to move to a specific position within a range. Servo motors are ideal for tasks that require controlled movements, such as steering mechanisms, robotic arms, or pan-tilt camera systems.

Servo motors typically have three wires: a power wire (usually red), a ground wire (usually black or brown), and a signal wire (often yellow, orange, or white). The power and ground wires connect to the Arduino’s 5V and GND pins, respectively, while the signal wire connects to a digital output pin. The signal wire receives pulse-width modulation (PWM) signals from the Arduino, which dictate the servo's angle of rotation. Most standard servo motors have a range of motion from 0 to 180 degrees.

Using the Arduino Servo library simplifies the control of servo motors. For example, you can set the angle of the motor by sending a specific value through the write() function.

A simple wiring of a servo motor setup can be seen below. A code snippet is also below, and this snippet causes the servo motor to rotate back and forth.

![Servo Wiring Diagram](assets/servo_wiring.png)


```
#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
```

https://docs.arduino.cc/tutorials/generic/basic-servo-control/ : This link provides a very basic understanding of servo control in case you think more information is required.

https://docs.arduino.cc/learn/electronics/servo-motors/ : This is a very useful resource that expands on the basics of servo motors. This link shows how a potentiometer can be connected to a servo motor to control the rotor's position. This would be a very useful project to implement after learning about potentiometers and servos.

https://docs.arduino.cc/libraries/servo/ : This link discusses the servo library. This is a fundamental library used when using servo motors in Arduino.

## Stepper Motors

A stepper motor is a type of DC motor that divides a full rotation into a series of discrete steps, making it ideal for applications requiring precise control of angular or linear position, speed, and acceleration. Unlike servo motors, stepper motors are not limited to a specific range of motion and can rotate continuously in precise increments. This makes them widely used in CNC machines, 3D printers, robotic arms, and other Arduino-based projects.

Stepper motors have multiple coils organized in phases, and the motor is driven by energizing these coils in a specific sequence. Most stepper motors have four or more wires that are connected to a motor driver, such as the A4988 or ULN2003, which interfaces with the Arduino. The motor driver controls the sequence of energizing the coils based on signals sent from the Arduino, allowing for smooth and precise movement.

To use a stepper motor with an Arduino, the Stepper library simplifies the process. Stepper motors vary, so their wiring can vary based off the motor driver they require.The 28BYJ-48 4-Phase Stepper Motor is the simplest stepper motor that comes with Arduino beginner kits, and its wiring is shown in the diagram belwo along with a code snippet that rotates the motor clockwise and counter-clockwise at varying speeds.

![Stepper Motor Wiring Diagram](assets/stepper_wiring.png)


```
`//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 2038;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}

void loop() {
// Rotate CW slowly at 5 RPM
myStepper.setSpeed(5);
myStepper.step(stepsPerRevolution);
delay(1000);

// Rotate CCW quickly at 10 RPM
myStepper.setSpeed(10);
myStepper.step(-stepsPerRevolution);
delay(1000);
}`
```

https://docs.arduino.cc/learn/electronics/stepper-motors/ : This link is very useful for learning about stepper motor implementation with Arduino and greatly expands upon this section. This link also provides code for different ways to control a stepper motor with Arduino.

https://howtomechatronics.com/tutorials/arduino/stepper-motors-and-arduino-the-ultimate-guide/ : This is an amazing resource to understand how stepper motors work physically. This link is also extrmely useful at showing some common stepper motors that can be used with Arduino.

https://docs.arduino.cc/libraries/stepper/ : This is a link to the stepper motor library. It is a fundamental library for stepper motor control.


## Summary
This page provides an introduction to essential Arduino components, including LEDs, push buttons, potentiometers, buzzers, servo motors, and stepper motors. Each section explains how the component works, how to wire it to an Arduino, and includes example code to demonstrate its use. These components form the foundation of many robotics and electronics projects, offering a range of functionalities from input and output to precise motor control. Links to detailed tutorials and resources are provided throughout the guide to expand on each topic, making this a comprehensive starting point for anyone working with Arduino.

## See Also:
- https://roboticsknowledgebase.com/wiki/computing/arduino/

## Further Reading
- I strongly recommend the book in the references. It provided the inspiration for this page.

## References
Arduino Project Handbook by Mark Geddes https://www.amazon.com/Arduino-Project-Handbook-Practical-Projects/dp/1593276907