Kutluhan Aktar
Published © CC BY-NC

IoT Modified Action-Man Figure with Laser Beams

Activate two laser modules fastened to each arm of a dilapidated Action-Man figure and control an LED as background lighting via ESP8266.

AdvancedFull instructions provided2 hours603
IoT Modified Action-Man Figure with Laser Beams

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Laser Module KY-008
×2
RGB Diffused Common Anode
RGB Diffused Common Anode
×1
SparkFun Solder-able Breadboard - Mini
SparkFun Solder-able Breadboard - Mini
×3
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE
TheAmplituhedron Data Panel

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

Fritzing File

Schematics

Schematic

Code

Source Code

Arduino
         ////////////////////////////////////////////////////  
        //      IoT Modified Action-Man Figure with       //
       //                 Laser Beams                    // 
      //          ----------------------------          //
     //              NodeMCU (ESP-12E)                 //           
    //               by Kutluhan Aktar                // 
   //                                                //
  ////////////////////////////////////////////////////

// By only subscribing to TheAmplituhedron, you can send data packets to NodeMCU(ESP8266) without creating a web server, or any other micro-controller, from your Data Panel on your account page.
// TheAmplituhedron Data Panel is a web application(available system) for TheAmplituhedron subscribers only, which is designed for sending information to micro-controllers automatically.
// Follow the steps down below to create your data panel connection path on which you will be able to send data packets to NodeMCU.
// 1) Go to your Dashboard.
// 2) Click IoT Data Panel under Available Systems.
// 3) Read the given instructions to better comprehend the application.
// 4) Just enter inputs to send information.
// As TheAmplituhedron API creates your connection path, you can get data packets from web by entering your WiFi settings and required information down below.
//
// As a reminder, my website has SSL protection so that you need to identify your NodeMCU connection by entering TheAmplituhedron FingerPrint or ThumbPrint.
// You can learn about it more from the link below.
// https://www.theamplituhedron.com/projects/IoT-Modified-Action-Man-Figure-with-Laser-Beams/
//
// Connections
// NodeMCU (ESP-12E) :           
//                                Laser Module(Right)
// D0 --------------------------- S
//                                Laser Module(Left)
// D1 --------------------------- S
//                                RGB LED(Anode)
// D2 --------------------------- 
// 3.3V ------------------------- 
// D3 --------------------------- 
// D4 --------------------------- 


// Include required libraries to get data from your data panel connection page.
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h> 
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>

// Define your WiFi settings.
const char *ssid = "SSID";
const char *password = "PASSWORD";
// Connect TheAmplituhedron.com with the current fingerprint.
const char *host = "www.theamplituhedron.com"; 
const char fingerprint[] PROGMEM = "46 3c 5c 2c 67 11 cd 88 b7 e9 76 74 41 34 48 bd bc a5 b9 cf";
const int httpsPort = 443;

// Create data holders to get data packets.
String connectionPath, URL, HEDRON, readString;
String Switch, Range, Message;

// Define Laser Pins.
#define Laser_Right D0
#define Laser_Left D1

// Define RGB Pins.
#define red D2
#define blue D3
#define green D4

void setup() {
  pinMode(Laser_Right, OUTPUT);
  pinMode(Laser_Left, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
  
  // Wait until connected.
  Serial.begin(115200);
 
  // It is just for assuring that if the connection is alive.
  WiFi.mode(WIFI_OFF);
  delay(1000);
  // This mode allows NodeMCU to connect any WiFi directly.
  WiFi.mode(WIFI_STA);        
  // Connect NodeMCU to your WiFi.
  WiFi.begin(ssid, password);
  
  Serial.print("\n\n");
  Serial.print("Try to connect to WiFi. Please wait! ");
  Serial.print("\n\n");
  // Halt the code until connected to WiFi.
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("*");
  }
 
  // If connection is successful, write WiFi SSID to serial monitor along with assigned IPAddress.
  Serial.print("\n\n");
  Serial.print("-------------------------------------");
  Serial.print("\n\n");
  Serial.print("Connection is successful!");
  Serial.print("\n\n");
  Serial.print("Connected WiFi SSID : ");
  Serial.print(ssid);
  Serial.print("\n\n");
  Serial.println("Connected IPAddress : ");
  //Serial.println(WiFi.localIP());
  Serial.print("\n\n");

  // Give time to ESP8266 for rebooting properly.
  delay(3000);

  // Turn off Lasers.
  digitalWrite(Laser_Right, LOW);
  digitalWrite(Laser_Left, LOW);

}

void loop() {
  
  // Define your data panel connection path.
  URL = "/dashboard/Data-Panel/";
  HEDRON = "your hedron";
  connectionPath = URL + HEDRON + ".php"; 
  
  // Create a WiFi Client to get form information.
  WiFiClientSecure client;
  // Set the fingerprint to connect TheAmplituhedron API.
  client.setFingerprint(fingerprint);
  // If the host is not responding,return.
  if(!client.connect(host, httpsPort)){
    Serial.println("Connection Failed!");
    return;
  }
  
  // Send a GET request to the connection path to receive variables.
  client.print(String("GET ") + connectionPath + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
  // Detect whether client is responding properly or not.
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
       Serial.println(">>> Client Timeout !");
       client.stop();
       return;
    }
  }  
             
  // Save variables from the connecion path form inputs.
  while(client.available()){
      // By using the plus character, get whole response without dealing with the headers.
      readString = client.readStringUntil('+');
      // Split the response by a pre-defined delimiter in a simple way. '%'(percentage) is defined as the delimiter by TheAmplituhedron API for this project.
      int delimiter, delimiter_1, delimiter_2, delimiter_3;
      delimiter = readString.indexOf("%");
      delimiter_1 = readString.indexOf("%", delimiter + 1);
      delimiter_2 = readString.indexOf("%", delimiter_1 +1);
      delimiter_3 = readString.indexOf("%", delimiter_2 +1);
      // Define variables to be executed on the code later.
      Switch = readString.substring(delimiter + 1, delimiter_1);
      Range = readString.substring(delimiter_1 + 1, delimiter_2);
      Message = readString.substring(delimiter_2 + 1, delimiter_3);
  }

  // View the received form inputs on the serial monitor.
  Serial.println(Switch + '\n' + Range + '\n' + Message + "\n--------------------\n");

  // Activate Laser Patterns depending on the Range. If the Range is smaller than 180, control Lasers with the Switch.
  if(Range.toInt() < 180){
      if(Switch == "ON"){
        digitalWrite(Laser_Right, HIGH);
        digitalWrite(Laser_Left, HIGH);
      }else if(Switch == "OFF"){
        digitalWrite(Laser_Right, LOW);
        digitalWrite(Laser_Left, LOW);  
      }
  }else{
    for(int i =0;i<=Range.toInt();i++){
       digitalWrite(Laser_Right, HIGH);
       delay(500);
       digitalWrite(Laser_Right, LOW);
       delay(500);      
    }

  }

  // Select RGB colors using the color names - from Message.
  if(Message == "RED"){
      digitalWrite(red, LOW);
      digitalWrite(blue, HIGH);
      digitalWrite(green, HIGH);
  }else if(Message == "BLUE"){
      digitalWrite(red, HIGH);
      digitalWrite(blue, LOW);
      digitalWrite(green, HIGH);
  }else if(Message == "GREEN"){
      digitalWrite(red, HIGH);
      digitalWrite(blue, HIGH);
      digitalWrite(green, LOW);
  }else if(Message == "YELLOW"){
      digitalWrite(red, LOW);
      digitalWrite(blue, HIGH);
      digitalWrite(green, LOW);
  }else if(Message == "MAGENTA"){
      digitalWrite(red, LOW);
      digitalWrite(blue, LOW);
      digitalWrite(green, HIGH);
  }else if(Message == "CYAN"){
      digitalWrite(red, HIGH);
      digitalWrite(blue, LOW);
      digitalWrite(green, LOW);
  }

  // Wait for the next request.
  delay(1000);
}

Credits

Kutluhan Aktar

Kutluhan Aktar

79 projects • 291 followers
Self-Taught Full-Stack Developer | @EdgeImpulse Ambassador | Maker | Independent Researcher

Comments