Arduino Microcontroller Circuitry and FreeCAD 3D Parametric Modeling Study Notes

Single LED Blinking Circuit Architecture


Arduino single LED blinking circuit diagram
  • Circuit Components and Pin Identification

    • A – Negative Wire: Carries electric power back to the power source (the Arduino board).

    • B – LED (Light Emitting Diode): A specialized type of diode that emits light when electric current flows through it.

    • C – Resistor: Controls and limits the amount of current flowing through a circuit component. Without a resistor, excessive current could flow and burn out components such as LEDs, sensors, or the Arduino board itself.

    • D – Positive Wire: Carries current and signals from the power source (Arduino board) to the circuit components (LED).

    • E – Pin 5: Configured as an OUTPUT signal pin.

    • F – Arduino Board: The main controller of the circuit.

    • G – GND Pin: Ground reference point in an electrical circuit from which voltages are measured, serving as a common return path for electric current.

  • Arduino C++ Source Code Breakdown

    • int ledPin = 5; defines digital pin 5 as the designated LED output pin.

    • void setup() runs once upon power-up or reset; configures ledPin as an output via pinMode(ledPin, OUTPUT);.

    • void loop() executes repeatedly in an infinite sequence after initialization.

    • digitalWrite(ledPin, HIGH); sends 5 V5\,\text{V} to the pin, turning the LED ON.

    • delay(5000); pauses code execution for 5000 ms5000\,\text{ms} (5 seconds).

    • digitalWrite(ledPin, LOW); sends 0 V0\,\text{V} to the pin, turning the LED OFF.

    • delay(5000); pauses code execution for another 5000 ms5000\,\text{ms}.

  • Code Analysis & Behavioral Principles

    • Role of Pin Definition (int ledPin = 5;): Assigns pin number 5 to the identifier ledPin for system-wide reference.

    • setup() vs. loop() Operational Difference: setup() runs once to initialize hardware settings and pin modes. loop() executes continuously to control interactive and timing behaviors.

    • Role of HIGH Signal State: Outputs a positive voltage (5 V5\,\text{V}) to drive power to the connected component.

    • Role of LOW Signal State: Drops the output voltage to 0 V0\,\text{V} (ground), de-energizing the component.

    • Line 12 Execution (digitalWrite(ledPin, LOW);): Deactivates the LED following its active state duration.

Dual LED Push Button Control System


Arduino dual LED circuit with push buttons
  • Circuit Hardware Configurations

    • Green LED: Connected to digital pin 5.

    • Red LED: Connected to digital pin 6.

    • Green Push Button: Connected to digital pin 2.

    • Red Push Button: Connected to digital pin 3.

  • Internal Pull-Up Resistors

    • Using INPUT_PULLUP mode in pinMode() engages the microcontroller's built-in internal pull-up resistor.

    • When the push button is unpressed, the input pin reads HIGH (5 V5\,\text{V}).

    • When the push button is pressed, the circuit connects to ground and reads LOW (0 V0\,\text{V}).

  • Dual LED Control Program Code

    • int greenLED = 5; and int redLED = 6; define the output LED pins.

    • int greenButton = 2; and int redButton = 3; define the button input pins.

    • pinMode(greenButton, INPUT_PULLUP); enables internal pull-up configuration for digital pin 2.

    • pinMode(redButton, INPUT_PULLUP); enables internal pull-up configuration for digital pin 3.

    • digitalRead(greenButton); reads the current logic level of pin 2.

    • If greenState == LOW, digitalWrite(greenLED, HIGH); turns on the Green LED; otherwise digitalWrite(greenLED, LOW); turns it off.

    • If redState == LOW, digitalWrite(redLED, HIGH); turns on the Red LED; otherwise digitalWrite(redLED, LOW); turns it off.

Potentiometer-Controlled Servo Motor System


Arduino single servo motor controlled by potentiometer
  • Circuit Component Identifiers

    • A – Signal Output Pin: Digital pin 9, which transmits pulse-width control signals to the servo motor.

    • B – Arduino Board: Main controller that processes incoming potentiometer signal values and computes corresponding position output signals.

    • C – Potentiometer: Variable resistor functioning as a manual position controller or angle input device for the servo.

    • D – Servo Motor: Specialized motor capable of rotating to precise angular positions and maintaining that target position.

    • E – Power Supply Wire: Delivers operating power from the Arduino board to the servo motor.

    • F – Ground (GND) Wire: Completes the electrical circuit back to the Arduino board.

    • G – Potentiometer Signal Wire: Transmits raw variable analog voltage signals from the potentiometer to analog pin A0.

  • Potentiometer Servo Program Breakdown

    • #include <Servo.h> imports the default Arduino Servo motor library.

    • Servo myServo; instantiates a servo control object named myServo.

    • int potPin = A0; designates analog pin A0 for reading potentiometer input values.

    • myServo.attach(9); assigns digital pin 9 as the output channel for servo pulse generation.

    • val = analogRead(potPin); reads the raw 10-bit analog voltage input value ranging from 0 to 10230\text{ to }1023

    • val = map(val, 0, 1023, 0, 180); converts the analog range 0 to 10230\text{ to }1023 into an angular rotation range of 0∘ to 180∘0^\circ\text{ to }180^\circ

    • myServo.write(val); commands the servo motor shaft to rotate to the mapped angle value val.

    • delay(15); adds a delay of 15 ms15\,\text{ms} to ensure continuous, smooth movement without physical motor jitter.

  • Code Functionality & Analysis

    • Library Inclusion (#include <Servo.h>): Loads predefined hardware driver functions needed to manage servo control timing.

    • Object Instantiation (Servo myServo;): Prepares an operational object instance capable of sending position commands.

    • Analog Pin Definition (int potPin = A0;): Specifies the physical channel connected to the center wiper of the potentiometer.

    • Pin Attachment (myServo.attach(9);): Binds the instantiated servo object to digital PWM-capable pin 9.

    • Comparative Execution (setup() vs loop()): setup() attaches pin configuration once initialization occurs; loop() repeatedly samples analog inputs and converts them into positional updates in real-time.

    • Motion Smoothing Delay (delay(15);): Gives the physical mechanical assembly 15 ms15\,\text{ms} to move toward the target angle before processing the next sensor read.

Automated Servo Sweep Circuit


Arduino servo motor sweep back and forth circuit
  • Sweep Motion Logic

    • The circuit utilizes a single servo motor connected to digital pin 9 driven continuously across its full range of motion without manual sensor intervention.

  • Program Code Analysis

    • for (int angle = 0; angle <= 180; angle += 1) iterates the position variable from 0∘ to 180∘0^\circ\text{ to }180^\circ in increments of 1∘1^\circ

    • Inside the forward loop, myServo.write(angle); updates target position and delay(15); provides time for step completion.

    • for (int angle = 180; angle >= 0; angle -= 1) decrements the position variable back from 180∘ to 0∘180^\circ\text{ to }0^\circ in step decrements of 1∘1^\circ

    • Inside the reverse loop, myServo.write(angle); updates target position and delay(15); maintains matching step timing.

Dual Servo Control with Dual Potentiometers


Arduino dual servo motor control with dual potentiometers
  • System Layout & Structural Mapping

    • A – Potentiometer 1: Connected to analog pin A0; controls the angular position of Servo 1 (Pin 9).

    • B – Potentiometer 2: Connected to analog pin A1; controls the angular position of Servo 2 (Pin 10).

    • C – Arduino Board: Central processor reading dual analog inputs and generating independent signal outputs.

  • Dual Servo Code Implementation

    • Servo servo1; and Servo servo2; instantiate two distinct servo objects.

    • int potPin1 = A0; and int potPin2 = A1; configure dedicated analog channels.

    • servo1.attach(9); connects Servo 1 signal line to digital pin 9.

    • servo2.attach(10); connects Servo 2 signal line to digital pin 10.

    • val1 = analogRead(potPin1); reads potentiometer 1 (0 to 10230\text{ to }1023).

    • val2 = analogRead(potPin2); reads potentiometer 2 (0 to 10230\text{ to }1023).

    • val1 = map(val1, 0, 1023, 0, 180); translates potentiometer 1 values into a range of 0∘ to 180∘0^\circ\text{ to }180^\circ

    • val2 = map(val2, 0, 1023, 0, 180); translates potentiometer 2 values into a range of 0∘ to 180∘0^\circ\text{ to }180^\circ

    • servo1.write(val1); sets target shaft position for Servo 1.

    • servo2.write(val2); sets target shaft position for Servo 2.

    • delay(15); provides joint delay for hardware synchronization.

  • Functional Questions & Detailed Explanations

    • Line 1 Role (#include <Servo.h>): Imports the standard Servo library to manage timing signals.

    • Line 23 Function (val1 = analogRead(potPin1);): Measures analog input voltage from Potentiometer 1 and returns an integer between 0 and 10230\text{ and }1023

    • Purpose of Line 27 (val1 = map(val1, 0, 1023, 0, 180);): Rescales the numerical range from standard 10-bit analog conversion into proportional degrees of shaft rotation (0∘ to 180∘0^\circ\text{ to }180^\circ).

    • Line 31 Function (servo1.write(val1);): Transmits position commands to rotate Servo 1 to mapped angle val1.

    • Line 15 vs Line 21 Execution: Line 15 (servo1.attach(9);) runs once in setup() for pin configuration. Line 21 (void loop()) opens the main block running continuously to support real-time user input.

    • Setup vs. Loop Distribution: setup() handles single-pass system configuration (attaching hardware pins), while loop() continuously monitors user controls and updates servo outputs.

Dual Servo Control with Push Buttons


Arduino dual servo motor control with dual push buttons
  • System Specifications & Pin Assignments

    • button1 connected to digital pin 2 with INPUT_PULLUP mode enabled.

    • button2 connected to digital pin 3 with INPUT_PULLUP mode enabled.

    • servo1 attached to digital pin 9.

    • servo2 attached to digital pin 10.

    • Default Rest Angles: originalAngle1 = 90 (90∘90^\circ) and originalAngle2 = 90 (90∘90^\circ).

    • Actuated State Angles: pressedAngle1 = 150 (150∘150^\circ) and pressedAngle2 = 30 (30∘30^\circ).

  • Control Code Program Logic

    • During setup(), both servos move to their default original positions (90∘90^\circ) via servo1.write(originalAngle1); and servo2.write(originalAngle2);.

    • loop() constantly evaluates digital inputs:

      • If digitalRead(button1) == LOW (Button 1 pressed), servo1 moves to 150∘150^\circ; otherwise it returns to 90∘90^\circ

      • If digitalRead(button2) == LOW (Button 2 pressed), servo2 moves to 30∘30^\circ; otherwise it returns to 90∘90^\circ

    • Execution pauses for delay(15); at the end of each loop iteration for smooth motion transition.

FreeCAD 3D Modeling Fundamentals

  • Lesson 3: Polyline Tool, Geometric Constraints, and 3D Padding

    • Polyline Tool:

      • Creates connected series of lines and arcs within a continuous sketch shape without exiting the tool.

      • Connects the final endpoint directly to the initial starting point to generate fully closed 2D profiles.

      • Step-by-Step Procedure:

        1. Open the Sketcher Workbench.

        2. Select Create New Sketch and pick an alignment plane.

        3. Select the Polyline tool (represented by a zig-zag line icon).

        4. Click inside the viewport to set the primary starting point.

        5. Click sequentially to construct secondary vertices and segments.

        6. Right-click or press Esc to terminate line creation.

      • Applications: Ideal for sketching complex structural profiles, bracket geometry, frames, and custom polygons.

    • Constraints:

      • Parametric rules that strictly specify shape geometry, spatial positions, and numerical dimensions of sketch elements.

      • Geometric Constraints: Govern structural properties (e.g., Horizontal, Vertical, Parallel, Equal, Tangent, Perpendicular).

      • Dimensional Constraints: Govern exact measurements (e.g., Distance, Radius, Angle).

      • Visual Verification: A fully constrained sketch turns green, indicating complete geometric stability suitable for 3D operations.

    • Padding (Extrusion):

      • Converts a 2D closed planar sketch into a 3D solid model by extruding thickness or height.

      • Step-by-Step Procedure:

        1. Complete and close the active 2D sketch.

        2. Switch from Sketcher to the Part Design Workbench.

        3. Select the target sketch and click the Pad icon.

        4. Input the target extrude length (e.g., 10 mm10\,\text{mm}).

        5. Select OK to generate the solid feature.

  • Lesson 4: Datum Planes, Construction Lines, and Material Removal (Pockets)

    • Datum Planes:

      • Custom reference planes created at arbitrary offset distances or angular orientations when standard primary planes (XY, XZ, YZ) are inadequate.

      • Provide new attachment surfaces for drawing sketches on angled, offset, or complex model geometry.

      • Step-by-Step Procedure:

        1. Access the Part Design Workbench.

        2. Select Create Datum Plane.

        3. Click a reference face or existing plane.

        4. Adjust numerical offset, angular inclination, or rotation parameters.

        5. Click OK to instantiate the plane.

    • Construction Lines:

      • Auxiliary reference lines used to guide, align, and position geometry elements within a sketch.

      • Rendered via the blue dashed-line toggle icon.

      • Hidden automatically during 3D operations and do not appear in the final solid model.

    • Pocket Tool:

      • Serves as the inverse feature of the Pad tool by subtracting or cutting material away from existing solid geometry.

      • Used to produce custom holes, internal cavities, cutouts, and surface grooves.

      • Step-by-Step Procedure:

        1. Select a solid model face or datum plane and initiate a New Sketch.

        2. Draw the closed 2D profile to be subtracted.

        3. Click Pocket and specify the cut depth or select Through All.

        4. Click OK to execute the subtraction.

  • Lesson 5: Edge Conditioning using the Fillet Tool

    • Fillet Tool:

      • Rounds off sharp linear edges or corner vertices on a 3D solid body.

      • Enhances mechanical structural strength while eliminating sharp stress concentration points.

      • Step-by-Step Procedure:

        1. Highlight target 3D object edges or corners.

        2. Click the Fillet Tool (represented by a rounded-edge icon).

        3. Input the desired radius measurement value.

        4. Click OK to generate rounded edge geometry.

      • Engineering Benefits: Mitigates internal stress concentrations along edges, improves aesthetic finish, and enhances manufacturing suitability.

FreeCAD Review and Assessment Solutions

  • Multiple Choice Questions & Key Answers

    1. The Polyline tool is used to:

      • Answer: b) Connect multiple lines

    2. A fully constrained sketch turns:

      • Answer: c) Green

    3. Padding converts a sketch into a:

      • Answer: c) 3D solid

    4. A datum plane is used to:

      • Answer: b) Create reference surfaces

    5. Construction lines are used for:

      • Answer: b) Reference only

    6. The Pocket tool is used to:

      • Answer: b) Remove material

    7. Which workbench allows you to pad a sketch?

      • Answer: c) Part Design

    8. Fillets are used to:

      • Answer: b) Round edges

    9. Which constraint ensures two lines are at 90∘90^\circ?

      • Answer: c) Perpendicular

    10. Which of the following is a dimensional constraint?

      • Answer: b) Radius

  • True or False Statements & Answers

    1. A polyline can include arcs and lines.

      • Answer: True

    2. Padding removes material from a model.

      • Answer: False

    3. Constraints help define geometry accurately.

      • Answer: True

    4. Datum planes are only decorative.

      • Answer: False

    5. Construction lines appear in the final solid.

      • Answer: False

    6. The Pocket tool cuts material away.

      • Answer: True

    7. Fillets are used to make sharp corners.

      • Answer: False

    8. A fully constrained sketch turns green.

      • Answer: True

    9. Datum planes help create new sketch surfaces.

      • Answer: True

    10. The Polyline tool can create closed shapes.

      • Answer: True

  • Conceptual "What" Questions & Answers

    • What is a polyline? A drawing tool used to create continuous connected lines and arc segments.

    • What does the Pad tool do? Converts a 2D sketch into a 3D solid by extruding material.

    • What is a datum plane used for? Creates custom reference surfaces for drawing sketches at custom angles or offsets.

    • What is the Pocket tool used for? Removes material from a solid object to make holes, slots, or cutouts.

    • What does a fillet do to edges? Rounds sharp model edges or corners to smooth geometry.

  • Analytical "Why" Questions & Answers

    • Why is constraint application important? Ensures sketch geometry is accurately dimensioned, stable, and predictable.

    • Why do designers use construction lines? Assists in precisely aligning and positioning sketch geometry without altering solid extrusions.

    • Why are datum planes needed? Allows features to be sketched on inclined or offset surfaces where standard planes are unavailable.

    • Why are fillets added to designs? Smooths sharp edges to reduce stress concentration and improve structural strength.

    • Why should a sketch be fully constrained before padding? Prevents geometry errors, unpredicted shifts, and model instability during 3D solid operations.

  • Procedural "How" Questions & Answers

    • How do you activate the Polyline tool? Click the Polyline icon inside the Sketcher Workbench.

    • How do you create a datum plane? Open Part Design Workbench, click Create Datum Plane, and select a reference surface to offset or tilt.

    • How do you remove material using the Pocket tool? Create a sketch on a face, open the Pocket tool, set depth parameters, and confirm with OK.

    • How do you apply a fillet? Select target edges on a 3D model, activate the Fillet tool, input the radius, and click OK.

    • How do you know your sketch is fully constrained? All lines and curves in the Sketcher viewport turn green.

  • Contextual "When" Questions & Answers

    • When should you use the Pad tool? When turning a fully constrained 2D profile into a 3D solid feature.

    • When do you use the Pocket tool? When material must be removed or cut out from existing 3D solid geometry.

    • When are construction lines helpful? When guide lines are required to position geometry without affecting solid features.

    • When is a sketch ready for padding? When all geometric elements are fully constrained and the sketch profile is closed.

    • When should fillets be applied? After the primary 3D base solid features have been completely generated.