Arduino Yun: Light Control

This is a proof of concept for setting up the newly released arduino Yun as light controller. A web server was setup on arduino Yun with support of MySQL and PHP. Light status is controlled with MySQL queries and even when a button is pressed triggers an SQL query, this is the advantage  of Arduino Yun’s Bridge, you can interact between the ATmega 32U4 (Arduino side) and the Linino AR9331(Linux side). Below are some pictures of the setup and also a demo video.

DSC_0053 DSC_0055 home_automation_bb 

Before proceeding with the setup I have to mention that at the moment I bypassed the security aspect of this project.

Use it at your own risk. If this is going to be in public you are exposed and vulnerable in attacks.

Setup of the Linino (Linux) side of arduino:

Download all necessary files from the below link:

  • Install LAMP stack following the below website:

  • Download the below file and put then in the desired folder of the webserver running on Arduino (skip downloading if you already downloaded the files from the first step):

Web Interface

I created the homeautomation database and the LEDstatus and webstatus tables as below :

LEDstatus table:

 Field  Type  Null  Key  Default  Extra
 id  int(2)  NO  PRI  NULL  auto_increment
 name  varchar(15)  YES  NULL
 LEDstatus  varchar(5)  YES  NULL
 pin  int(2)  YES  NULL
 pinOut  int(2)  YES  NULL

..and added two entries in the LEDstatus table:

 id  name  LEDstatus  pin  pinOut
1  LED1 -1 2 8
2  LED2 -1 3 9
    webstatus table:
 Field  Type  Null  Key  Default  Extra
 status  int(1)  YES  NULL
  • Create some bash scripts for different mysql queries and place them in the root folder  (skip downloading if you already downloaded the files from the first step) :


  • Download the arduino sketch  (skip downloading if you already downloaded the files from the first step):

Arduino sketch

Many thanks to the below:


14 thoughts on “Arduino Yun: Light Control

    • In the root directory of root user (as you can see in the sketch there’s a command “mysql.runShellCommand(“sh ~/ -1 “+ledid);”) so you can put those scripts anywhere you want just be sure that in arduino sketch you have declared the correct directory for each script.

      • I actually use xampp control panel. i put the sh files on the htdocs. the led on the index.html dont turn on when i turn on the tack switch on the arduino. why?

  1. when I do all of this and open the page I see this (see below)in the screen and the red and green button are blinking what do I wrong?
    I create the same tables in my database and put in the good login name and password.

    “); $echo (”
    “); $row=mysql_fetch_array($result); $ledname=$row[name]; $echo stripslashes($ledname); $echo ”

    “; $if ($row[LEDstatus]==1) { $echo (“GREEN BLINKING”); $echo (“Submit Form”); } $if ($row[LEDstatus]==-1) { $echo (“”); $echo (“Submit Form”); } $echo (“RED BLINKING”); $i=$i+1; } ?>

  2. This is a good article and everything but there are two boards that you are using here. One is the ardiuno yun and the other is what?

    Also, you don’t really note whether you need to do any kind of config on the daughter board? (whatever it is)

  3. Counting the breadboard, then there are three boards. One white breadboard and two blue boards. In the first picture you can see them. The blue boards don’t appear to be connected to each other. Obviously one of the two blue boards is the arduino yun but what is the other one?

  4. Hi ,
    I try to do this tutorial but it does not work.
    I can turn on and off the LEDs from the interface, but on the breadboard nothing happens.

    I checked the tables work, the status values change.

    Does anyone have an idea ?

    Thank you

  5. Hey guys,
    Has someone already made this project with 4 LEDs for example ?
    We had only to add a line to the LEDstatus table and report the new in- and out-pin ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s