Wednesday, August 17, 2011
Arduino - TVOut Library
I love that the community around the Arduino way smarter than I am.
How about connecting your Arduino to your TV (Composite - yellow wire) with just a connector cable and 2 resistors for the circuit.
The following YouTube video shows it running Tetris. Also, in the description for the video is a link to the code.
I don't know who mdmetzle is but they are definitely way smarter than I am and might cause me to not get rid of the crappy 14" TV we have sitting around gathering lots of dust.
Who'd have thought that such a little board would provide som much fun.
Thursday, July 14, 2011
Arduino - Web server controlled LED using serial connection between the Arduino and web server
I was chatting to a friend who was working on home automation. Controlling lights, heating and other stuff around the house using a touch screen controller and I thought if you used a web site as the interface then connected to the Arduino over a serial link it would be possible to switch things on and off from any devlice that could display a web page and access the web server.
Personally, I would not recommend using a serial link from the server to the Arduino as the Arduino resets itself everytime something is sent over serial, More correctly an ethernet shield would be great. Giving more scalability as the web server can talk to mutliple Arduinos with no great extra effort.
I installed XAMPP on my netbook as the webserver and used PHP code on the server to present the web interface and send the command to the Arduino over serial. The Arduino is waiting for a serial command and then depending on what it is will turn on or off the mounted LED.
So, not the most impressive looking demo, but as a proof of concept if I can turn on a LED I can control a relay to turn on an kind of device.
Below is the code. Be aware I'm more about getting the Arduino to do something and so the code will be a bit rough around the edges. It works but I definitely do not consider it best practise or even efficent code.
Use at your own risk.
PHP on the server:
Arduino Code:
Personally, I would not recommend using a serial link from the server to the Arduino as the Arduino resets itself everytime something is sent over serial, More correctly an ethernet shield would be great. Giving more scalability as the web server can talk to mutliple Arduinos with no great extra effort.
I installed XAMPP on my netbook as the webserver and used PHP code on the server to present the web interface and send the command to the Arduino over serial. The Arduino is waiting for a serial command and then depending on what it is will turn on or off the mounted LED.
So, not the most impressive looking demo, but as a proof of concept if I can turn on a LED I can control a relay to turn on an kind of device.
Below is the code. Be aware I'm more about getting the Arduino to do something and so the code will be a bit rough around the edges. It works but I definitely do not consider it best practise or even efficent code.
Use at your own risk.
PHP on the server:
<?php
exec('mode com4: baud=9600 data=8 stop=1 parity=n xon=no');
$switch1 = "";
/* Serial script for pan/tilt Camera with servos */
/* Script by Aneal Khimani, 2-12-10 */
//check the GET action SuperGlobal var to see if an
//action is to be performed
if (isset($_GET['action'])) {
$switch1 = $_GET['action'];
//Action required
switch ($switch1) {
case "on":
$fp = fopen("com4", "w");
fwrite($fp, chr(97));
fclose($fp);
break;
case "off":
$fp = fopen("com4", "w");
fwrite($fp, chr(98));
fclose($fp);
break;
}
}
?>
<html>
<body>
<center>
<p>
<font size="4">Flick Switch</font><br />
<table width="30">
<tr><td><a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>">On</a></td><td><?php if($switch1 == 'on'){echo "<b>ON</b>";} ?></td></tr>
<tr><td><a href="<?=$_SERVER['PHP_SELF'] . "?action=off" ?>">Off</a></td><td><?php if($switch1 == 'off'){echo "<b>OFF</b>";} ?></td></tr>
</table>
</p>
</center>
</body>
</html>
Arduino Code:
/*
Used with the PHP code
http://localhost/arduino.php
*/
void setup() {
Serial.begin(9600); // initialize serial communication:
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
// read the serial port:
if (Serial.available() > 0) {
int inByte = Serial.read();
switch (inByte) {
case 'a':
digitalWrite(13, HIGH); // set the LED on
Serial.println("HIGH");
break;
case 'b':
digitalWrite(13, LOW); // set the LED off
Serial.
println("LOW");
break;
}
}
}
Wednesday, June 8, 2011
Arduino Servo mounted maze controlled by 4 buttons
OK, this one is a bit less impressive than I wanted it to be. Then I found out that really cheap servos cannot take the weight of a decent sized maze. So, plan B was to use a small maze as a 'proof of concept'.
Using 4 buttons for up, down, left and right to move the maze to get the bead from the start to the finish.
The code (which is below) is actually quite straight forward. Most of my time was spend gluing bits of cardbaord together to make the various bits that are needed to mount the servos and the maze itself..
In case you need recommends on cardbaord the box that the bumper packs of pampers nappies come in are ideal. (yes I have small kids)
Below is the code. Be aware I'm more about getting the Arduino to do something and so the code will be a bit rough around the edges. It works but I definitely do not consider it best practise or even efficent code.
Use at your own risk.
Using 4 buttons for up, down, left and right to move the maze to get the bead from the start to the finish.
The code (which is below) is actually quite straight forward. Most of my time was spend gluing bits of cardbaord together to make the various bits that are needed to mount the servos and the maze itself..
In case you need recommends on cardbaord the box that the bumper packs of pampers nappies come in are ideal. (yes I have small kids)
Below is the code. Be aware I'm more about getting the Arduino to do something and so the code will be a bit rough around the edges. It works but I definitely do not consider it best practise or even efficent code.
Use at your own risk.
// Balance Table for Maze
// Winkleink
// 2011
// Pin 7 Left
// Pin 6 Right
//Pin 5 Up
//Pin 4 Down
// Pin 10 Servo - Up/Down
// Pin 9 Servo - Left/Right
// Library that makes working with Servos easier
#include <Servo.h>
// Set Button variables
int bLeft = 5; // Left Button
int bRight = 4; // Right Button
int bUp = 7; // Up Button
int bDown = 6; // Down Button
// Set Servo variables
Servo servoUD; // Servo Up/Down on Pin 10
Servo servoLR; // Servo Left/Right on Pin 9
//Set Servo position variables
int posUD = 100; // variable to store the Up/Down servo position
int posLR = 100; // variable to store the Left/Right servo position
void setup()
{
servoUD.attach(10); // attaches the servo on pin 10 to the servo object
servoLR.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(bLeft,INPUT); // bLeft - Left Button
pinMode(bRight,INPUT); // bRight - Right Button
pinMode(bUp,INPUT); // bUp - Up Button
pinMode(bDown,INPUT); // bDown - Down Button
}
void loop()
{
// Position the Serrvo
// As the initial variable are center this also centers the table when it starts
servoUD.write(posUD);
servoLR.write(posLR);
if (digitalRead(bLeft) == HIGH){
posLR--;
}
if (digitalRead(bRight) == HIGH){
posLR++;
}
if (digitalRead(bUp) == HIGH){
posUD--;
}
if (digitalRead(bDown) == HIGH){
posUD++;
}
delay(50);
}
Subscribe to:
Posts (Atom)