Aiman AnsariIshan Mudgal
Published

Peace Missile

What if the same systems that deliver warheads can deliver lifelines.

IntermediateShowcase (no instructions)Over 1 day84
Peace Missile

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
LED (generic)
LED (generic)
×3

Software apps and online services

n8n
The n8n workflow also used ChatGPT-4o API within the workflow.
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
Circular saw
Rubber bands
Wood planks
3D Printer (generic)
3D Printer (generic)
Nail Gun

Story

Read more

Schematics

Arduino wiring

Code

Arduino code

Arduino
The code for connecting to the internet, communicating with n8n, parsing collected json info, and using it to turn the motors 90 degrees, and back. The serial monitor gives detailed info of the status of the steps and the received info. There are also LEDs that light up for the same.
#include <WiFi.h>       // Use <ESP8266WiFi.h> for ESP8266
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <ESP32Servo.h>

Servo o;
Servo oo;
Servo ooo;

const char* ssid = "ssid";
const char* password = "password";
const char* n8n_webhook_url = "https://yourlinkhere.app.n8n.cloud/webhook-test/arduino-status";

int control1;
int control2;
int control3;

void setup() {

  o.attach(5);
  oo.attach(6);
  ooo.attach(7);
  
  o.write(0);
  oo.write(0);
  ooo.write(0);
  
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  pinMode(38, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);

  if (WiFi.status() != WL_CONNECTED) {
    delay(200);
    Serial.print(".");
  }
    Serial.println("\nWiFi Connected");

  // digitalWrite(46, LOW);
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin(n8n_webhook_url);
    http.addHeader("Content-Type", "application/json");
  
    // Test data payload
    String httpRequestData = "{\"status\":\"success\", \"message\":\"Hello from Arduino!\"}";
    int httpResponseCode = http.POST(httpRequestData);

    if (httpResponseCode == 200) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
      String payload = http.getString();
      Serial.println(payload);
      tone(46, 500, 500);
      delay(1000);

      StaticJsonDocument<256> doc;
      DeserializationError error = deserializeJson(doc, payload);

        if (!error) {
          control1 = doc["control1"];
          control2 = doc["control2"];
          control3 = doc["control3"];
        }

        if (control1 >= 150) {
          digitalWrite(1, HIGH);
          o.write(180);
          delay(1000);
          o.write(0);
        } else {
          digitalWrite(1, LOW);
        }

        if (control2 >= 150) {
          digitalWrite(2, HIGH);
          oo.write(180);
          delay(1000);
          oo.write(0);
        } else {
          digitalWrite(2, LOW);
        }
        
        if (control3 >= 150) {
          digitalWrite(3, HIGH);
          ooo.write(180);
          delay(1000);
          ooo.write(0);
        } else {          
          digitalWrite(3, LOW);
        }

      delay(500);

    } else {
      Serial.print("Error code: ");
      Serial.print("Lunch from n8n");
      Serial.println(httpResponseCode);
        
    }
    http.end();
  
  }
  delay(1000); // Send every 10 seconds

}

Credits

Aiman Ansari
1 project • 0 followers
Ishan Mudgal
2 projects • 1 follower

Comments