Project tutorial

IoT Web Server © LGPL

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

  • 1,246 views
  • 0 comments
  • 3 respects

Components and supplies

About this project

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

Custom parts and enclosures

IoTStepperMSchm
iotsteppermotorknob_WItZGDB1vf.sch

Schematics

IoTStepperMSchm
Iotsteppermschm tou6zv6wob

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);
}

Comments

Similar projects you might like

Measure and Analyze Tide Levels with ThingSpeak and MATLAB

Project tutorial by Team MATLAB IoT

  • 2,393 views
  • 0 comments
  • 16 respects

Helping the Disabled and Chronic Patients battle the heat

Project tutorial by Manan Rai

  • 470 views
  • 0 comments
  • 6 respects

Drive with PID Control on an Arduino Mega 2560

Project tutorial by Team MATLAB Makers

  • 2,334 views
  • 0 comments
  • 6 respects

Bluetooth MIDI-Operated Antique Reed Organ

Project in progress by Willem Hillier

  • 2,338 views
  • 0 comments
  • 10 respects

CUTSIE WHUN Version 2 - The Ultimate Balancing Robot

Project in progress by Pigeon-Kicker

  • 149 views
  • 0 comments
  • 1 respect

AutoHome - Internet of Things (IoT) for Home Automation

Project showcase by Team AutoHome

  • 160 views
  • 0 comments
  • 0 respects
Add projectSign up / Login