Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Wi-Fi Controlled Smart Target System with ESP8266 and NeoPixel Ring

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled Smart Target System with ESP8266 and NeoPixel Ring

Circuit Documentation

Summary

This document provides a detailed overview of a circuit that includes various sensors, a NeoPixel ring, a piezo buzzer, an RS-485 module, and an ESP8266 NodeMCU microcontroller. The circuit is designed to detect sound and vibration, control LEDs, and communicate over a network.

Component List

Adafruit 16 NeoPixel Ring

Piezo Buzzer

SW-420 Vibration Sensor

RS-485 Module

Sound Sensor

Mini 560 Step Down 20-7V to 5V

RJ45

ESP8266 NodeMCU

Wiring Details

Adafruit 16 NeoPixel Ring

Piezo Buzzer

SW-420 Vibration Sensor

RS-485 Module

Sound Sensor

Mini 560 Step Down 20-7V to 5V

RJ45

ESP8266 NodeMCU

Code Documentation

Main Code

#include <Arduino.h>
#include <FastLED.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncWebServer.h>
#include <painlessMesh.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include <LittleFS.h>

// Configurazione generale
#define LED_PIN 14
#define NUM_LEDS 16
#define PIEZO_PIN 12
#define SOUND_PIN 13
#define SHOCK_PIN 15
#define WIFI_SSID "ETT_SHADOWS"
#define WIFI_PASSWORD "shadowsasdlocorotondo"
#define AP_SSID "TARGET_AP"

CRGB leds[NUM_LEDS];
AsyncWebServer server(80);
painlessMesh mesh;
WiFiClient client;

// Stati
enum TargetState { CHECK, READY, WAKE, TAKEN, SLEEP };
TargetState currentState = CHECK;

unsigned long lastStateChange = 0;
const unsigned long stateTimeout = 60000; // 1 minuto
unsigned long wakeStartTime = 0;

// Bersaglio configurazioni
typedef struct {
    String id;
    String sensorType;
    String waitColor;
    String takenColor;
    int timeout;
} TargetConfig;

TargetConfig config = {
    "target_01",       // ID del bersaglio
    "sound",           // Tipo di sensore
    "#00FF00",         // Colore LED in attesa
    "#FF0000",         // Colore LED colpito
    10                 // Timeout in secondi
};

// Funzioni per rete Mesh
void meshCallback(uint32_t nodeId) {
    Serial.printf("Evento nella rete mesh: Nodo %u si รจ connesso o disconnesso.\n", nodeId);
}

// Funzioni Wi-Fi
void setupWiFi() {
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.println("Tentativo di connessione WiFi...");

    unsigned long startAttempt = millis();
    while (WiFi.status() != WL_CONNECTED && millis() - startAttempt < stateTimeout) {
        unsigned long elapsed = millis() - startAttempt;
        int ledsToLight = map(elapsed, 0