Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions 3D/hardware_guide/Components/Buttons/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

# Buttons and Switches

A button or switch is a simple component that controls the flow of current in a circuit by opening or closing the connection.

## How They Work

- **Normally Open (NO):** This is the most common type of push button. The circuit is disconnected (open) by default. When you press the button, it completes the circuit (closes it), allowing current to flow.
- **Normally Closed (NC):** The circuit is connected (closed) by default. When you press the button, it breaks the circuit (opens it), stopping the current flow.

## The Problem of Floating Pins

When you connect a button to a microcontroller's input pin, you need to know its state: is it pressed or not pressed? This corresponds to a digital HIGH or LOW.

If you just connect a button to an input pin and VCC (e.g., 5V), the pin will be HIGH when pressed. But what about when it's not pressed? The input pin is not connected to anything, which is called a **floating state**. In this state, the pin can randomly read HIGH or LOW due to electrical noise, leading to unreliable behavior.

To fix this, we must use **pull-up** or **pull-down** resistors.

## Pull-up and Pull-down Resistors

These resistors ensure the input pin is always in a known, stable state.

### 1. Pull-down Resistor

- **How it works:** A resistor (typically 10kΩ) is connected from the input pin to Ground (GND).
- **Behavior:**
- When the button is **not pressed**, the resistor "pulls" the input pin's voltage down to GND. The pin reads **LOW**.
- When the button **is pressed**, it connects the input pin directly to VCC (5V), overriding the resistor. The pin reads **HIGH**.

![Pull-down Resistor Diagram](https://www.upesy.com/wp-content/uploads/2021/09/pull-down-resistor-schematic.png)

### 2. Pull-up Resistor

- **How it works:** A resistor (typically 10kΩ) is connected from the input pin to VCC (5V).
- **Behavior:**
- When the button is **not pressed**, the resistor "pulls" the input pin's voltage up to VCC. The pin reads **HIGH**.
- When the button **is pressed**, it connects the input pin directly to GND, overriding the resistor. The pin reads **LOW**.

![Pull-up Resistor Diagram](https://www.upesy.com/wp-content/uploads/2021/09/pull-up-resistor-schematic.png)

**Note:** The logic is inverted with a pull-up resistor (pressed = LOW).

## Internal Pull-ups

Most microcontrollers (including Arduino and Raspberry Pi) have **internal pull-up resistors** that you can enable in your code. This is extremely convenient as it means you don't need to add an external resistor to your circuit.

**Arduino Example:**
```cpp
// Enables the internal pull-up resistor on pin 2
pinMode(2, INPUT_PULLUP);
```

When using `INPUT_PULLUP`, you simply wire the button between the input pin and GND. The pin will be HIGH when not pressed and LOW when pressed.

## Debouncing

When you press a mechanical button, the metal contacts can bounce against each other for a few milliseconds before settling. A microcontroller is fast enough to read these bounces as multiple, separate presses.

**Debouncing** is the technique used to handle this, ensuring only one press is registered.

- **Software Debouncing:** The most common method. After detecting a press, you can add a small delay (e.g., 50ms) in your code and then read the button state again to make sure it's still pressed.
- **Hardware Debouncing:** Can be done by adding a small capacitor to the circuit.
1 change: 1 addition & 0 deletions 3D/hardware_guide/Components/Buttons/tutorials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.youtube.com/watch?v=RiYnucfy_rs
62 changes: 62 additions & 0 deletions 3D/hardware_guide/Components/LEDs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

# LEDs (Light Emitting Diodes)

An LED is a semiconductor light source that emits light when current flows through it. They are one of the most common components in electronics, used for everything from simple indicators to lighting.

## How an LED Works

- **Diode:** An LED is a type of diode, which means it only allows current to flow in one direction.
- **Polarity:** Because it's a diode, an LED has polarity. It has a positive lead (**anode**) and a negative lead (**cathode**).
- **Anode (Positive):** This is typically the longer leg.
- **Cathode (Negative):** This is typically the shorter leg. The flat edge on the side of the LED also indicates the cathode.

If you connect an LED backwards, it will not light up and can be damaged.

![LED Polarity Diagram](https://www.build-electronic-circuits.com/wp-content/uploads/2013/08/led-polarity.png)

## Why You MUST Use a Resistor with an LED

An LED has very little internal resistance. If you connect it directly to a voltage source (like a 5V pin on an Arduino), a very large amount of current will flow through it, instantly destroying the LED. This is called thermal runaway.

To prevent this, you **must** always use a **current-limiting resistor** in series with the LED.

### How to Calculate the Resistor Value

You can use Ohm's Law (V = I * R) to find the right resistor value.

**R = (Vs - Vf) / I**

- **R:** The resistance you need (in Ohms).
- **Vs:** The voltage of your power source (e.g., 5V for an Arduino).
- **Vf:** The LED's forward voltage. This is the amount of voltage the LED "drops" when it's on. It varies by color (see chart below).
- **I:** The desired current for the LED (in Amperes). A safe and common value for most 5mm LEDs is 20mA, which is **0.020A**.

### Typical LED Forward Voltages (Vf)

| Color | Forward Voltage (approx.) |
| :--- | :---: |
| Red | 1.8V - 2.2V |
| Green | 2.0V - 2.4V |
| Blue | 3.0V - 3.4V |
| White | 3.0V - 3.4V |
| Yellow | 2.0V - 2.2V |

**Example Calculation (Red LED with 5V source):**

- Vs = 5V
- Vf = 2.0V (average for a red LED)
- I = 0.020A (20mA)

R = (5V - 2.0V) / 0.020A

R = 3V / 0.020A

R = 150 Ω

The closest standard resistor value is 220Ω, which is a perfect choice as it provides a little extra protection.

## Types of LEDs

- **Through-Hole:** The standard LEDs with two legs, common in breadboarding.
- **Surface Mount (SMD):** Tiny LEDs that are soldered directly onto a circuit board.
- **RGB LEDs:** These combine three separate LEDs (Red, Green, and Blue) in a single package. By controlling the brightness of each color, you can create any color in the spectrum.
1 change: 1 addition & 0 deletions 3D/hardware_guide/Components/LEDs/tutorials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.youtube.com/watch?v=RiYnucfy_rs
40 changes: 40 additions & 0 deletions 3D/hardware_guide/Components/Motors/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

# Motors in Electronics

Motors are essential components in robotics and many electronic projects. They convert electrical energy into mechanical motion.

## Types of Motors

There are many different types of motors, each with its own characteristics and best use cases.

### 1. DC Motors

- **What they are:** The most common type of motor. They have two terminals, and when you apply a DC voltage, the shaft spins.
- **Control:** The speed is controlled by varying the voltage. The direction is changed by reversing the polarity of the voltage.
- **Use Cases:** Fans, toys, robot wheels.
- **Note:** They are not precise. You can control the speed and direction, but not the exact position of the shaft.

### 2. Servo Motors

- **What they are:** A DC motor combined with a position feedback sensor (usually a potentiometer) and a small controller circuit. This allows for precise control of the shaft's angular position.
- **Control:** They are controlled by sending a series of pulses (Pulse Width Modulation, or PWM). The width of the pulse determines the angle of the shaft (e.g., 1ms pulse for 0 degrees, 2ms for 180 degrees).
- **Use Cases:** Robotic arms, steering systems in RC cars, pan-tilt camera mounts.

### 3. Stepper Motors

- **What they are:** These motors rotate in discrete steps. The shaft moves a specific number of degrees per step (e.g., 1.8 degrees per step).
- **Control:** They are controlled by energizing internal coils in a specific sequence. This requires a dedicated stepper motor driver (like an A4988 or DRV8825).
- **Use Cases:** 3D printers, CNC machines, scanners, and any application requiring precise, repeatable positioning.

### 4. Brushless Motors

- **What they are:** A more advanced type of motor that uses electronic commutation instead of mechanical brushes. This makes them more efficient, durable, and quieter.
- **Control:** Requires a dedicated Electronic Speed Controller (ESC) to operate.
- **Use Cases:** Drones, electric vehicles, high-performance RC cars.

## Motor Drivers

A microcontroller (like an Arduino or Raspberry Pi) cannot power a motor directly because motors require more current than the microcontroller's GPIO pins can supply. You **must** use a motor driver.

- **What it does:** A motor driver is an intermediate circuit that takes a low-current control signal from the microcontroller and delivers a higher-current signal to the motor.
- **Common Examples:** L298N (for DC and stepper motors), A4988 (for stepper motors), DRV8825 (for stepper motors), ESCs (for brushless motors).
1 change: 1 addition & 0 deletions 3D/hardware_guide/Components/Motors/tutorials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.youtube.com/watch?v=RiYnucfy_rs
67 changes: 67 additions & 0 deletions 3D/hardware_guide/Components/Potentiometers/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

# Potentiometers

A potentiometer is a three-terminal variable resistor. It acts as a voltage divider and is commonly used to provide a variable analog signal to a microcontroller, for example, to control volume, brightness, or the position of a servo motor.

## How a Potentiometer Works

Inside a potentiometer, there is a resistive track and a sliding contact, or **wiper**. As you turn the knob, the wiper moves along the track.

It has three pins:

1. **Pin 1 (CCW - Counter-Clockwise):** One end of the resistive track.
2. **Pin 2 (Wiper):** The middle pin, connected to the sliding contact.
3. **Pin 3 (CW - Clockwise):** The other end of the resistive track.

![Potentiometer Diagram](https://www.build-electronic-circuits.com/wp-content/uploads/2013/09/potentiometer-schematic-symbol-and-breadboard-layout.png)

## Using a Potentiometer as a Voltage Divider

This is the most common way to use a potentiometer with a microcontroller.

1. **Connect the outer pins to power:**
- Connect Pin 1 to Ground (GND).
- Connect Pin 3 to your voltage source (e.g., 5V or 3.3V).

2. **Connect the center pin to an analog input:**
- Connect Pin 2 (the wiper) to an analog input pin on your microcontroller (e.g., A0 on an Arduino).

### What Happens?

- When the knob is turned all the way to the GND side (Pin 1), the wiper is close to GND, and the voltage on the analog pin will be close to 0V. The microcontroller will read a value close to 0.
- When the knob is turned all the way to the VCC side (Pin 3), the wiper is close to VCC, and the voltage on the analog pin will be close to 5V. The microcontroller will read its maximum analog value (e.g., 1023 for a 10-bit ADC on an Arduino).
- At any position in between, the wiper picks up a voltage that is proportional to its position along the resistive track, providing a smooth range of analog values.

## Reading the Value

You use the `analogRead()` function on a microcontroller to read the voltage from the wiper pin.

**Arduino Example:**

```cpp
// Connect the potentiometer's center pin to A0
int potPin = A0;

void setup() {
Serial.begin(9600);
}

void loop() {
// Read the analog value (from 0 to 1023)
int potValue = analogRead(potPin);

// Print the value to the Serial Monitor
Serial.println(potValue);

delay(100); // Wait a bit before the next reading
}
```

## Types of Potentiometers

- **Linear Taper:** The resistance changes linearly as you turn the knob. If you turn the knob 50% of the way, the resistance is 50% of the total. These are used for most sensor control applications.
- **Logarithmic (Audio) Taper:** The resistance changes logarithmically. This is used for audio applications (like volume controls) because human hearing is also logarithmic.

## Using a Potentiometer as a Rheostat

A potentiometer can also be used as a simple two-terminal variable resistor (called a rheostat). You do this by using only the wiper (Pin 2) and one of the outer pins (Pin 1 or 3). In this configuration, it can be used to control the current in a circuit, for example, to vary the brightness of an LED.
1 change: 1 addition & 0 deletions 3D/hardware_guide/Components/Potentiometers/tutorials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.youtube.com/watch?v=RiYnucfy_rs
60 changes: 60 additions & 0 deletions 3D/hardware_guide/Components/Resistors/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

# Resistors

A resistor is a fundamental passive electronic component that creates resistance in the flow of electric current. Its purpose is to limit current, divide voltage, and in some cases, generate heat.

## What Does a Resistor Do?

Imagine electricity flowing through a wire is like water flowing through a pipe. A resistor is like a narrow section of that pipe, which restricts the flow.

Key functions:

- **Current Limiting:** This is the most common use. For example, an LED (Light Emitting Diode) can be destroyed if too much current flows through it. A resistor is placed in series with the LED to limit the current to a safe level.
- **Voltage Division:** Two or more resistors can be used to create a voltage divider, which produces a lower, stable voltage from a higher voltage source. This is very useful for providing a specific reference voltage to a component or reading sensors.
- **Pull-up and Pull-down:** In digital logic, resistors are used to ensure that a pin is in a known state (either HIGH or LOW) when it would otherwise be "floating," such as when a button is not being pressed.

## Units of Resistance

The unit of electrical resistance is the **Ohm (Ω)**.

You will commonly see values in:

- **Ohms (Ω)**
- **Kilo-ohms (kΩ):** 1 kΩ = 1,000 Ω
- **Mega-ohms (MΩ):** 1 MΩ = 1,000,000 Ω

## How to Read a Resistor (Color Codes)

Through-hole resistors are too small to have their value printed on them. Instead, they use a system of colored bands.

![Resistor Color Code Chart](https://www.build-electronic-circuits.com/wp-content/uploads/2011/11/4-band-resistor-color-code-chart.png)

### 4-Band Resistors:

- **Band 1:** First digit of the resistance value.
- **Band 2:** Second digit of the resistance value.
- **Band 3:** Multiplier (the number of zeros to add).
- **Band 4:** Tolerance (how accurate the resistor's value is). Gold is ±5%, Silver is ±10%.

**Example:**

A resistor has the colors: **Brown, Black, Red, Gold**

1. **Brown:** 1
2. **Black:** 0
3. **Red:** x 100 (or add two zeros)
4. **Gold:** ±5% tolerance

So, the value is **10** followed by **two zeros** = **1000 Ω** or **1 kΩ**, with a ±5% tolerance.

## Ohm's Law

The relationship between voltage (V), current (I), and resistance (R) is defined by Ohm's Law:

**V = I * R**

- **V:** Voltage (in Volts)
- **I:** Current (in Amperes)
- **R:** Resistance (in Ohms)

This is the most important formula in basic electronics. You can use it to calculate the correct resistor value needed for a specific application, like protecting an LED.
1 change: 1 addition & 0 deletions 3D/hardware_guide/Components/Resistors/tutorials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.youtube.com/watch?v=RiYnucfy_rs
1 change: 1 addition & 0 deletions 3D/hardware_guide/Components/Sensors/tutorials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.youtube.com/watch?v=RiYnucfy_rs
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

# Arduino Uno Basic Examples

Here are some basic examples to get you started with the Arduino Uno.

## 1. Blink

This is the "Hello, World!" of microcontrollers. It blinks the built-in LED on the Arduino board.

```cpp
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
```

## 2. Fading an LED

This example shows how to fade an LED on and off using one of the PWM pins.

```cpp
int led = 9;
int brightness = 0;
int fadeAmount = 5;

void setup() {
pinMode(led, OUTPUT);
}

void loop() {
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}
```

## 3. Reading a Sensor

This example shows how to read the value from an analog sensor, such as a potentiometer or a photoresistor.

```cpp
void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1);
}
```

## 4. Button

This example shows how to read a pushbutton press.

```cpp
const int buttonPin = 2;
const int ledPin = 13;

int buttonState = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
```
Loading