0% found this document useful (0 votes)
12 views13 pages

Drone v2

Uploaded by

Savir Bhaiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views13 pages

Drone v2

Uploaded by

Savir Bhaiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1.

Components and Connections Overview:

Here are the components involved in the project:

● Arduino Uno (or Nano)


● DHT11 Temperature and Humidity Sensor
● Ultrasonic Sensor (HC-SR04)
● MPU6050 IMU (Inertial Measurement Unit)
● 4 Brushless Motors
● 4 Electronic Speed Controllers (ESCs)
● LiPo Battery (to power ESCs)
● Breadboard (for connections)
● Power Distribution Board (PDB) (optional but recommended for better power
management)

Component Connections Summary:

● Ultrasonic Sensor (HC-SR04):


○ VCC → 5V (Arduino)
○ GND → GND (Arduino)
○ Trig → Pin 12 (Arduino)
○ Echo → Pin 11 (Arduino)
● DHT11 Temperature/Humidity Sensor:
○ VCC → 5V (Arduino)
○ GND → GND (Arduino)
○ Data Pin → Pin 10 (Arduino)
○ (Note: DHT11 often requires a 10KΩ pull-up resistor between VCC and Data
Pin.)
● MPU6050 IMU:
○ VCC → 5V (Arduino)
○ GND → GND (Arduino)
○ SCL → A5 (Arduino - I²C Clock)
○ SDA → A4 (Arduino - I²C Data)
● ESCs for Motors:
○ Signal Wires (PWM):
■ ESC 1 → Pin 3 (Arduino)
■ ESC 2 → Pin 5 (Arduino)
■ ESC 3 → Pin 6 (Arduino)
■ ESC 4 → Pin 9 (Arduino)
○ Power Wires (ESCs): Connected to the Power Distribution Board (PDB),
which in turn is connected to the LiPo Battery.
○ Ground Wires (ESCs): Connected to the GND rail of the PDB.

2. Breadboard and Wiring Diagram Explanation:


1. Power Supply Setup:
○ Arduino is powered through the Vin pin from a Voltage Regulator connected
to the LiPo Battery. Alternatively, you can power the Arduino via USB or
directly from the LiPo if using a compatible step-down voltage regulator (5V
output).
○ ESCs are powered by the LiPo Battery via the Power Distribution Board
(PDB). The signal wires from the ESCs go to the Arduino PWM pins, and
their power wires are connected to the PDB.
2. Sensor Connections:
○ All sensors (Ultrasonic, DHT11, MPU6050) share the 5V and GND lines from
the Arduino.
○ Data lines from each sensor are connected to specific Arduino pins as
described above.

3. Visual Representation (Example Arduino Setup with Breadboard):

Since I can't generate images directly here, let me guide you with a detailed mental map of
how everything is laid out:

● Arduino Uno sits in the center or one side of the breadboard.


● The 5V and GND pins of the Arduino are connected to the power rails (red and blue
lines) of the breadboard.
● DHT11 Sensor:
○ One of its legs (VCC) is connected to the 5V rail of the breadboard.
○ The GND leg connects to the GND rail.
○ The Data Pin connects to Pin 10 on the Arduino.
○ A 10KΩ resistor is placed between the 5V rail and the Data Pin.
● Ultrasonic Sensor:
○ Connect VCC to the 5V rail.
○ Connect GND to the GND rail.
○ Trig Pin goes to Pin 12.
○ Echo Pin goes to Pin 11.
● MPU6050 IMU:
○ VCC goes to the 5V rail.
○ GND goes to the GND rail.
○ SCL Pin goes to A5 on the Arduino.
○ SDA Pin goes to A4 on the Arduino.
● ESC Connections:
○ PWM Signal Wires (thin wires from ESCs) connect to the appropriate PWM
pins (3, 5, 6, 9) on the Arduino.
○ Power Wires (Thicker) from each ESC connect to the Power Distribution
Board.
○ The LiPo Battery connects to the Power Distribution Board, which provides
power to the motors via the ESCs.
4. Example Circuit (Component Layout Explanation):

1. Breadboard Power Rail Setup:


○ Connect the 5V pin of the Arduino to the positive (red) rail of the
breadboard.
○ Connect the GND pin of the Arduino to the ground (blue) rail of the
breadboard.
2. Ultrasonic Sensor Wiring:
○ Place the HC-SR04 sensor in the breadboard and connect the VCC pin to
the red power rail.
○ Connect the GND pin to the ground rail.
○ Connect Trig to Pin 12 on the Arduino and Echo to Pin 11.
3. DHT11 Sensor Wiring:
○ Place the DHT11 sensor on the breadboard.
○ Connect its VCC pin to the red power rail, GND pin to the ground rail, and
the Data pin to Pin 10 of the Arduino.
○ Add a 10KΩ pull-up resistor between the VCC and Data pin of the DHT11
sensor.
4. MPU6050 IMU Wiring:
○ Place the MPU6050 on the breadboard.
○ Connect its VCC pin to the red power rail, and GND to the blue rail.
○ Connect SCL to A5 and SDA to A4 on the Arduino.
5. ESCs and Motors Setup:
○ Connect the signal wires of each ESC to the following Arduino pins:
■ ESC 1 to Pin 3
■ ESC 2 to Pin 5
■ ESC 3 to Pin 6
■ ESC 4 to Pin 9
○ The power wires from the ESCs connect to the Power Distribution Board
(PDB), and the LiPo battery powers the PDB.

5. Optional Enhancements:

● Voltage Regulation: If powering your Arduino directly from a LiPo Battery (typically
11.1V for 3S or 14.8V for 4S), you’ll need a step-down voltage regulator to bring
the battery voltage down to 5V to safely power the Arduino.
● Additional Sensors: Wind speed sensors or barometers could also be integrated
into this design to further enhance the weather prediction capabilities.

Summary of Wiring Connections:


Component Arduino Pin Power Notes
Source

Ultrasonic Pin 12 (Trig) 5V / GND Trig to Pin 12, Echo to Pin 11


Sensor
Pin 11 (Echo)

DHT11 Sensor Pin 10 (Data Pin) 5V / GND 10KΩ pull-up resistor between VCC
& Data

MPU6050 IMU A5 (SCL), A4 5V / GND I²C communication for IMU


(SDA)

ESC 1 (Motor Pin 3 (PWM) Powered by ESCs power motors, PWM controls
1) PDB speed

ESC 2 (Motor Pin 5 (PWM) Powered by


2) PDB

ESC 3 (Motor Pin 6 (PWM) Powered by


3) PDB

ESC 4 (Motor Pin 9 (PWM) Powered by


4) PDB

LiPo Battery N/A Powers PDB Powers ESCs and Arduino (via
regulator)

🚁🔧
This setup should work for building your weather-predicting drone using Arduino. Good luck
with your project!

New hotkeys for you:

● 1. Request step-by-step images or diagrams 🎨


● 2.
Here is an example of how the Arduino Uno is connected to a breadboard along with the
DHT11 sensor, HC-SR04 ultrasonic sensor, MPU6050 IMU, and the ESCs controlling the
brushless motors. The layout includes all the wiring details and connections as described.

Let me know if you need further clarifications!

Certainly! Here’s the combined code that integrates everything: DHT11 sensor readings
for temperature and humidity, ultrasonic obstacle avoidance, and a basic weather
prediction model using a moving average. The drone will use the IMU for stabilization and
predict temperature trends based on the DHT11 data.

Full Combined Code for the Weather Prediction Drone:

cpp

Copy code
#include <Wire.h>

#include <Servo.h>

#include <MPU6050.h>

#include <DHT.h>

#define DHTPIN 10 // Pin where the DHT11 is connected

#define DHTTYPE DHT11 // DHT 11 sensor

DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor

// Define motor pins

Servo motor1, motor2, motor3, motor4;

MPU6050 mpu;

// Ultrasonic sensor pins

const int trigPin = 12;

const int echoPin = 11;

long duration;

int distance;

int obstacleThreshold = 30; // Distance threshold for obstacle


detection

// Flight variables

int motorSpeed = 1000; // Base throttle value

// Weather Prediction variables


#define NUM_SAMPLES 10 // Number of samples for moving average

float temperatureReadings[NUM_SAMPLES]; // Store temperature samples

int tempIndex = 0;

// Function to calculate moving average for temperature prediction

float movingAverageTemp() {

float total = 0;

for (int i = 0; i < NUM_SAMPLES; i++) {

total += temperatureReadings[i];

return total / NUM_SAMPLES;

// Function to update temperature readings

void updateTemperatureReadings(float newTemp) {

temperatureReadings[tempIndex] = newTemp;

tempIndex = (tempIndex + 1) % NUM_SAMPLES;

void setup() {

Serial.begin(9600);

Wire.begin();

// Initialize MPU6050 and DHT11 sensor


mpu.initialize();

dht.begin();

// Attach motors to PWM pins

motor1.attach(3); // Front-left motor

motor2.attach(5); // Front-right motor

motor3.attach(6); // Rear-left motor

motor4.attach(9); // Rear-right motor

// Setup ultrasonic sensor pins

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

// Arm motors

motor1.writeMicroseconds(1000);

motor2.writeMicroseconds(1000);

motor3.writeMicroseconds(1000);

motor4.writeMicroseconds(1000);

delay(2000);

void loop() {

// ********** Read and Display Weather Data **********

float temperature = dht.readTemperature();


float humidity = dht.readHumidity();

// Check if DHT sensor reading failed

if (isnan(temperature) || isnan(humidity)) {

Serial.println("Failed to read from DHT sensor!");

return;

// Print the current temperature and humidity

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.print(" °C, Humidity: ");

Serial.print(humidity);

Serial.println(" %");

// ********** Update and Display Temperature Prediction **********

// Update the temperature readings for moving average

updateTemperatureReadings(temperature);

// Get the moving average temperature prediction

float predictedTemp = movingAverageTemp();

Serial.print("Predicted Temperature: ");

Serial.print(predictedTemp);
Serial.println(" °C");

// ********** Ultrasonic Sensor - Obstacle Avoidance **********

long distance = getUltrasonicDistance();

Serial.print("Distance: ");

Serial.println(distance);

// ********** Get and Stabilize the Drone **********

int16_t ax, ay, az, gx, gy, gz;

mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

adjustStabilization(ax, ay, gx, gy);

// ********** Obstacle Avoidance Logic **********

if (distance < obstacleThreshold) {

avoidObstacle();

} else {

flyStraight();

delay(100); // Slow down the loop for more stable readings

// ********** Function to get the Ultrasonic Distance **********


long getUltrasonicDistance() {

// Trigger the ultrasonic sensor

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Read the echo pin

duration = pulseIn(echoPin, HIGH);

// Calculate the distance in cm

distance = duration * 0.034 / 2;

return distance;

// ********** Stabilization using IMU **********

void adjustStabilization(int ax, int ay, int gx, int gy) {

// Use gyroscope data to stabilize the drone

int roll = map(gx, -17000, 17000, -100, 100);

int pitch = map(gy, -17000, 17000, -100, 100);

motor1.writeMicroseconds(motorSpeed + pitch - roll);

motor2.writeMicroseconds(motorSpeed + pitch + roll);


motor3.writeMicroseconds(motorSpeed - pitch - roll);

motor4.writeMicroseconds(motorSpeed - pitch + roll);

// ********** Obstacle Avoidance **********

void avoidObstacle() {

// Slow down the drone to avoid the obstacle

motor1.writeMicroseconds(motorSpeed - 200);

motor2.writeMicroseconds(motorSpeed - 200);

motor3.writeMicroseconds(motorSpeed - 200);

motor4.writeMicroseconds(motorSpeed - 200);

delay(500); // Allow time to turn or move

// ********** Fly Straight **********

void flyStraight() {

// Maintain constant throttle for straight flight

motor1.writeMicroseconds(motorSpeed);

motor2.writeMicroseconds(motorSpeed);

motor3.writeMicroseconds(motorSpeed);

motor4.writeMicroseconds(motorSpeed);

}
Explanation of Combined Code:

● Temperature and Humidity Reading: The DHT11 sensor reads temperature and
humidity. This data is displayed via the serial monitor.
● Weather Prediction: The code keeps track of the last 10 temperature readings and
computes the moving average. This provides a simple prediction for future
temperature changes.
● Ultrasonic Sensor: Measures the distance to obstacles. If an obstacle is detected,
the drone reduces speed to avoid a collision.
● IMU for Stabilization: Uses data from the MPU6050 (gyroscope and accelerometer)
to maintain drone balance.
● Obstacle Avoidance: The drone checks the ultrasonic sensor for obstacles. If it
detects something closer than the threshold, it slows down and adjusts accordingly.
● Motor Control: Four brushless motors are controlled via PWM signals sent from the
Arduino. The motor speeds are adjusted to maintain stability and avoid obstacles.

Next Steps:

● Tuning and Calibration: The stabilization logic can be tuned by adjusting the PID
control parameters (this example just uses basic pitch/roll adjustments).
● Additional Sensors: Add more sensors like wind speed or a barometer for more
sophisticated weather prediction.
● Data Logging: Log weather data over time to build better predictive models.

🚁✨
This complete code should give you a solid starting point for building your
weather-predicting drone using an Arduino!

You might also like