Project tutorial

IoT Web Server © LGPL

IoT showing how to control a stepper motor "knob" from a website with PHP sockets.

  • 2,491 views
  • 0 comments
  • 3 respects

Components and supplies

About this project

Overview

Internet of Things (IoT) is a new emerging technology these days. The IoT project refers to all physical objects (things) that are connected to each other using the Internet infrastructure.

Arduino board is one of the important objects in this ecosystem, since it facilitates us to connect and control different devices like sensors, LEDs, step motors, servos and mobile phones.

This tutorial describes how to create an Internet of Things with a PHP UDP and TCP server running on Website and Arduino:

Website Hosting using WAMP SERVER to Remote Control a Stepper Motor.

The objects can be in the same network for simplicity or in different networks for a more complexity. The idea is for the PHP SERVERS on the Web Page to send an UDP request to the Arduino using a very simple server in the Web Page with which the data is sent to a client (or clients). A very small and simple UDP client. The client runs in Arduino, accepting this type of UDP request which contains the current state of the motor movement.

If you like this idea you can access my web page at www.iotwebserver.xyz, register for free as a user and start using and enjoying IOT technology.

if for some reason the server is not available, let me know here or send me an email zavala.o.v.arturo@gmail.com

Code

ATmega32u4_IoTStepperKnob.cppArduino
/*
*	Author		: Zavala Ortiz Vicente Arturo.
*	language	: .cpp
*	Created		: 3/11/2015 11:56:57 AM
*	Name		: ATmega32u4_WiFiStepperKnob.cpp
*	Update		: 1/9/2017 02:29:15 PM
*	Description : wifi Socket Client
*/

#include <util/delay.h>
#include <stdlib.h>

#include "CC3000.h"
#include "CC3000_Client.h"
#include "AFMotor.h"
#include "common.h"

/*****		wifi Global Variables		*****/
// Connection info data lengths
#define MAX_MSG_LEN							100
#define DHT11_PIN							0
// Constants

char ap_ssid[]				= "SSID of network";	    // SSID of network
char ap_password[]		= "Password of network";	// Password of network

unsigned int ap_security	= WLAN_SEC_WPA2;	  // Security of network
unsigned long timeout		  = 3000;            	// Milliseconds

// Global Variables
CC3000 wifi						= CC3000();
CC3000_Client client  = CC3000_Client(wifi);

char in_message[MAX_MSG_LEN]	= {0};

/*****		Other Global Variables		*****/
static char page[20], data[20];
signed int option, value, out, stepper2_actual_value = 0;

void setup()
{
	/* add setup code here */
 	ConnectionInfo connection_info;
 
 	// Initialize CC3000 (configure SPI communications) 	
 	Serial.begin(115200);
 	 
 	// Initialize CC3000 (configure SPI communications)
 	if(!wifi.init(9)) {
 			Serial.println("Initialize CC3000 FAIL!");
 		return;
 	}

	else {
		Serial.println"Initialize CC3000 OK");
	}

	if(!wifi.connect(ap_ssid, ap_security, ap_password, timeout)) {	
		Serial.println("Error: Could not connect to AP!");
	}

	else
		return;
	
	
	_delay_ms(5000);
	
	// Gather connection details and print IP address
	if(!wifi.getConnectionInfo(connection_info) )
	{
		Serial.println("Error: Could not obtain connection details");
		return;
	}
	
	else 
	{	
		Serial.println("IP Address: ");
		printIPAddr(connection_info.ip_address);
	}

	_delay_ms(5000);
}

uint8_t i;

void loop()
{		
	/* add main program code here */
 	Serial.println("WAITING FOR MESSAGE!");

	flush_buffer(in_message);
	
	if(client.readfrom(4444, in_message, MAX_MSG_LEN) == -1) {
		Serial.println("NO MESSAGE RECEIVED");
	}
	
	Serial.println(in_message);
			

  if(client.readfrom(4444, in_message, MAX_MSG_LEN) == -1) {
	  Serial.println("NO MESSAGE RECEIVED");
  }

	else
	{
	  stepper2.setSpeed(200);

		if(http_gets(data, "stepper_motor2", in_message)) {
		  value = atoi(data);
							
			if(value > 0) {
				  stepper2.step(value, FORWARD, SINGLE);
			}

			else if (value < 0) {
				  stepper2.step(value, BACKWARD, SINGLE);				
			}
	}
	
	flush_buffer(in_message);
}

Custom parts and enclosures

IoTStepperMSchm
iotsteppermotorknob_WItZGDB1vf.sch

Schematics

IoTStepperMSchm
Iotsteppermschm tou6zv6wob

Comments

Similar projects you might like

Obstacle Avoidance for 3DR Solo

Project tutorial by Stephan

  • 3,732 views
  • 2 comments
  • 28 respects

Smart Car Working By Movement Of The Finger

Project showcase by Hesham99900999

  • 263 views
  • 0 comments
  • 1 respect

Kayak GPS Navigation

Project in progress by Chrisroy

  • 800 views
  • 0 comments
  • 4 respects

Slo-Mo Frame Optical Illusion Arduino Nano

Project in progress by WannaDuino

  • 73 views
  • 0 comments
  • 0 respects

Turn Walabot into a "Why-Not?" Bot for the Disabled/Elderly

Project in progress by Eric Olson

  • 549 views
  • 0 comments
  • 5 respects

I Let Everyone on the Internet Control My X-Mas Decoration

Project showcase by Tobi_Lxtr

  • 4,345 views
  • 7 comments
  • 37 respects
Add projectSign up / Login