Created by Dewu Han and Tony Chen
This is our project management and Gantt char of our porject
Our original project is to control a lamp over the internet with an Arduino over web-interface, but we have upgraded our Project to work as multifunction Christmas decorating light
The Hardware
- A Computer
- A External Hard Drive
- A Linux Web-Server with PHP
- An Arduino Uno
- Breadboard & Jumpers
- LEDs & Bulb
The program and codes
- Server terminal configuration and commands
sean127@sean127:~$ sudo su
[sudo] password for sean127:
root@sean127:/home/sean127# vi /var/www/example.php
root@sean127:/home/sean127# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1079 errors:0 dropped:0 overruns:0 frame:0
TX packets:1079 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:91239 (91.2 KB) TX bytes:91239 (91.2 KB)
root@sean127:/home/sean127# sudo usermod -a -G dialout sean127
root@sean127:/home/sean127# sudo chmod a+rw /dev/ttyACM0
root@sean127:/home/sean127# /etc/init.d/apache2 restart
* Restarting web server apache2 ... waiting [ OK ]
root@sean127:/home/sean127# chmod 777 -R /var/www/
root@sean127:/home/sean127# /etc/init.d/apache2 restart
* Restarting web server apache2 ... waiting [ OK ]
The server is called LAMP server, it stands for Linux, Apache, MySQL, and Php. Although MySQL is installed on the server, but this project works without one. we ran several commands on the server, and the following are the most important ones.
check which port arduino is connected:
dmesg
to authorize data transmission for the usb port “ttyACM0”
sudo usermod -a -G dialout sean127
sudo chmod a+rw /dev/ttyACM0
restart apache
/etc/init.d/apache2 restart
the required web files are stored in the directory /var/www/
to create permission for php file to read and write to the text file we use this:
chmod 777 -R /var/www/
check ip of the server
ifconfig
- Arduino Code
int timer = 200; // The higher the number, the slower the timing.
char inByte = 0;
char code = '0';
int led = 13;
int thisPin2 =2;
int thisPin3 =3;
int thisPin4 =4;
int thisPin5 =5;
int thisPin6 =6;
int thisPin7 =7;
int thisPin8 =8;
void setup(){
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(thisPin2, OUTPUT);
pinMode(thisPin3, OUTPUT);
pinMode(thisPin4, OUTPUT);
pinMode(thisPin5, OUTPUT);
pinMode(thisPin6, OUTPUT);
pinMode(thisPin7, OUTPUT);
pinMode(thisPin8, OUTPUT);
}
void loop()
{
if (Serial.available() > 0) {
inByte = Serial.read();
}
else {
inByte = code;
}
Serial.println(inByte);
if(inByte == ‘1’){
leds();
code = ‘1’;
}
else if(inByte == ‘0’){
code = ‘0’;
}
else if(inByte == ‘2’){
digitalWrite(led,HIGH);
}
else if(inByte == ‘3’){
digitalWrite(led,LOW);
}
}
void leds()
{
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin < 9; thisPin++) { // turn the pin on: digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); } // loop from the highest pin to the lowest: for (int thisPin = 8; thisPin >= 2; thisPin–) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
- PHP Code for web interface
- PHP serial class
http://code.google.com/p/php-serial/
Sample Code
deviceOpen(); // To write into
$serial->sendMessage("Hello !"); // Or to read from
$read = $serial->readPort(); // If you want to change the configuration, the device must be closed $serial->deviceClose(); // We can change the baud rate $serial->confBaudRate(2400); // etc... ?>
PHP_serial.class.php can be used to communicate with a serial port under Linux, OSX, or Windows. It takes the path of serial device and checks whether it is valid before opening a connection to it. It will read and send data to the serial port once the connection is opened.
Arduino and Relay connection
The circuit:
The proper way to drive Relays with the Arduino