Welcome to Flux
Treat Flux like your intern. Tell it what you'd like to build and it'll get to work. You can also ask it questions, brainstorm ideas, and teach it your preferences. Learn More
Ready.
Description:Diagram
OUT1VCC, GND, TXD, RXDQ11VDD, TXD, RXD, GNDMPNVDD, SDA, SCL, GNDU1ENA, ENB, IN1, IN2, IN3, IN4, OUT1, OUT2, OUT3, OUT4M1, M2OUT1:VCC to 5V of Arduino.OUT1:GND to GND.OUT1:TXD to D0/RX of Arduino.OUT1:RXD to D1/TX of Arduino.Q11:VDD to 5V.Q11:GND to GND.Q11:TXD to D10 (for software serial communication).Q11:RXD to D11 (for software serial communication).MPN:VDD to 3.3V.MPN:GND to GND.MPN:SDA to A4 (I2C data line).MPN:SCL to A5 (I2C clock line).U1:ENA to Arduino PWM Pin (e.g., D3).U1:ENB to Arduino PWM Pin (e.g., D9).U1:IN1 to D8.U1:IN2 to D7.U1:IN3 to D6.U1:IN4 to D5.U1:OUT1 and U1:OUT2 to M1.U1:OUT3 and U1:OUT4 to M2.U1:VSS to 5V.U1:VS to LiPo Battery +.U1:GND to GND.OUT1:VCC to 5V, OUT1:GND to GND.Q11:VDD to 5V, Q11:GND to GND, Q11:TXD to D10, Q11:RXD to D11.MPN:VDD to 3.3V, MPN:GND to GND, MPN:SDA to A4, MPN:SCL to A5.U1:ENA to D3, U1:ENB to D9, U1:IN1 to D8, U1:IN2 to D7, U1:IN3 to D6, U1:IN4 to D5.U1:OUT1 and U1:OUT2 to M1, U1:OUT3 and U1:OUT4 to M2, U1:VSS to 5V, U1:VS to LiPo Battery +, U1:GND to GND.SoftwareSerial for Bluetooth communicationTinyGPS++ for GPSWire for I2C communication with the compassHMC5883L (Adafruit's library for the compass).TXD to Arduino D10, RXD to Arduino D11TXD to Arduino D8, RXD to Arduino D7SDA to Arduino A4, SCL to Arduino A5ENA, IN1, IN2, IN3, IN4, and ENB to the appropriate Arduino digital pins.Cpp
#include #include #include #include TinyGPSPlus gps; SoftwareSerial bluetooth(10, 11); // RX, TX for HC-05 SoftwareSerial gpsSerial(8, 7); // RX, TX for PAM-7Q HMC5883L compass; const int motorPin1 = 2; // IN1 on the L298N const int motorPin2 = 3; // IN2 on the L298N const int motorPin3 = 4; // IN3 on the L298N const int motorPin4 = 5; // IN4 on the L298N const int enablePinA = 9; // ENA on the L298N const int enablePinB = 10; // ENB on the L298N void setup() { Serial.begin(9600); bluetooth.begin(9600); gpsSerial.begin(9600); Wire.begin(); compass = HMC5883L(); // Motor pins pinMode(enablePinA, OUTPUT); pinMode(enablePinB, OUTPUT); pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); // Set motor speed analogWrite(enablePinA, 255); analogWrite(enablePinB, 255); // Initial calibration for compass compass.setRange(HMC5883L_RANGE_1_3GA); compass.setMeasurementMode(HMC5883L_CONTINOUS); compass.setDataRate(HMC5883L_DATARATE_15HZ); compass.setSamples(HMC5883L_SAMPLES_8); } void loop() { while (gpsSerial.available() > 0) { gps.encode(gpsSerial.read()); } if (gps.location.isUpdated()) { double latitude = gps.location.lat(); double longitude = gps.location.lng(); Serial.print(F("Latitude= ")); Serial.print(latitude, 6); Serial.print(F(" Longitude= ")); Serial.println(longitude, 6); } // Get compass readings Vector norm = compass.readNormalize(); double heading = atan2(norm.YAxis, norm.XAxis); if (heading < 0) { heading += 2 * PI; } if (heading > 2 * PI) { heading -= 2 * PI; } heading = heading * 180 / PI; // Convert to degrees Serial.print(F("Heading: ")); Serial.println(heading); // Example motor control based on heading (simple case, needs expansion based on your logic) if (heading > 0 && heading < 180) { moveForward(); } else { moveBackward(); } // Simple Bluetooth Control if (bluetooth.available() > 0) { char command = (char)bluetooth.read(); if (command == 'f') { moveForward(); } else if (command == 'b') { moveBackward(); } else if (command == 'l') { turnLeft(); } else if (command == 'r') { turnRight(); } else if (command == 's') { stopMoving(); } } } void moveForward() { digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); } void moveBackward() { digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); } void turnLeft() { digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); } void turnRight() { digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); } void stopMoving() { digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); }
Reviews
Inspect
Autonomous "Follow Me" Cooler
Controls
Properties
Availability & Pricing
| Distributor | Qty 1 | |
|---|---|---|
| Digi-Key | $11.76 | |
| LCSC | $1.07–$4.03 | |
| Mouser | $11.76 | |
Assets
Welcome 👋
Flux accelerates your PCB design with AI.
Create your account to start using this component and bring your ideas to life.
ramprakashvishnoi8