Drone v2
Drone v2
Since I can't generate images directly here, let me guide you with a detailed mental map of
how everything is laid out:
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.
DHT11 Sensor Pin 10 (Data Pin) 5V / GND 10KΩ pull-up resistor between VCC
& Data
ESC 1 (Motor Pin 3 (PWM) Powered by ESCs power motors, PWM controls
1) PDB speed
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!
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.
cpp
Copy code
#include <Wire.h>
#include <Servo.h>
#include <MPU6050.h>
#include <DHT.h>
MPU6050 mpu;
long duration;
int distance;
// Flight variables
int tempIndex = 0;
float movingAverageTemp() {
float total = 0;
total += temperatureReadings[i];
temperatureReadings[tempIndex] = newTemp;
void setup() {
Serial.begin(9600);
Wire.begin();
dht.begin();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// Arm motors
motor1.writeMicroseconds(1000);
motor2.writeMicroseconds(1000);
motor3.writeMicroseconds(1000);
motor4.writeMicroseconds(1000);
delay(2000);
void loop() {
if (isnan(temperature) || isnan(humidity)) {
return;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(humidity);
Serial.println(" %");
updateTemperatureReadings(temperature);
Serial.print(predictedTemp);
Serial.println(" °C");
Serial.print("Distance: ");
Serial.println(distance);
avoidObstacle();
} else {
flyStraight();
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
return distance;
void avoidObstacle() {
motor1.writeMicroseconds(motorSpeed - 200);
motor2.writeMicroseconds(motorSpeed - 200);
motor3.writeMicroseconds(motorSpeed - 200);
motor4.writeMicroseconds(motorSpeed - 200);
void flyStraight() {
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!