{"id":26045466,"url":"https://github.com/akashdip2001/gyroscope","last_synced_at":"2026-03-07T20:02:21.817Z","repository":{"id":280980263,"uuid":"943808725","full_name":"akashdip2001/Gyroscope","owner":"akashdip2001","description":"Gyroscope module check","archived":false,"fork":false,"pushed_at":"2025-03-06T10:53:25.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T11:22:03.331Z","etag":null,"topics":["3d-simulation","gyroscope","gyroscope-module-check"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akashdip2001.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-06T09:52:10.000Z","updated_at":"2025-03-06T10:54:01.000Z","dependencies_parsed_at":"2025-03-06T11:32:10.528Z","dependency_job_id":null,"html_url":"https://github.com/akashdip2001/Gyroscope","commit_stats":null,"previous_names":["akashdip2001/gyroscope"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/akashdip2001/Gyroscope","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FGyroscope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FGyroscope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FGyroscope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FGyroscope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akashdip2001","download_url":"https://codeload.github.com/akashdip2001/Gyroscope/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FGyroscope/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30229587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T19:01:10.287Z","status":"ssl_error","status_checked_at":"2026-03-07T18:59:58.103Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d-simulation","gyroscope","gyroscope-module-check"],"created_at":"2025-03-07T19:53:16.079Z","updated_at":"2026-03-07T20:02:21.776Z","avatar_url":"https://github.com/akashdip2001.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gyroscope module check\n\n**MPU6050**, which is a common IMU (Inertial Measurement Unit) sensor with a gyroscope and accelerometer. Below is an **Arduino Nano** program to check whether the **gyroscope** is working. It reads **gyroscope data** (X, Y, Z) from the MPU6050 and prints it to the **Serial Monitor**.\n\n---\n\nhttps://github.com/user-attachments/assets/e0cbd5ce-cf62-4fba-a10f-d5bce5d15676\n\n### **Connections:**\n| MPU6050 Pin | Arduino Nano Pin |\n|------------|----------------|\n| VCC        | 5V            |\n| GND        | GND           |\n| SDA        | A4            |\n| SCL        | A5            |\n\n---\n\n### **Code:**\n```cpp\n#include \u003cWire.h\u003e\n\nconst int MPU6050_ADDR = 0x68;  // MPU6050 I2C address\n\nvoid setup() {\n    Serial.begin(9600);  // Start Serial Monitor\n    Wire.begin();        // Start I2C communication\n\n    // Wake up MPU6050 (default in sleep mode)\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x6B);  // PWR_MGMT_1 register\n    Wire.write(0);     // Set to zero (wakes up MPU6050)\n    Wire.endTransmission(true);\n}\n\nvoid loop() {\n    int16_t gyro_x, gyro_y, gyro_z;\n\n    // Request gyroscope data\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x43); // Starting register for gyro data\n    Wire.endTransmission(false);\n    Wire.requestFrom(MPU6050_ADDR, 6, true); // Request 6 bytes\n\n    // Read raw gyroscope values\n    gyro_x = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_y = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_z = (Wire.read() \u003c\u003c 8) | Wire.read();\n\n    // Display gyro readings\n    Serial.print(\"Gyro X: \"); Serial.print(gyro_x);\n    Serial.print(\" | Gyro Y: \"); Serial.print(gyro_y);\n    Serial.print(\" | Gyro Z: \"); Serial.println(gyro_z);\n\n    delay(500);  // Wait for half a second\n}\n```\n---\n\n\u003cimg align=\"right\" alt=\"\" width=\"45%\" src=\"https://github.com/user-attachments/assets/e9f796ee-13ad-4f3b-8cc4-2a74aa05f29b\"\u003e\n\n### **How It Works:**\n1. The code initializes **I2C communication** using the `Wire` library.\n2. It **wakes up the MPU6050** (since it's in sleep mode by default).\n3. It **reads raw gyroscope data** (X, Y, Z) from the sensor registers.\n4. It **prints** the gyroscope values to the Serial Monitor.\n5. The program loops every **500ms**, continuously updating the readings.\n\n---\n\n### **How to Run:**\n1. Upload this code to your **Arduino Nano** using the **Arduino IDE**.\n2. Open **Serial Monitor** (`Tools \u003e Serial Monitor`).\n3. Set **baud rate** to `9600`.\n4. Move/rotate the **MPU6050**, and you should see gyroscope readings change.\n\n---\n\n## ✅ Formatting the output cleanly  \n### ✅ Adding a simple **visual representation** using text-based bars  \n\n---\n\n### **Updated Code with Clear Output \u0026 Visual Representation**\n```cpp\n#include \u003cWire.h\u003e\n\nconst int MPU6050_ADDR = 0x68;  // MPU6050 I2C address\n\nvoid setup() {\n    Serial.begin(9600);  // Start Serial Monitor\n    Wire.begin();        // Start I2C communication\n\n    // Wake up MPU6050 (default in sleep mode)\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x6B);  // PWR_MGMT_1 register\n    Wire.write(0);     // Set to zero (wakes up MPU6050)\n    Wire.endTransmission(true);\n\n    Serial.println(\"MPU6050 Gyroscope Test Initialized...\");\n    Serial.println(\"Move the sensor to see changes in gyro values!\");\n    Serial.println(\"------------------------------------------------\");\n}\n\nvoid loop() {\n    int16_t gyro_x, gyro_y, gyro_z;\n\n    // Request gyroscope data\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x43); // Starting register for gyro data\n    Wire.endTransmission(false);\n    Wire.requestFrom(MPU6050_ADDR, 6, true); // Request 6 bytes\n\n    // Read raw gyroscope values\n    gyro_x = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_y = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_z = (Wire.read() \u003c\u003c 8) | Wire.read();\n\n    // Scale down values for better readability\n    int scaled_x = gyro_x / 150;\n    int scaled_y = gyro_y / 150;\n    int scaled_z = gyro_z / 150;\n\n    // Print formatted output\n    Serial.println(\"------------------------------------------------\");\n    Serial.print(\"Gyro X: \"); Serial.print(gyro_x);\n    Serial.print(\" | Y: \"); Serial.print(gyro_y);\n    Serial.print(\" | Z: \"); Serial.println(gyro_z);\n\n    // Visual representation\n    Serial.print(\"X-axis: \"); drawBar(scaled_x);\n    Serial.print(\"Y-axis: \"); drawBar(scaled_y);\n    Serial.print(\"Z-axis: \"); drawBar(scaled_z);\n\n    delay(500);  // Wait for half a second\n}\n\n// Function to print a text-based bar representation\nvoid drawBar(int value) {\n    if (value \u003c 0) {\n        Serial.print(\"[\");\n        for (int i = 0; i \u003c -value; i++) Serial.print(\"-\");\n        Serial.println(\"] \u003c\");\n    } else {\n        Serial.print(\"\u003e [\");\n        for (int i = 0; i \u003c value; i++) Serial.print(\"+\");\n        Serial.println(\"]\");\n    }\n}\n```\n\nhttps://github.com/user-attachments/assets/749e4a5e-e083-4781-97d1-cd391a4db0f7\n\n```cpp\n#include \u003cWire.h\u003e\n\nconst int MPU6050_ADDR = 0x68;  // MPU6050 I2C address\nint16_t gyro_x, gyro_y, gyro_z;\n\nvoid setup() {\n    Serial.begin(9600);  // Start Serial Monitor\n    Wire.begin();        // Start I2C communication\n\n    // Wake up MPU6050\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x6B);  // PWR_MGMT_1 register\n    Wire.write(0);     // Set to zero (wakes up MPU6050)\n    Wire.endTransmission(true);\n\n    Serial.println(\"MPU6050 Drone Simulation Initialized...\");\n    Serial.println(\"Move the sensor to see directional changes!\");\n}\n\nvoid loop() {\n    // Request gyroscope data\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x43); // Starting register for gyro data\n    Wire.endTransmission(false);\n    Wire.requestFrom(MPU6050_ADDR, 6, true); // Request 6 bytes\n\n    // Read gyroscope values\n    gyro_x = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_y = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_z = (Wire.read() \u003c\u003c 8) | Wire.read();\n\n    // Define thresholds for movement\n    int threshold = 800;  // Adjust based on sensitivity\n\n    Serial.println(\"\\n------------------------------\");\n    Serial.println(\"          DRONE STATUS        \");\n    Serial.println(\"------------------------------\");\n\n    // Determine movement direction\n    if (gyro_x \u003e threshold) {\n        Serial.println(\"➡️  Moving RIGHT\");\n    } else if (gyro_x \u003c -threshold) {\n        Serial.println(\"⬅️  Moving LEFT\");\n    }\n\n    if (gyro_y \u003e threshold) {\n        Serial.println(\"⬆️  Moving FORWARD\");\n    } else if (gyro_y \u003c -threshold) {\n        Serial.println(\"⬇️  Moving BACKWARD\");\n    }\n\n    if (gyro_z \u003e threshold) {\n        Serial.println(\"↻ Rotating CLOCKWISE\");\n    } else if (gyro_z \u003c -threshold) {\n        Serial.println(\"↺ Rotating COUNTERCLOCKWISE\");\n    }\n\n    if (gyro_x \u003c threshold \u0026\u0026 gyro_x \u003e -threshold \u0026\u0026 \n        gyro_y \u003c threshold \u0026\u0026 gyro_y \u003e -threshold \u0026\u0026 \n        gyro_z \u003c threshold \u0026\u0026 gyro_z \u003e -threshold) {\n        Serial.println(\"✈️  Drone is STABLE\");\n    }\n\n    delay(500);  // Update every 500ms\n}\n```\n\nhttps://github.com/user-attachments/assets/e2513c7b-a7df-48af-a298-d77224926220\n\n✅ **How to Read Output Easily?**  \n- **Numbers** show actual gyro values.  \n- **Bars (`+` and `-`)** show direction and intensity of movement.  \n- `\" \u003e \"` means positive movement, `\" \u003c \"` means negative movement.\n\n---\n\n# **Real-time moving rectangle** that reacts to your MPU6050 movements, like a **drone simulation**.\n\n[![Screenshot (154)](https://github.com/user-attachments/assets/8164d561-42fa-46dd-b8dc-cf41c096a046)](https://processing.org/download)  \n\n🚀 **why not in Adrino IDE ?**  \nSince the **Serial Monitor** only displays text, it **cannot show graphical movement** directly.  \n✅ Instead, I will create a **Processing sketch** (a program that runs on your PC) to visualize the rectangle moving based on your hand movements!  \n\n---\n\n### **🛠 SetUp**\n1. **Arduino Nano + MPU6050** (with I2C connected)\n2. **Processing IDE** (Download from [processing.org](https://processing.org/))\n3. **Install the `Serial` Library in Processing** (It's built-in)\n\n---\n\n# 2D simulation\n\n### **Step 1: Upload This Code to Arduino Nano**\nThis code **reads MPU6050 data** and **sends it to the PC** via Serial.\n```cpp\n#include \u003cWire.h\u003e\n\nconst int MPU6050_ADDR = 0x68;\nint16_t gyro_x, gyro_y;\n\nvoid setup() {\n    Serial.begin(115200);  \n    Wire.begin();  \n\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x6B);  \n    Wire.write(0);  \n    Wire.endTransmission(true);\n}\n\nvoid loop() {\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x43);  \n    Wire.endTransmission(false);\n    Wire.requestFrom(MPU6050_ADDR, 4, true);  \n\n    gyro_x = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_y = (Wire.read() \u003c\u003c 8) | Wire.read();\n\n    // Scale values for better control\n    int scaled_x = map(gyro_x, -15000, 15000, -10, 10);\n    int scaled_y = map(gyro_y, -15000, 15000, -10, 10);\n\n    Serial.print(scaled_x);\n    Serial.print(\",\");\n    Serial.println(scaled_y);\n\n    delay(50);  \n}\n```\n---\n\n### **Step 2: Run This Code in Processing**\nProcessing **receives Serial data** and **moves a rectangle** based on your hand movement.  \n\n```java\nimport processing.serial.*;\n\nSerial port;  \nint rectX, rectY;  \n\nvoid setup() {\n  size(600, 600);  \n  port = new Serial(this, Serial.list()[0], 115200);  // Adjust port if needed\n  rectX = width / 2;\n  rectY = height / 2;\n}\n\nvoid draw() {\n  background(0);\n  fill(255, 0, 0);\n  rect(rectX, rectY, 50, 50);\n\n  while (port.available() \u003e 0) {\n    String data = port.readStringUntil('\\n');\n    if (data != null) {\n      data = trim(data);\n      String[] values = split(data, ',');\n      if (values.length == 2) {\n        int moveX = int(values[0]);\n        int moveY = int(values[1]);\n\n        rectX += moveX;\n        rectY += moveY;\n\n        // Keep rectangle inside window\n        rectX = constrain(rectX, 0, width - 50);\n        rectY = constrain(rectY, 0, height - 50);\n      }\n    }\n  }\n}\n```\n\n---\n\n### **🚀 How It Works**\n- The **Arduino reads gyroscope values** and sends **scaled X, Y movement** via Serial.  \n- **Processing receives these values** and moves a **rectangle** on the screen.  \n- **When you tilt the MPU6050**, the rectangle **moves like a drone**!\n\n---\n\n### **📌 How to Run This?**\n1. **Upload the Arduino code** to your Nano.  \n2. **Open Processing** and **paste the Processing code** above.  \n3. **Run the Processing Sketch** → You’ll see a **rectangle moving with your MPU6050**!\n\nhttps://github.com/user-attachments/assets/e98f0834-b109-47a6-a3ed-fbd38ad1b027\n\n---\n\n# 3D simulation\n\n---\n\n### **🛠 What We Will Do:**\n✅ **Use Processing** to create a **3D cube (or drone shape)**  \n✅ **Use MPU6050 data** to control **pitch, roll, and yaw**  \n✅ **Display real-time movement** that matches your hand motion  \n\n---\n\n### **Step 1: Upload This Code to Arduino Nano**\nThis code **reads** the **gyro data** from the MPU6050 and **sends it over Serial**.  \n\n```cpp\n#include \u003cWire.h\u003e\n\nconst int MPU6050_ADDR = 0x68;\nint16_t gyro_x, gyro_y, gyro_z;\n\nvoid setup() {\n    Serial.begin(115200);\n    Wire.begin();\n\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x6B);\n    Wire.write(0);\n    Wire.endTransmission(true);\n}\n\nvoid loop() {\n    Wire.beginTransmission(MPU6050_ADDR);\n    Wire.write(0x43);  \n    Wire.endTransmission(false);\n    Wire.requestFrom(MPU6050_ADDR, 6, true);\n\n    gyro_x = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_y = (Wire.read() \u003c\u003c 8) | Wire.read();\n    gyro_z = (Wire.read() \u003c\u003c 8) | Wire.read();\n\n    // Scale values for smooth rotation\n    float scaled_x = gyro_x / 150.0;\n    float scaled_y = gyro_y / 150.0;\n    float scaled_z = gyro_z / 150.0;\n\n    Serial.print(scaled_x);\n    Serial.print(\",\");\n    Serial.print(scaled_y);\n    Serial.print(\",\");\n    Serial.println(scaled_z);\n\n    delay(50);\n}\n```\n\n---\n\n### **Step 2: Run This 3D Simulation in Processing**\nWe use **Processing + PeasyCam** to create a **real-time 3D cube (drone) simulation**.  \n\n```java\nimport processing.serial.*;\nimport peasy.*;\n\nSerial port;\nPeasyCam cam;\nfloat roll = 0, pitch = 0, yaw = 0;\n\nvoid setup() {\n  size(800, 800, P3D);\n  cam = new PeasyCam(this, 500);\n  port = new Serial(this, Serial.list()[0], 115200);\n}\n\nvoid draw() {\n  background(0);\n  lights();\n  \n  translate(0, 0, 0);\n  rotateX(radians(pitch));\n  rotateY(radians(yaw));\n  rotateZ(radians(roll));\n  \n  fill(0, 255, 0);\n  stroke(255);\n  \n  box(100);  // 3D Cube (Can be replaced with a drone model)\n  \n  while (port.available() \u003e 0) {\n    String data = port.readStringUntil('\\n');\n    if (data != null) {\n      data = trim(data);\n      String[] values = split(data, ',');\n      if (values.length == 3) {\n        roll = float(values[0]);\n        pitch = float(values[1]);\n        yaw = float(values[2]);\n      }\n    }\n  }\n}\n```\n\n---\n\n### **🚀 What Happens Here**\n- The **Arduino reads** **pitch, roll, yaw** and sends it via Serial.  \n- **Processing reads the values** and applies them to a **3D cube (your drone model)**.  \n- The cube **tilts, rotates, and moves** like your **real MPU6050 sensor!**  \n\n---\n\n### **📌 How to Run This**\n1. **Upload the Arduino code** to your Nano.  \n2. **Install Processing** ([Download Here](https://processing.org/download))  \n3. **Install PeasyCam Library** (Go to `Sketch \u003e Import Library \u003e Add Library \u003e Search \"PeasyCam\" \u003e Install`)  \n4. **Run the Processing Sketch**  \n5. **Move your MPU6050** → Watch the **3D cube tilt, turn, and rotate** in real-time!\n\n---\n\n### If You get error with Add Library\n\nIf you're missing the **PeasyCam library** in Processing. Let's fix that.  \n\n---\n\n### **✅ Fix: Install PeasyCam in Processing**\n1. Open **Processing IDE**.  \n2. Go to **Sketch \u003e Import Library \u003e Add Library**.  \n3. In the search bar, type **\"PeasyCam\"**.  \n4. Click **Install** and wait for it to complete.  \n5. Restart Processing and try running the code again.  \n\n---\n\n### **🛠 Alternative Without PeasyCam (Using Manual 3D Rotation)**\nIf you want a **simple version without PeasyCam**, replace the code with this:\n\n```java\nimport processing.serial.*;\n\nSerial port;\nfloat roll = 0, pitch = 0, yaw = 0;\n\nvoid setup() {\n  size(800, 800, P3D);\n  port = new Serial(this, Serial.list()[0], 115200);\n}\n\nvoid draw() {\n  background(0);\n  lights();\n\n  translate(width / 2, height / 2, 0);\n  rotateX(radians(pitch));\n  rotateY(radians(yaw));\n  rotateZ(radians(roll));\n\n  fill(0, 255, 0);\n  stroke(255);\n  box(100);  // 3D Cube\n\n  while (port.available() \u003e 0) {\n    String data = port.readStringUntil('\\n');\n    if (data != null) {\n      data = trim(data);\n      String[] values = split(data, ',');\n      if (values.length == 3) {\n        roll = float(values[0]);\n        pitch = float(values[1]);\n        yaw = float(values[2]);\n      }\n    }\n  }\n}\n```\n\n### **📌 How This Works**\n- **Removes PeasyCam** but keeps the **3D movement.**  \n- Uses **rotateX(), rotateY(), rotateZ()** for real-time rotation.  \n- Cube moves **based on MPU6050 data** like a drone.\n\nhttps://github.com/user-attachments/assets/dcd72a90-6dd1-469e-a8ad-ff456e0b5d66\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakashdip2001%2Fgyroscope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakashdip2001%2Fgyroscope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakashdip2001%2Fgyroscope/lists"}