darkfexy

/

All changes saved

0

0

Files

Schematic

Code

PCB

Log InSign Up

PCB and Schematic Design Assistance

flux

0:39

Generating Arduino code.

Creating an Arduino sketch.

Clarifying pins for Arduino code.

Here’s a simple Arduino sketch that walks through each pin/component one‐by‐one so you can verify wiring and basic operation. Adjust any pin numbers or timings to match your final layout.

Cpp


// === Pin Definitions ===
// Communications
const int hc05Key    =  7;    // if used
// HC-05 serial is on Serial1 if you use a 328P–Arduino Nano
// (Arduino Nano only has one hardware UART, so we use SoftwareSerial if needed)
#include 
const int btRxPin    =  1;    // D1 → HC-05 RX 
const int btTxPin    =  0;    // D0 ← HC-05 TX
SoftwareSerial BT(btRxPin, btTxPin);

// Ultrasonic sensors
const int trigFront  =  7;    // D7 → HC-SR04 Front TRIG
const int echoFront  =  8;    // D8 ← HC-SR04 Front ECHO

// Bumper & status LED
const int bumpPin    = 13;    // D13 → bumper switch
const int ledPin     = 12;    // spare digital pin for LED_STAT (avoid sharing D13)

// MOSFET gates (test as digital outputs)
const int vacGate    = 10;    // D10 → Q1 gate
const int brushGate  = 11;    // D11 → Q2 gate
const int pumpGate   = 12;    // D12 → Q3/relay drive

// Motor driver inputs
const int m1In1      =  3;    // D3 → L293D IN1
const int m1In2      =  5;    // D5 → L293D IN2
const int m2In3      =  6;    // D6 → L293D IN3
const int m2In4      =  9;    // D9 → L293D IN4

// IR cliff sensors
const int ir1Pin     = A0;    // A0 → TCRT5000 #1
const int ir2Pin     = A1;    // A1 → TCRT5000 #2

// ========================

void setup() {
  Serial.begin(9600);
  BT.begin(9600);
  pinMode(ledPin,    OUTPUT);
  pinMode(bumpPin,   INPUT_PULLUP);
  pinMode(trigFront, OUTPUT);
  pinMode(echoFront, INPUT);
  
  pinMode(vacGate,   OUTPUT);
  pinMode(brushGate, OUTPUT);
  pinMode(pumpGate,  OUTPUT);

  pinMode(m1In1,     OUTPUT);
  pinMode(m1In2,     OUTPUT);
  pinMode(m2In3,     OUTPUT);
  pinMode(m2In4,     OUTPUT);

  Serial.println(F("=== Hardware Test Start ==="));
}

void loop() {
  // 1) Blink status LED
  digitalWrite(ledPin, HIGH);
  delay(200);
  digitalWrite(ledPin, LOW);
  delay(200);

  // 2) Read bumper switch
  bool bump = !digitalRead(bumpPin);
  Serial.print(F("Bumper: "));
  Serial.println(bump ? "PRESSED" : "OPEN");

  // 3) Test HC-05 comms
  if (BT.available()) {
    Serial.print(F("BT RX: "));
    Serial.write(BT.read());
  }
  if (Serial.available()) {
    BT.write(Serial.read());
    Serial.println(F("→ sent to HC-05"));
  }

  // 4) Trigger HC-SR04 Front
  long duration;
  digitalWrite(trigFront, LOW);
  delayMicroseconds(2);
  digitalWrite(trigFront, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigFront, LOW);
  duration = pulseIn(echoFront, HIGH, 30000);
  float distCm = duration * 0.034 / 2;
  Serial.print(F("Front Dist: "));
  Serial.print(distCm);
  Serial.println(F(" cm"));

  // 5) Read IR cliff sensors
  int ir1 = analogRead(ir1Pin);
  int ir2 = analogRead(ir2Pin);
  Serial.print(F("IR1: "));
  Serial.print(ir1);
  Serial.print(F("  IR2: "));
  Serial.println(ir2);

  // 6) Toggle MOSFETs & relay
  digitalWrite(vacGate,   HIGH); delay(100); digitalWrite(vacGate,   LOW);
  digitalWrite(brushGate, HIGH); delay(100); digitalWrite(brushGate, LOW);
  digitalWrite(pumpGate,  HIGH); delay(100); digitalWrite(pumpGate,  LOW);
  Serial.println(F("MOSFET/Relay pulses sent"));

  // 7) Test motors via L293D (short bursts)
  digitalWrite(m1In1, HIGH);
  digitalWrite(m1In2, LOW);
  digitalWrite(m2In3, HIGH);
  digitalWrite(m2In4, LOW);
  delay(200);
  digitalWrite(m1In1, LOW);
  digitalWrite(m1In2, LOW);
  digitalWrite(m2In3, LOW);
  digitalWrite(m2In4, LOW);
  Serial.println(F("Motors forward pulse"));

  delay(1000);  // Wait before repeating
}
How to use:
  1. Upload this sketch to your Nano.
  2. Open the Serial Monitor at 9600 baud.
  3. Verify each printed message and sensor reading.
  4. Observe LED blink, bumper switch state, ultrasonic distance, IR sensor values, MOSFET and motor pulses.
Let me know if you need any modifications!
Add testpoints
Decoupling capacitors
Select 3.3V LDO
Trace width calc
MOSFET selection
260 days

​
Sign up to send

To get started, talk to Flux or create a New Document.

Reviews

Documents

    Documents are markdown text files which describe project goals, capture details, or even simulation outputs.

    Assets

    Assets are files uploaded to this project which can be used in various ways.

    Cultural Peach Ecto Goggles thumbnail
    Welcome to your new project. Imagine what you can build here.

    Properties

    Properties describe core aspects of the project.

    Pricing & Availability

    Distributor

    Qty 1

    Arrow

    $18.83–$36.78

    Digi-Key

    $38.06–$42.39

    LCSC

    $38.21–$38.68

    Mouser

    $52.83–$72.79

    TME

    $11.70

    Verical

    $17.33–$25.31

    Controls

    Welcome 👋

    Flux helps you build PCBs faster with an AI teammate!

    Create your account to collaborate, stay updated, fork your own version, and get instant answers from our AI agent.

        Introducing AI Placement!
        AI Placement Demo

        AI-Powered Component Placement

        Let AI place your components intelligently. AI Placement analyzes your schematic and positions components for optimal routing, signal integrity, and board density.

        From Schematic to Layout in Seconds

        Skip the tedious manual placement. AI Placement generates a starting layout you can refine, saving hours of repetitive work on every new design.

        Works With Auto-Layout

        Pair AI Placement with Auto-Layout for a complete AI-driven PCB design flow — from component placement through trace routing, all with one click.

        Try it