my first drone project with arduino nano iot 33

Hi guys i'm korean univ student. During my vacation, I started Diy project making mini drone.


This is my first drone. I've suffered from many problems.But i success to fly my drone for a second....:slight_smile:
However the drone rotate around the z-axis. and it can't balance itself.
I've seen so many video that brushed drone which was made roughly fly in a certain direction. So.. i wonder that which one is real or bigger problem between hardware and software. And if the problem is in the software, how i can fix my drone in the air.
Plz tell me how can i solve the problem.... :confused: :confused:

Hi kimjunsuk

You might take a look at the Udemy drone class offerings to see if any can augment your class work.

Udemy Drone Classes

What book(s) are you using and do you have any Nano 33 IoT drone code to share?

surfnm:
Hi kimjunsuk

You might take a look at the Udemy drone class offerings to see if any can augment your class work.

Udemy Drone Classes

What book(s) are you using and do you have any Nano 33 IoT drone code to share?

The recommendations are appreciated, but if possible, I don't want to spend money on lectures because i already spent too much money to solve some problem while i've made drone.

This is my code. i use Blynk, IR laser measuring sensor, and accellometor sensor library.

#include <Arduino_LSM6DS3.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#include <Arduino_LSM6DS3.h>
#include "Adafruit_VL53L0X.h"
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
char auth[] = "---------------------------------------------";
char ssid[] = "-------------";
char pass[] = "-------------------";
int ml=4;
int mr=5;
int fl=3;
int fr=6;
int bl=9;
int br=10;
int c=75;
int dis;
double D=0;
double i=0;
double flspd=0;
double frspd=0;
double blspd=0;
double brspd=0;
double mlspd=0;
double mrspd=0;
void altitude();
void attitude();
void setup() {
Blynk.begin(auth, ssid, pass);
pinMode(fl,OUTPUT);
pinMode(fr,OUTPUT);
pinMode(bl,OUTPUT);
pinMode(br,OUTPUT);
pinMode(ml,OUTPUT);
pinMode(mr,OUTPUT);
Serial.begin(9600);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");

while (1);
}
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}
}

BLYNK_WRITE(V0){
dis=param.asInt();
}

BLYNK_WRITE(V1){
int cx=param[0].asInt();
int cy=param[1].asInt();

if(flspd+cx-cy>=0&&flspd+cx-cy<=255){
flspd=flspd+cx-cy;
}
if(frspd-cx-cy>=0&&frspd-cx-cy<=255){
frspd=frspd-cx-cy;
}
if(blspd+cx+cy>=0&&blspd+cx+cy<=255){
blspd=blspd+cx+cy;
}
if(brspd-cx+cy>=0&&brspd-cx+cy<=255){
brspd=brspd-cx+cy;
}
if(mlspd+cx>=0&&mlspd+cx<=255){
mlspd=mlspd+cx;
}
if(mrspd-cx>=0&&mrspd-cx<=255){
mrspd=mrspd-cx;
}

}

void loop() {

Blynk.run();
altitude();
attitude();
analogWrite(ml,mlspd);
analogWrite(mr,mrspd);
analogWrite(fl,flspd);
analogWrite(fr,frspd);
analogWrite(bl,blspd);
analogWrite(br,brspd);
}
void altitude(){//altitude handling
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&measure, false);
if (measure.RangeStatus != 4) {
Serial.print("Distance (mm): ");
Serial.println(measure.RangeMilliMeter);
D=((dis-measure.RangeMilliMeter/10)(dis-measure.RangeMilliMeter/10)(dis-measure.RangeMilliMeter/10))/54;
if((i+D)<=255&&(i+D)>=0){
i+=D;
}
else if((i+D)<0){
i+=0;
}
else if((i+D)>255){
i+=(int)D%255;
}
}
else {

}
}
void attitude(){//attitude control
float x, y, z;

if (IMU.accelerationAvailable()) {
IMU.readAcceleration(y, x, z);
if(i+xxxc-yyyc>=0&&i+xxxc-yyyc<=255){
frspd=i+xxxc-yyyc;
}
if(i-xxxc-yyyc>=0&&i-xxxc-yyyc<=255){
flspd=i-xxxc-yyyc;
}
if(i+xxxc+yyyc>=0&&i+xxxc+yyyc<=255){
brspd=i+xxxc+yyyc;
}
if(i-xxxc+yyyc>=0&&i-xxxc+yyyc<=255){
blspd=i-xxxc+yyyc;
}
if(i+xxxc>=0&&i+xxxc<=255){
mrspd=i+xxxc;
}
if(i-x
xxc>=0&&i-xxxc<=255){
mlspd=i-x
xxc;
}
}
}

Thank you :slight_smile:

Hi kimjunsuk,

Thanks for the code share, will take a look this week and see if I can help.

Understand that you prefer not to take another class, however the Coursera diy drone class might be of interest to some

Coursera Drone Class

Diy drone project notes might be of help as well

Overview
*Arduino coding plan/work breakdown structure/statement of work
*Kalman filters for navigation purposes
*Quaternions for keeping track of attitude (angular position)
*BLE and or WiFi for sending IMU data

How-to
*Arduino SOW
** Planning and Implementing an Arduino Program - Programming Questions - Arduino Forum
*Kalman filter
** https://forum.arduino.cc/index.php/topic,58048.0.html
*Quaternions
** Arduino Nano 33 IoT: Angles from IMU - Nano 33 IoT - Arduino Forum
*IMU data via BLE or WiFi
** Communication between Nano IOT and C# or/and Python. - Nano 33 IoT - Arduino Forum