To blink LED from mobile phone or iPod or another computer via WiFi




Hello Everyone,
I like this site too much, the site really played very important role in awakening my enthusiasm and creativity.
This is my first project and its really for the first timers project.
I got this project from Instructible site , modified to access from web and mobile.
To blink LED from mobile phone or iPod or another computer via WiFi




My aim was to control some electronics from mobile.
I wanted to achieve it with existing devices from our daily use ,without buying any special circuit. Also want to keep it simple so that it would be easy for someone to start as his first project.

For the project we need,
Laptop with wifi capability
– Wify Lan
– Mobile phone or ipod with Wify Connectivity
– Visual Studio .net. (You can also develop it into jsp or java but I already have .net)
– Main component Arduino
– Led
– 1 k Registor
– Connecting Wires

Step 1:

Arduino Code
Upload following sketch to arduino . I am connecting LED to pin 8. You can modify it with the number you want to connect to.

//Arduino Control
int ledPin =  8;    // LED connected to digital pin 8
int incomingByte = 0; // for incoming serial data

// The setup() method runs once, when the sketch starts

void setup()   {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
if(incomingByte == 105){
digitalWrite(ledPin, HIGH);
}
else if(incomingByte == 111){
digitalWrite(ledPin, LOW);
}
}
}

Step 2:

The c# .net code
We are basically developing simple website which will be accessed by mobile or computer.
The website has “On” and “Off” button.
Following is the c# code

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO.Ports;

namespace DotNetControl
{
public partial class _Default : System.Web.UI.Page
{
SerialPort port = new SerialPort(“COM8”, 9600, Parity.None, 8, StopBits.One);
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (port.IsOpen)
{
port.Close();
}
}
catch (Exception exp)
{
Response.Write(exp.Message);
}
}

protected void btnOn_Click(object sender, EventArgs e)
{
if (port.IsOpen)
{
port.Close();
port.Open();
port.Write(“i”);
port.Close();
}
else
{
port.Open();
port.Write(“i”);
port.Close();
}
}

protected void btnOff_Click(object sender, EventArgs e)
{
if (port.IsOpen)
{
port.Close();
port.Open();
port.Write(“o”);
port.Close();
}
else
{
port.Open();
port.Write(“o”);
port.Close();
}
}
}
}

As you can see in the code above
protected void btnOn_Click(object sender, EventArgs e)
{
if (port.IsOpen)
{
port.Close();
port.Open();
port.Write(“i”);
port.Close();
}
else
{
port.Open();
port.Write(“i”);
port.Close();
}
}

I am making checks before opening the port , if the port is open then close it and again open it for sending .This is because in web application it always gives error that port is open or port can not be accessed and similar error though the port is available .
I tried to avoid these errors.

Step 3:

Step 3

Other part we need to take care is while deploying the website

 

For more detail: To blink LED from mobile phone or iPod or another computer via WiFi




Clip to Evernote

Leave a Comment

(Spamcheck Enabled)

Read previous post:
LED Strip Circuit
RGB LED Strip Circuit with Arduino

This Instructable covers the assembly of a circuit capable of PWM-ing (pulse width modulating) a high-power RGB LED strip and...

Close
Scroll to top