Hi,
Here,I want to post some update about may Enchanted windows project. I was able to control window using arduino yun’s wi-fi.I was not sure about a actual window so I have tried with thermo Cole model.
Here I have used 150 RPM DC geared motor with Infineon DC motor control shield.pic connections are:
Digital 2 in yun -> IN1 in motor shield
Digital 3 in yun -> IN2 in motor shield
INH1 and INH2 were connected to 5V in yun. Also I have shorted GND of Infineon shield and yun as power for both board are different. Yun was powered by 5V supply and motor shield was powered by 12V supply same as motor supply.
Yun Software:
I have modified Bridge example as per my requirement. Using REST APIs I was able to control motor. Code is as below:
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
// Listen to the default port 5555, the Yún webserver
// will forward there all the HTTP requests you send
YunServer server;
boolean JustTwoSeconds;
void setup()
{
// Bridge startup
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);
// Listen for incoming connection only from localhost
// (no one from the external network could connect)
server.listenOnLocalhost();
server.begin();
// For Driving Motor We need this two pins.
pinMode( 2, OUTPUT ); //IN_1
pinMode( 3, OUTPUT ); //IN_2
}
void loop()
{
// Get clients coming from server
YunClient client = server.accept();
// There is a new client?
if (client)
{
// Process request
process(client);
// Close connection and free resources.
client.stop();
}
delay(50); // Poll every 50ms
if( JustTwoSeconds )
{
JustTwoSeconds = 0;
delay(4900); // 1.5 sec
digitalWrite( 2, LOW ); //IN_1
digitalWrite( 3, LOW ); //IN_2
}
}
void process(YunClient client) {
// read the command
String command = client.readStringUntil('/');
// is "digital" command?
if (command == "digital") {
digitalCommand(client);
}
// is "analog" command?
if (command == "analog") {
analogCommand(client);
}
// is "mode" command?
if (command == "mode") {
modeCommand(client);
}
}
void digitalCommand(YunClient client)
{
int pin, value;
// Read pin number
pin = client.parseInt();
if( pin == 1 )
{
digitalWrite( 2, HIGH ); //IN_1
digitalWrite( 3, LOW ); //IN_2
JustTwoSeconds = 1;
}
else if( pin == 2 )
{
digitalWrite( 2, LOW ); //IN_1
digitalWrite( 3, HIGH ); //IN_2
JustTwoSeconds = 1;
}
else if( pin == 3 )
{
digitalWrite( 2, LOW ); //IN_1
digitalWrite( 3, LOW ); //IN_2
}
else
{
;
}
}
HTML File:
For EASY interface I have created simple HTML file which you can open in any device. Code is as follow:
<body bgcolor = "yellow">
<a href = "http://192.168.240.1/arduino/digital/1 ">
<h3><center> OPEN WINDOW </center></h3>
</a>
</br>
</br>
<a href = "http://192.168.240.1/arduino/digital/2 ">
<h3><center> CLOSE WINDOW </center></h3>
</a>
</br>
</br>
<a href = "http://192.168.240.1/arduino/digital/3 ">
<h3><center> STOP </center></h3>
</a>
</body>
I will publish a video soon.
Top Comments