Posts with «ikea» label

Ikea Standing Desk Goes Dumb to Smart on LIN Bus

IKEA’s products are known for their clean, Scandinavian design and low cost, but it is their DIY or “assemble it yourself” feature that probably makes them so popular with hackers. We seem to receive tips about IKEA hacks with a consistent regularity. [Robin Reiter] has a Bekant Sit/Stand motorized table with buttons to raise and lower the surface, but it doesn’t have any memory presets. That’s a shame because it requires a lot of fiddling with the up/down buttons to get it right every time. It would be nice to press a button, go grab a Coffee, and come back to find it adjusted at the desired height. With a little bit of hacking, he was able to not only add memory preset buttons, but also a USB interface for future computer control.

The existing hardware consists of a PIC16LF1938 micro-controller with two buttons for movement control and a LIN bus  protocol which communicates with the automotive grade motors with integrated encoders that report position values. After a bit of sniffing around with his oscilloscope and analyzer, he was able to figure out the control codes for the motor movements. For some strange reason, however, the LIN signals were inverted, so he had to introduce a transistor signal inverter between the PIC master and the Arduino Nano that would act as a slave LIN node. Software was made much easier thanks to an Arduino library developed by [Zapta] for the LIN Bus signal Injector, The controls now have four buttons — two to replicate the original up/down movements, and the other two to act as memory presets.

The code, schematic and a simple wiring layout are posted on Github, in case there are others out there who’d like to replicate this hack. Check out the video after the break where he gives a walk through the code.


Filed under: hardware, home hacks

Transform an Ikea Side Table into a Music Visualizer

Use some LEDs to upgrade a $10 Ikea side table into a centerpiece that bumps and jives to the beat of your tunes. Get your freq on!

Read more on MAKE

The post Transform an Ikea Side Table into a Music Visualizer appeared first on Make: DIY Projects and Ideas for Makers.

Control your Arduino over the Internet using Blynk

Introduction

There are many ways of remotely-controlling your Arduino or compatible hardware over the Internet. Some are more complex than others, which can be a good thing or a bad thing depending on your level of expertise. Lately we’ve become more interested in this topic and have come across Blynk, which appeared to be a simple solution – and thus the topic of our review.

What is Blynk?

From their website: “Blynk is a Platform with iOS and Android apps to control Arduino, Raspberry Pi and the likes over the Internet. It’s a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets. 

It’s really simple to set everything up and you’ll start tinkering in less than 5 mins. Blynk is not tied to some specific board or shield. Instead, it’s supporting hardware of your choice. Whether your Arduino or Raspberry Pi is linked to the Internet over Wi-Fi, Ethernet or this new ESP8266 chip, Blynk will get you online and ready for the Internet Of Your Things.” Here is the original launch video:

 

Blynk started off as an idea, and raised initial funding through Kickstarter – which was successful and the system has now launched. Blynk comprises of an app on your smartphone (Android or iOS) inside which you can add widgets (controls) to send commands back to your development board (Arduino etc.).

For example, you can add a switch to turn a digital output on or off. Furthermore, data from sensors connected to the development board can be send back to the smartphone. The data passes through the Blynk Cloud server, or you can download and run your own server on your own hardware and infrastructure.

How much does it cost?

Right now (September 2015) the Blynk system is free. We downloaded the app and experimented without charge. We believe that over time there will be payment required for various functions, however you can try it out now to see if Blynk suits your needs then run with it later or experiment with other platforms.

Getting Started

Well enough talk, let’s try Blynk out. Our hardware is an Android smartphone (the awesome new Oppo R7+) for control, and a Freetronics EtherTen connected to our office modem/router:

You can also use other Arduino+Ethernet combinations, such as an Arduino Uno with an Ethernet shield. First you need to download the app for your phone – click here for the links. Then from the same page, download the Arduino library – and install it like you would any other Arduino library.

For our first example, we’ll use an LED connected to digital pin 7 (via a 560 ohm resistor) shown above. Now it’s time to set up the Blynk app. When you run the app for the first time, you need to sign in – so enter an email address and password:

Then click the “+” at the top-right of the display to create a new project, and you should see the following screen:

You can name your project, select the target hardware (Arduino Uno) – then click “E-mail” to send that auth token to yourself – you will need it in a moment. Then click “Create” to enter the main app design screen. Next, press “+” again to get the “Widget Box” menu as shown below, then press “Button”:

This will place a simple button on your screen:

Press the button to open its’ settings menu:

From this screen you can name your button, and also determine whether it will be “momentary” (i.e., only on when you press the button) – or operate as a switch (push on… push off…). Furthermore you need to select which physical Arduino pin the button will control – so press “PIN”, which brings up the scrolling menu as shown below:

We set ours to D7 then pressed “Continue”. Now the app is complete. Now head back to your computer, open the Arduino IDE, and load the “Arduino_Ethernet” sketch included with the library:

Then scroll down to line 30 and enter the auth key that was sent to you via email:

Save then upload the sketch to your Arduino. Now head back to your smartphone, and click the “Play” (looks like a triangle pointing right) button. After a moment the app will connect to the Blynk server… the Arduino will also be connected to the server – and you can press the button on the screen to control the LED.

And that’s it – remote control really is that easy. We’ve run through the process in the following short video:

Now what else can we control? How about some IKEA LED strips from our last article. Easy… that consisted of three digital outputs, with PWM. The app resembles the following:

… and watch the video below to see it in action:

Monitoring data from an Arduino via Blynk

Data can also travel in the other direction – from your Arduino over the Internet to your smartphone. At the time of writing this (September 2015) you can monitor the status of analogue and digital pins, and widgets can be added in the app to do just that. They can display the value returned from each ADC, which falls between zero and 1023 – and display the values in various forms – for example:

The bandwidth required for this is just under 2 K/s, as you can see from the top of the image above. You can see this in action through the video below:

Conclusion

We have only scratched the surface of what is possible with Blynk – which is an impressive, approachable and usable “Internet of Things” platform. Considering that you can get an inexpensive Android smartphone or tablet for under AU$50, the overall cost of using Blynk is excellent and well worth consideration, even just to test out the “Internet of Things” buzz yourself. So to get started head over to the Blynk site.

And finally a plug for our own store – tronixlabs.com – which along with being Australia’s #1 Adafruit distributor, also offers a growing range and Australia’s best value for supported hobbyist electronics from DFRobot, Freetronics, Seeedstudio and much much more.

As always, have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our forum – dedicated to the projects and related items on this website.

The post Control your Arduino over the Internet using Blynk appeared first on tronixstuff.

Tronixstuff 20 Sep 09:30

Experimenting with Arduino and IKEA DIODER LED Strips

Introduction

A few weeks ago I found a DIODER LED strip set from a long-ago trek to IKEA, and considered that something could be done with it.  So in this article you can see how easy it is to control the LEDs using an Arduino or compatible board with ease… opening it up to all sorts of possibilities.

This is not the most original project – however things have been pretty quiet around here, so I thought it was time to share something new with you. Furthermore the DIODER control PCB has changed, so this will be relevant to new purchases. Nevertheless, let’s get on with it.

So what is DIODER anyhow? 

As you can see in the image below, the DIODER pack includes four RGB LED units each with nine RGB LEDs per unit. A controller box allows power and colour choice, a distribution box connects between the controller box and the LED strips, and the whole thing is powered by a 12V DC plugpack:

The following is a quick video showing the DIODER in action as devised by IKEA:

 

Thankfully the plugpack keeps us away from mains voltages, and includes a long detachable cable which connects to the LED strip distribution box. The first thought was to investigate the controller, and you can open it with a standard screwdriver. Carefully pry away the long-side, as two clips on each side hold it together…


… which reveals the PCB. Nothing too exciting here – you can see the potentiometer used for changing the lighting effects, power and range buttons and so on:

Our DIODER has the updated PCB with the Chinese market microcontroller. If you have an older DIODER with a Microchip PIC – you can reprogram it yourself.

The following three MOSFETs are used to control the current to each of the red, green and blue LED circuits. These will be the key to controlling the DIODER’s strips – but are way too small for me to solder to. The original plan was to have an Arduino’s PWM outputs tap into the MOSFET’s gates – but instead I will use external MOSFETs.

So what’s a MOSFET?

In the past you may have used a transistor to switch higher current from an Arduino, however a MOSFET is a better solution for this function. The can control large voltages and high currents without any effort. We will use N-channel MOSFETs, which have three pins – Source, Drain and Gate. When the Gate is HIGH, current will flow into the Drain and out of the Gate:

A simplistic explanation is that it can be used like a button – and when wiring your own N-MOSFET a 10k resistor should be used between Gate and Drain to keep the Gate low when the Arduino output is set to LOW (just like de-bouncing a button). To learn more about MOSFETS – get yourself a copy of “The Art of Electronics“. It is worth every cent.

However being somewhat time poor (lazy?), I have instead used a Freetronics NDrive Shield for Arduino – which contains six N-MOSFETs all on one convenient shield  – with each MOSFET’s Gate pin connected to an Arduino PWM output.

So let’s head back to the LED strips for a moment, in order to determine how the LEDs are wired in the strip. Thanks to the manufacturer – the PCB has the markings as shown below:

They’re 12V LEDs in a common-anode configuration. How much current do they draw? Depends on how many strips you have connected together…

For the curious I measured each colour at each length, with the results in the following table:

So all four strips turned on, with all colours on – the strips will draw around 165 mA of current at 12V. Those blue LEDs are certainly thirsty.

Moving on, the next step is to connect the strips to the MOSFET shield. This is easy thanks to the cable included in the DIODER pack, just chop the white connector off as shown below:

By connecting an LED strip to the other end of the cable you can then determine which wire is common, and which are the cathodes for red, green and blue.

The plugpack included with the DIODER pack can be used to power the entire project, so you will need cut the DC plug (the plug that connects into the DIODER’s distribution box) off the lead, and use a multimeter to determine which wire is negative, and which is positive.

Connect the negative wire to the GND terminal on the shield, and the positive wire to the Vin terminal.  Then…

  • the red LED wire to the D3 terminal,
  • the green LED wire to the D9 terminal,
  • and the blue LED wire to the D10 terminal.

Finally, connect the 12V LED wire (anode) into the Vin terminal. Now double-check your wiring. Then check it again.

Testing

Now to run a test sketch to show the LED strip can easily be controlled. We’ll turn each colour on and off using PWM (Pulse-Width Modulation) – a neat way to control the brightness of each colour. The following sketch will pulse each colour in turn, and there’s also a blink function you can use.

// Controlling IKEA DIODER LED strips with Arduino and Freetronics NDRIVE N-MOSFET shield
// CC by-sa-nc John Boxall 2015 - tronixstuff.com 
// Components from tronixlabs.com

#define red 3
#define green 9
#define blue 10
#define delaya 2

void setup() 
{
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}

void blinkRGB()
{
  digitalWrite(red, HIGH);
  delay(1000);
  digitalWrite(red, LOW);
  digitalWrite(green, HIGH);
  delay(1000);
  digitalWrite(green, LOW);
  digitalWrite(blue, HIGH);
  delay(1000);
  digitalWrite(blue, LOW);
}

void pulseRed()
{
  for (int i=0; i<256; i++)
  {
    analogWrite(red,i);
    delay(delaya);
  }
  for (int i=255; i>=0; --i)
  {
    analogWrite(red,i);
    delay(delaya);
  }
}

void pulseGreen()
{
  for (int i=0; i<256; i++)
  {
    analogWrite(green,i);
    delay(delaya);
  }
  for (int i=255; i>=0; --i)
  {
    analogWrite(green,i);
    delay(delaya);
  }
}

void pulseBlue()
{
  for (int i=0; i<256; i++)
  {
    analogWrite(blue,i);
    delay(delaya);
  }
  for (int i=255; i>=0; --i)
  {
    analogWrite(blue,i);
    delay(delaya);
  }
}

void loop()
{
  pulseRed();
  pulseGreen();
  pulseBlue();
}

Success. And for the non-believers, watch the following video:

Better LED control

As always, there’s a better way of doing things and one example of LED control is the awesome FASTLED library by Daniel Garcia and others. Go and download it now – https://github.com/FastLED/FastLED. Apart from our simple LEDS, the FASTLED library is also great with WS2812B/Adafruit NeoPixels and others.

One excellent demonstration included with the library is the AnalogOutput sketch, which I have supplied below to work with our example hardware:

#include <FastLED.h>

// Example showing how to use FastLED color functions
// even when you're NOT using a "pixel-addressible" smart LED strip.
//
// This example is designed to control an "analog" RGB LED strip
// (or a single RGB LED) being driven by Arduino PWM output pins.
// So this code never calls FastLED.addLEDs() or FastLED.show().
//
// This example illustrates one way you can use just the portions 
// of FastLED that you need.  In this case, this code uses just the
// fast HSV color conversion code.
// 
// In this example, the RGB values are output on three separate
// 'analog' PWM pins, one for red, one for green, and one for blue.
 
#define REDPIN   3
#define GREENPIN 9
#define BLUEPIN  10

// showAnalogRGB: this is like FastLED.show(), but outputs on 
// analog PWM output pins instead of sending data to an intelligent,
// pixel-addressable LED strip.
// 
// This function takes the incoming RGB values and outputs the values
// on three analog PWM output pins to the r, g, and b values respectively.
void showAnalogRGB( const CRGB& rgb)
{
  analogWrite(REDPIN,   rgb.r );
  analogWrite(GREENPIN, rgb.g );
  analogWrite(BLUEPIN,  rgb.b );
}



// colorBars: flashes Red, then Green, then Blue, then Black.
// Helpful for diagnosing if you've mis-wired which is which.
void colorBars()
{
  showAnalogRGB( CRGB::Red );   delay(500);
  showAnalogRGB( CRGB::Green ); delay(500);
  showAnalogRGB( CRGB::Blue );  delay(500);
  showAnalogRGB( CRGB::Black ); delay(500);
}

void loop() 
{
  static uint8_t hue;
  hue = hue + 1;
  // Use FastLED automatic HSV->RGB conversion
  showAnalogRGB( CHSV( hue, 255, 255) );
  
  delay(20);
}


void setup() {
  pinMode(REDPIN,   OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN,  OUTPUT);

  // Flash the "hello" color sequence: R, G, B, black.
  colorBars();
}

You can see this in action through the following video:

Conclusion

So if you have some IKEA LED strips, or anything else that requires more current than an Arduino’s output pin can offer – you can use MOSFETs to take over the current control and have fun. And finally a plug for my own store – tronixlabs.com – offering a growing range and Australia’s best value for supported hobbyist electronics from adafruit, DFRobot, Freetronics, Seeed Studio and much much more.

As always, have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our forum – dedicated to the projects and related items on this website.

The post Experimenting with Arduino and IKEA DIODER LED Strips appeared first on tronixstuff.

IKEA Hack Music Visualizer Table

An ordinary IKEA table becomes the center of attention when it's turned into a music visualizer!

Read more on MAKE

MAKE » Arduino 11 Jan 18:01

Pimp your ikea lamp into a customized death star

Ikea hacks are well widespread in the maker movement and David Bliss, founder at Nurun, did a great job transforming the Death Star inspired PS 2014 Pendant Lamp into something more dynamic.

The lamp was pimped up with an Arduino Uno and Arduino Motor Shield, NeoPixel LEDs and other components you can see in the illustration.

The detailed description of the project is on his blog , the code on github and the final result in the following video:

Arduino Blog 26 Nov 22:41
arduino  featured  ikea  led  motor  shield  

IKEA SMS lamp with GSM shield

-->-->-->-->

 

 

 

We create a lamp controlled by SMS using a GSM shield, a RGB shield and a Arduino UNO.
Due to the simplicity of these boards, simply plug one over the other and connect a strip led to have a lighting effect.
Then sending normal text messages from any phone, you can turn on and choose the color to set.

The scketch check the text of the received message, if the SMS contains a character, it follows on the corresponding color.
It ‘also provided a fader functions can be called with the character F

This is the list commands:
R to set RED
G to set GREEN
B to set BLUE
Y to set YELLOW
O to set ORANGE
P to set PURPLE
W to set WHITE
F to set the fader function

This is just an example of the possible applications of the GSM / GPRS shield.
You can for example control the home lighting with a simple text message, or receive an SMS in case of alarm.
In addition, the SIM900 has the capacity to also decode DTMF tones, so you can call this in the sim GSM shield and switch loads directly from the telephone keypad.

The complete library it contains many other functions through which you can make calls, connect to the Internet, send and receive SMS.

This is the simple firmware in Arduino.

 

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs

#include "SIM900.h"
#include "sms.h"
#include "SoftwareSerial.h"
#include "sms.h"
SMSGSM sms;
int red = 10;    // RED LED connected to PWM pin 3
int green = 5;    // GREEN LED connected to PWM pin 5
int blue = 6;    // BLUE LED connected to PWM pin 6
int r=50; int g=100; int b=150;
int rup; int gup; int bup;

boolean started=false;
char smsbuffer[160];
char n[20];
int fader=1;
int inc=10;

void setup() 
{
  //Serial connection.
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  if (gsm.begin(2400)){
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");
  if(started){
    delsms();
  }

};

void loop() 
{
  int pos=0;
  //Serial.println("Loop");
  if(started){
    pos=sms.IsSMSPresent(SMS_ALL);
    if(pos){
      Serial.println("IsSMSPresent at pos ");
      Serial.println(pos); 
      sms.GetSMS(pos,n,smsbuffer,100);
        Serial.println(n);
        Serial.println(smsbuffer);
        if(!strcmp(smsbuffer,"R")){
          Serial.println("RED");
          r=255;
          g=0;
          b=0;
        }      
        if(!strcmp(smsbuffer,"G")){
          Serial.println("GREEN");
          r=0;
          g=255;
          b=0;
        }    
        if(!strcmp(smsbuffer,"B")){
          Serial.println("BLUE");
          r=0;
          g=0;
          b=255;
        }  
        if(!strcmp(smsbuffer,"P")){
          Serial.println("PURPLE");
          r=255;
          g=0;
          b=255;
        }  
        if(!strcmp(smsbuffer,"Y")){
          Serial.println("YELLOW");
          r=255;
          g=255;
          b=0;
        }  
        if(!strcmp(smsbuffer,"O")){
          Serial.println("ORANGE");
          r=255;
          g=165;
          b=0;
        }  
        if(!strcmp(smsbuffer,"W")){
          Serial.println("WHITE");
          r=255;
          g=255;
          b=255;
        }  
        if(!strcmp(smsbuffer,"F")){
          Serial.println("FADER");
          fader=1;
          r=50; g=100; b=150;
        }
        else
        {
          fader=0;
        }  
        rgb(r, g, b);
        delsms();

    }
    if(fader){
      funcfader();
    }

  }
};

void delsms(){
  Serial.println("delsms");
  for (int i=0; i<10; i++){  //do it max 10 times
      int pos=sms.IsSMSPresent(SMS_ALL);
      if (pos!=0){
        Serial.print("\nFind SMS at the pos ");
        Serial.println(pos); 
        if (sms.DeleteSMS(pos)==1){    
          Serial.print("\nDeleted SMS at the pos ");
          Serial.println(pos);      
        }
        else
        {
          Serial.print("\nCant del SMS at the pos ");
          Serial.println(pos);         
        }
      }
    }

}

void funcfader(){
    if (rup==1){r+=1;}
    else{r-=1;}
    if (r>=255){rup=0;}
    if (r<=0){rup=1;}

    if (gup==1){g+=1;}
    else{g-=1;}
    if (g>=255){gup=0;}
    if (g<=0){gup=1;}

    if (bup==1){b+=1;}
    else{b-=1;}
    if (b>=255){bup=0;}
    if (b<=0){bup=1;}  
    rgb(r, g, b);
}

void rgb(int r, int g, int b)
{
  if (r>255) r=255;
  if (g>255) g=255;
  if (b>255) b=255;
  if (r<0) r=0;
  if (g<0) g=0;
  if (b<0) b=0;

  analogWrite(red, r); 
  analogWrite(green, g); 
  analogWrite(blue, b);   
}
-->-->-->-->-->-->
-->-->

ARDUINO WIFI RGB LAMP [IKEA DUDERÖ MODDING]

 

We create an application based on Arduino, that allows you to control brightness and color of a RGB strip LED via local network or Internet through a WiFi or Ethernet shield

How it works

The system that we propose is based on the Arduino UNO, on which are mounted two shield: the Ethernet or WIFI Shield, which provides the connection to LAN, and the RGB shield which mounts three power drivers to control the LED strip.
In Arduino must be loaded different sketch depending of the type of connection you choose (Ethernet or WiFi). The sketch allows you to manage communication via LAN and create a web interface (which will come to those who try to access via a local network) and run the commands received.
Arduino is like a web server, an HTML page is showed through a browser, by introducing into the address bar the IP address corresponding to the ethernet/WIFI shield.

This means that the lamp can be turned on and controlled by any device on the network or remotely via the Internet. The web page shows the current setting of R, G, B of the lamp and allows you to edit them.

 

The shield RGB

Arduino controls the LED channels by a shield very simple, containing three MOSFET enhancement-mode n-channel type P36NF06; each MOSFET is driven on the gate, through a resistor, with the logic signal that Arduino sends. To be precise, pin 3 controls T3 (red), pin 5 controls T2 (green) and pin 6 controls T1 (blue), each line has a status LED, polarized by a limiting resistor (LEDs indicate how it is behaving this channel). Note that Arduino controls the individual transistors by PWM signals, which duty cycle determines the presence and intensity of a certain color; more precisely, the width of the pulses can changes from a minimum to a maximum to decide how much light should be the group of LEDs of the respective color.

The drain of each MOSFET controls the load which must be connected with the anode to the positive line of the common power supply (+); for each channel there is a connector with a positive contact (goes on line common) and a negative (corresponding to the respective drain MOSFET).
We have provided the possibility to power the LEDs in two ways: with the power drawn by Arduino contact Vin (in which case you should close the jumper on Vin) or with a voltage supplied to the terminal PWR (PWR jumper closed on), you can opt for the first solution if you think your lamps absorbs less than 1.5 amps, but if you need more power you have give power apart from the shield, with a suitable power supply.
Note that by closing the jumper on Vin, the Arduino must be supplied at 12 V with a power supply capable of delivering all the current required.

 

R1: 1 kohm
R2: 390 ohm
R3: 180 ohm
R4: 330 ohm
R5: 330 ohm
R6: 330 ohm

T1: STP36NE06
T2: STP36NE06
T3: STP36NE06

LD1: Led 5 mm blue
LD2: Led 5 mm green
LD3: Led 5 mm red

D1: 6A600

- Screw a 2

R1: 1 kohm
R2: 390 ohm
R3: 180 ohm
R4: 330 ohm
R5: 330 ohm
R6: 330 ohm

T1: STP36NE06
T2: STP36NE06
T3: STP36NE06

LD1: Led 5 mm blu (510LB7C)
LD2: Led 5 mm verde
LD3: Led 5 mm rosso

D1: 6A600

Varie:
- Screw 2 via(4 pz.)
- Strip M/F 6 via (2 pz.)
- Strip M/F 8 via (2 pz.)

The sketch

/* IKEA Dudero mods WIFI Version

 created 2011
 by Boris Landoni

 This example code is in the public domain.

http://www.open-electronics.org

http://www.futurashop.it

http://blog.elettronicain.it/

 */

// Inclusione Libreria per Server Web WiFi
#include <WiServer.h>
#include <avr/pgmspace.h>
#include <EEPROM.h>

int red = 3;    // RED LED connected to PWM pin 3
int green = 5;    // GREEN LED connected to PWM pin 5
int blue = 6;    // BLUE LED connected to PWM pin 6
int r=50; int g=100; int b=150;
int rup; int gup; int bup;
int fader=0;
int inc=10;
String inString = String(50);
char buffer[160]; // make sure this is large enough for the largest string it must hold

// Definizione Parametri Rete Wireless
#define WIRELESS_MODE_INFRA	1  // Infrastrutturata (basata su Access Point)
#define WIRELESS_MODE_ADHOC	2  // Ad-hoc (senza Access Point)

unsigned char local_ip[] = {192, 168, 0, 89};      // Indirizzo IP
unsigned char gateway_ip[] = {192, 168, 0, 254};	    // Indirizzo gateway IP
unsigned char subnet_mask[] = {255, 255, 255, 0};   // Subnet Mask
const prog_char ssid[] PROGMEM = {"AP_FES"};	    // SSID access point

// Selezione tipo di cifratura rete Wireless
unsigned char security_type = 3;  // 0 -> nessuna cifratura
                                  // 1 -> cifratura WEP
                                  // 2 -> cifratura WPA
                                  // 3 -> cifratura WPA2

// Password cifratura per WPA/WPA2 (max. 64 cratteri)
const prog_char security_passphrase[] PROGMEM = {"12345678"};

// Password cifratura per WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
				 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

// Selezione tipo di rete Wireless infrastrutturata
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

// Variabili per lunghezza SSID e password di cifratura
unsigned char ssid_len;
unsigned char security_passphrase_len;

prog_char string_0[] PROGMEM  = "<html><head><title>Boris's Project</title></head><script language=\"javascript\"> var alphaStr = \"0123456789ABCDEF\";";
prog_char string_1[] PROGMEM  = "var alphaArr = [\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\"]; var RGB = [";
prog_char string_2[] PROGMEM  = "];function pulsRED(){document.bgColor='#FF0000';RGB = [255,0,0]}function pulsGRE(){document.bgColor='#00FF00';RGB = [0,255,0]}";
prog_char string_3[] PROGMEM  = "function pulsBLU(){document.bgColor='#0000FF';RGB = [0,0,255]}function pulsYEL(){document.bgColor='#FFFF00';RGB = [255,255,0]}";
prog_char string_4[] PROGMEM  = "function pulsPIN(){document.bgColor='#FF00FF';RGB = [255,0,255]}function pulsCEL(){document.bgColor='#00FFFF';RGB = [0,255,255]}";
prog_char string_5[] PROGMEM  = "function pulsWHI(){document.bgColor='#FFFFFF';RGB = [255,255,255]}";
prog_char string_6[] PROGMEM  = " ";
prog_char string_7[] PROGMEM  = "function HEX_from_RGB(){document.bgColor = '#' + DEC_to_HEX(RGB[0]) + DEC_to_HEX(RGB[1]) + DEC_to_HEX(RGB[2]);}";
prog_char string_8[] PROGMEM  = "function adjRED(incr){	RGB[0] += incr;	if (RGB[0] > 255) RGB[0] = 255;	if (RGB[0] < 0) RGB[0] = 0;}";
prog_char string_9[] PROGMEM  = "function adjGRN(incr)	{RGB[1] += incr;if (RGB[1] > 255) RGB[1] = 255;	if (RGB[1] < 0) RGB[1] = 0;}";
prog_char string_10[] PROGMEM  = "function adjBLU(incr)	{RGB[2] += incr;if (RGB[2] > 255) RGB[2] = 255;	if (RGB[2] < 0) RGB[2] = 0;}";
prog_char string_11[] PROGMEM = "function setRED(r) { RGB[0] = r; } function setGRN(g) { RGB[1] = g; } function setBLU(b) { RGB[2] = b; }";
prog_char string_12[] PROGMEM = "function newRGB() { HEX_from_RGB(); } </script> <script language=\"javascript\"> var i_a; ";
prog_char string_13[] PROGMEM = "function DEC_to_HEX(dec) {var n_ = Math.floor(dec / 16); var _n = dec - n_ * 16; return alphaArr[n_] + alphaArr[_n];	}";
prog_char string_14[] PROGMEM = "function HEX_to_DEC(hex){var n_ = alphaStr.indexOf(hex.substring(0,1)); var _n = alphaStr.indexOf(hex.substring(1,2)); return n_ * 16 + _n;	}";
prog_char string_15[] PROGMEM = "function updateFields(){var d = document.colForm;d.r.value = RGB[0];	d.g.value = RGB[1];	d.b.value = RGB[2];	}";
prog_char string_16[] PROGMEM = "function setRGB(){var d = document.colForm; var R = d.r.value;	var G = d.g.value;	var B = d.b.value;";
prog_char string_17[] PROGMEM = "setRED(parseInt(R));	setGRN(parseInt(G));	setBLU(parseInt(B));	newRGB(); updateFields();} </script>";
prog_char string_18[] PROGMEM = "</head><body><center><form method=GET, name=\"colForm\"><h1>The INTERNET RGB LAMP</h1> <table> <tr> <td valign=\"top\"> <input type=\"text\" name=\"r\"> ";
prog_char string_19[] PROGMEM = "<input type=\"text\" name=\"g\"> <input type=\"text\" name=\"b\"> <input type=\"button\" value=\"Calculate\" onclick=\"setRGB();\">";
prog_char string_20[] PROGMEM = " </td></tr> <tr><td><CENTER><input type=\"button\" class=\"tweak\" value=\"Red+\" onclick=\"adjRED(i_a);newRGB();updateFields();\">";
prog_char string_21[] PROGMEM = "<input type=\"button\" class=\"tweak\" value=\"Green+\" onclick=\"adjGRN(i_a);newRGB();updateFields();\"><input type=\"button\" class=\"tweak\" value=\"Blue+\"";
prog_char string_22[] PROGMEM = "onclick=\"adjBLU(i_a);newRGB();updateFields();\"> <select name=\"inc\" onchange=\"i_a = parseInt(document.colForm.inc.options";
prog_char string_23[] PROGMEM = "[document.colForm.inc.selectedIndex].value);\"> <option value=\"1\"";//selected
prog_char string_24[] PROGMEM = ">inc/speed = 1x <option value=\"5\"";
prog_char string_25[] PROGMEM = ">inc/speed = 5x <option value=\"10\"";
prog_char string_26[] PROGMEM = ">inc/speed = 10x <option value=\"25\"";
prog_char string_27[] PROGMEM = ">inc/speed = 25x <option value=\"50\"";
prog_char string_28[] PROGMEM = ">inc/speed = 50x <option value=\"100\"";
prog_char string_29[] PROGMEM = ">inc/speed = 100x <option value=\"150\"";
prog_char string_30[] PROGMEM = ">inc/speed = 150x <option value=\"200\"";
prog_char string_31[] PROGMEM = ">inc/speed = 200x <option value=\"250\"";
prog_char string_32[] PROGMEM = ">inc/speed = 250x</select><input type=";
prog_char string_33[] PROGMEM = "\"button\" class=\"tweak\" value=\"Red-\" onclick=\"adjRED(0-i_a);newRGB();updateFields();\"><input type=\"button\" class=\"tweak\" value=\"Green-\"";
prog_char string_34[] PROGMEM = "onclick=\"adjGRN(0-i_a);newRGB();updateFields();\"><input type=\"button\" class=\"tweak\" value=\"Blue-\" onclick=\"adjBLU(0-i_a);newRGB();updateFields();\">";
prog_char string_35[] PROGMEM = "</CENTER></td> <tr><td><CENTER>Fader<input type=\"radio\" name=\"fad\" value=\"1\"";
prog_char string_36[] PROGMEM = "/> On<input type=\"radio\" name=\"fad\" value=\"0\" ";
prog_char string_37[] PROGMEM = "/> Off</CENTER></td></tr> </tr></td> </tr> <input type=\"submit\" style=\" width:80;height:44px;background-color:FF0000;\" onclick=\"pulsRED();updateFields();\";>";
prog_char string_38[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:00FF00;\" onclick=\"pulsGRE();updateFields();\";>";
prog_char string_39[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:0000FF;\" onclick=\"pulsBLU();updateFields();\";>";
prog_char string_40[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:FFFF00;\" onclick=\"pulsYEL();updateFields();\";>";
prog_char string_41[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:FF00FF;\" onclick=\"pulsPIN();updateFields();\";>";
prog_char string_42[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:00FFFF;\" onclick=\"pulsCEL();updateFields();\";>";
prog_char string_43[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:FFFFFF;\" onclick=\"pulsWHI();updateFields();\";>";
prog_char string_44[] PROGMEM = "<tr><td><CENTER><input type=\"submit\" value=\"Set colors\"></CENTER></td></tr>   ";
prog_char string_45[] PROGMEM = "</table> </form> <script language=\"javascript\">newRGB(); updateFields(); ";
prog_char string_46[] PROGMEM = "i_a = parseInt(document.colForm.inc.options[document.colForm.inc.selectedIndex].value);</script>";
prog_char string_47[] PROGMEM = "<font size= 2>Powered by Open-Electronics.org - Boris Landoni</font>"; //please don't remove  ";
prog_char string_48[] PROGMEM  = "<br></center></body></html>";
prog_char string_49[] PROGMEM  = "";
prog_char string_50[] PROGMEM  = "";
prog_char string_51[] PROGMEM  = "";

PROGMEM const char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5,
string_6,
string_7,
string_8,
string_9,
string_10,
string_11,
string_12,
string_13,
string_14,
string_15,
string_16,
string_17,
string_18,
string_19,
string_20,
string_21,
string_22,
string_23,
string_24,
string_25,
string_26,
string_27,
string_28,
string_29,
string_30,
string_31,
string_32,
string_33,
string_34,
string_35,
string_36,
string_37,
string_38,
string_39,
string_40,
string_41,
string_42,
string_43,
string_44,
string_45,
string_46,
string_47,
string_48,
string_49,
string_50,
string_51
};

void setup()
{
  // start the Ethernet connection and the server:
// Inizializzo WiServer (Gestione_Richieste_Web per creare/trasmettere pagine HTML)
      WiServer.init (Gestione_Richieste_Web);
      // Inizializzo porta seriale
      Serial.begin (9600);
      WiServer.enableVerboseMode (false);

      Serial.println("Serial READY");
      Serial.println("WiFi READY");
      Serial.println("Server READY");

      r = EEPROM.read(1);
      g = EEPROM.read(2);
      b = EEPROM.read(3);
      inc = EEPROM.read(4);
      fader = EEPROM.read(5);
} 

void loop()  { 

    // Avvio WiServer
  WiServer.server_task();

  delay(10);

  if (fader==1){
    funcfader();
  }

}

// Gestione diverse richieste provenienti dal WEB
// INPUT:   URL pagina web richiesta
// OUTPUT:  Flag URL riconosciuto/non riconosciutoo
boolean Gestione_Richieste_Web (char* URL) {
  Serial.print("Richiesta Web - URL->");
  Serial.println(URL); 

  // Se URL richiesto corrisponde a "/" (pagina index)
  if (strcmp (URL, "/") == 0) {
    // Secondo gli I/O creo e invio le pagine Web
    Serial.println("pagina index");
    printWebPage();

    // Ritorno URL è stato riconosciuto
    return true;
  }    // Chiusura if URL richieso corrisponde a "/" (pagina index)

  // Se URL richieso corrisponde a "?OPERATION=ACCENDI_ROSSO
  if (strncmp (URL, "/?r=*",4) == 0) {

    Serial.println("pagina operazione"); 

                char colorArr[5];
                String temp="";
                inString=URL;
                Serial.print("inString: ");
                Serial.println(inString);

                int Pos_r = inString.indexOf("r");
                int Pos_g = inString.indexOf("g");
                int Pos_b = inString.indexOf("b");
                int Pos_i = inString.indexOf("inc");
                int Pos_f = inString.indexOf("fad");
                int End = inString.indexOf("HTTP");
                Serial.print("Pos_r: ");
                Serial.println(Pos_r);
                Serial.print("Pos_g: ");
                Serial.println(Pos_g);
                Serial.print("Pos_b: ");
                Serial.println(Pos_b);
                Serial.print("Pos_i: ");
                Serial.println(Pos_i);
                Serial.print("Pos_f: ");
                Serial.println(Pos_f);
                Serial.print("End: ");
                Serial.println(End);
                if(Pos_r>=0){
                   temp=inString.substring((Pos_r+2), (Pos_g-1));
                   temp.toCharArray(colorArr, 5);
                   r=(atoi(colorArr));
                   Serial.print("red: ");
                   Serial.println(r);
                   EEPROM.write(1, r);
                }
                if(Pos_g>=0){
                   temp=inString.substring((Pos_g+2), (Pos_b-1));
                   temp.toCharArray(colorArr, 5);
                   g=(atoi(colorArr));
                   Serial.print("green: ");
                   Serial.println(g);
                   EEPROM.write(2, g);
                }         

                if(Pos_b>=0){
                   temp=inString.substring((Pos_b+2), (Pos_i-1));
                   temp.toCharArray(colorArr, 5);
                   b=(atoi(colorArr));
                   Serial.print("blue: ");
                   Serial.println(b);
                   EEPROM.write(3, b);
                }      

                if(Pos_i>=0){
                   temp=inString.substring((Pos_i+4), (Pos_f-1));
                   temp.toCharArray(colorArr, 5);
                   inc=(atoi(colorArr));
                   Serial.print("inc: ");
                   Serial.println(inc);
                   EEPROM.write(4, inc);
                } 

                if(Pos_f>=0){
                   temp=inString.substring((Pos_f+4), (End-1));
                   temp.toCharArray(colorArr, 5);
                   fader=(atoi(colorArr));
                   Serial.print("fader: ");
                   Serial.println(fader);
                   EEPROM.write(5, fader);
                }     

               if ((Pos_r>=0)&&(Pos_g>=0)&&(Pos_b>=0)) {
                 rgb(r,g,b);
               }

    // Secondo gli I/O creo e invio le pagine Web
    printWebPage();

    // Ritorno URL è stato riconosciuto
    return true;
  }    // Chiusura if URL richieso corrisponde a "?OPERATION=ACCENDI_ROSSO"

  // Ritorno URL non riconosciuto
  return false;
}

 void printWebPage2()
{
      int tmp=0;
      Serial.println("printWebPage");
      // send a standard http response header

//      WiServer.print("HTTP/1.1 200 OK");
//      WiServer.print("Content-Type: text/html");
//      WiServer.print();

      //strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0]))); // Necessary casts and dereferencing, just copy.
      //WiServer.print( buffer );
      //Serial.println( buffer );
      for (int i = 0; i < 51; i++)
      {
          //strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
          //WiServer.print( buffer );
          WiServer.print_P((char*)pgm_read_word(&(string_table[i])));
          //Serial.println( buffer );
          //delay(500);
      }

}          

void printWebPage()
{
      int tmp=0;
      Serial.println("printWebPage");
      // send a standard http response header
      //WiServer.print_P("HTTP/1.1 200 OK");
      //WiServer.print_P("Content-Type: text/html");

      //strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0]))); // Necessary casts and dereferencing, just copy.
      WiServer.print_P((char*)pgm_read_word(&(string_table[0])));
      //Serial.println( buffer );
      for (int i = 1; i < 51; i++)
      {
          /*if (i==9)
          {
              strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])));  //butto tutto nell'array buffer
              for (tmp=0 ; tmp < sizeof(buffer); tmp++)
              {
                if (buffer[tmp]=='#')
                {
                  //Serial.println( "trovato ##### " ); 

                }

              }
          }
          else
          {
            strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
          }*/
          //strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
          WiServer.print_P((char*)pgm_read_word(&(string_table[i])));
          //Serial.println( buffer );
          if (i==1)
          {
            char tmpstr[4];
            WiServer.print( itoa(r,tmpstr,10) );
            //Serial.println( itoa(r,tmpstr,10) );
            WiServer.print( "," );
            //Serial.println("," );
            WiServer.print( itoa(g,tmpstr,10) );
            //Serial.println( itoa(g,tmpstr,10) );
            WiServer.print( "," );
            //Serial.println( "," );
            WiServer.print( itoa(b,tmpstr,10) );
            //Serial.println( itoa(b,tmpstr,10) );
          }

          if (i==23){if (inc==1){WiServer.print("selected");}}
          if (i==24){if (inc==5){WiServer.print("selected");}}
          if (i==25){if (inc==10){WiServer.print("selected");}}
          if (i==26){if (inc==25){WiServer.print("selected");}}
          if (i==27){if (inc==50){WiServer.print("selected");}}
          if (i==28){if (inc==100){WiServer.print("selected");}}
          if (i==29){if (inc==150){WiServer.print("selected");}}
          if (i==30){if (inc==200){WiServer.print("selected");}}
          if (i==31){if (inc==250){WiServer.print("selected");}}

          if (i==35)
          {
            if (fader==1){
              WiServer.print("checked");
            }
          }
          if (i==36)
          {
            if (fader==0){
              WiServer.print("checked");
            }
          }
      }
     Serial.println("FINE printWebPage"); 

}

void funcfader(){
    Serial.println("fader");
    if (rup==1){r+=1;}
    else{r-=1;}
    if (r>=255){rup=0;}
    if (r<=0){rup=1;}

    if (gup==1){g+=1;}
    else{g-=1;}
    if (g>=255){gup=0;}
    if (g<=0){gup=1;}

    if (bup==1){b+=1;}
    else{b-=1;}
    if (b>=255){bup=0;}
    if (b<=0){bup=1;}

    delay(inc*2);
    rgb(r, g, b);
}

void rgb(int r, int g, int b)
{

  Serial.print("RGB: ");
  Serial.print(r);
  Serial.print(" ");
  Serial.print(g);
  Serial.print(" ");
  Serial.print(b);
  if (r>255) r=255;
  if (g>255) g=255;
  if (b>255) b=255;
  if (r<0) r=0;
  if (g<0) g=0;
  if (b<0) b=0;

  analogWrite(red, r);
  analogWrite(green, g);
  analogWrite(blue, b);
}

 

/* IKEA Dudero mods Ethernet Version

 created 2011
 by Boris Landoni

 This example code is in the public domain.

http://www.open-electronics.org

http://www.futurashop.it

http://blog.elettronicain.it/

 */

#include <SPI.h>
#include <Ethernet.h>
#include <avr/pgmspace.h>
#include <EEPROM.h>

int red = 3;    // RED LED connected to PWM pin 3
int green = 5;    // GREEN LED connected to PWM pin 5
int blue = 6;    // BLUE LED connected to PWM pin 6
int r=50; int g=100; int b=150;
int rup; int gup; int bup;
int fader=0;
int inc=10;
String inString = String(50);
char buffer[160]; // make sure this is large enough for the largest string it must hold

byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0x1D, 0x89 };
byte ip[] = { 192,168,0,88 };
byte gateway[] = { 192, 168, 0, 1 };
byte subnet[] = { 255, 255, 255, 0 };

/*

*/

prog_char string_0[] PROGMEM  = "<html><head><title>Boris's Project</title></head><script language=\"javascript\"> var alphaStr = \"0123456789ABCDEF\";";
prog_char string_1[] PROGMEM  = "var alphaArr = [\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\"]; var RGB = [";
prog_char string_2[] PROGMEM  = "];function pulsRED(){document.bgColor='#FF0000';RGB = [255,0,0]}function pulsGRE(){document.bgColor='#00FF00';RGB = [0,255,0]}";
prog_char string_3[] PROGMEM  = "function pulsBLU(){document.bgColor='#0000FF';RGB = [0,0,255]}function pulsYEL(){document.bgColor='#FFFF00';RGB = [255,255,0]}";
prog_char string_4[] PROGMEM  = "function pulsPIN(){document.bgColor='#FF00FF';RGB = [255,0,255]}function pulsCEL(){document.bgColor='#00FFFF';RGB = [0,255,255]}";
prog_char string_5[] PROGMEM  = "function pulsWHI(){document.bgColor='#FFFFFF';RGB = [255,255,255]}";
prog_char string_6[] PROGMEM  = "";
prog_char string_7[] PROGMEM  = "function HEX_from_RGB(){document.bgColor = '#' + DEC_to_HEX(RGB[0]) + DEC_to_HEX(RGB[1]) + DEC_to_HEX(RGB[2]);}";
prog_char string_8[] PROGMEM  = "function adjRED(incr){	RGB[0] += incr;	if (RGB[0] > 255) RGB[0] = 255;	if (RGB[0] < 0) RGB[0] = 0;}";
prog_char string_9[] PROGMEM  = "function adjGRN(incr)	{RGB[1] += incr;if (RGB[1] > 255) RGB[1] = 255;	if (RGB[1] < 0) RGB[1] = 0;}";
prog_char string_10[] PROGMEM  = "function adjBLU(incr)	{RGB[2] += incr;if (RGB[2] > 255) RGB[2] = 255;	if (RGB[2] < 0) RGB[2] = 0;}";
prog_char string_11[] PROGMEM = "function setRED(r) { RGB[0] = r; } function setGRN(g) { RGB[1] = g; } function setBLU(b) { RGB[2] = b; }";
prog_char string_12[] PROGMEM = "function newRGB() { HEX_from_RGB(); } </script> <script language=\"javascript\"> var i_a; ";
prog_char string_13[] PROGMEM = "function DEC_to_HEX(dec) {var n_ = Math.floor(dec / 16); var _n = dec - n_ * 16; return alphaArr[n_] + alphaArr[_n];	}";
prog_char string_14[] PROGMEM = "function HEX_to_DEC(hex){var n_ = alphaStr.indexOf(hex.substring(0,1)); var _n = alphaStr.indexOf(hex.substring(1,2)); return n_ * 16 + _n;	}";
prog_char string_15[] PROGMEM = "function updateFields(){var d = document.colForm;d.r.value = RGB[0];	d.g.value = RGB[1];	d.b.value = RGB[2];	}";
prog_char string_16[] PROGMEM = "function setRGB(){var d = document.colForm; var R = d.r.value;	var G = d.g.value;	var B = d.b.value;";
prog_char string_17[] PROGMEM = "setRED(parseInt(R));	setGRN(parseInt(G));	setBLU(parseInt(B));	newRGB(); updateFields();} </script>";
prog_char string_18[] PROGMEM = "</head><body><center><form method=GET, name=\"colForm\"><h1>The INTERNET RGB LAMP</h1> <table> <tr> <td valign=\"top\"> <input type=\"text\" name=\"r\"> ";
prog_char string_19[] PROGMEM = "<input type=\"text\" name=\"g\"> <input type=\"text\" name=\"b\"> <input type=\"button\" value=\"Calculate\" onclick=\"setRGB();\">";
prog_char string_20[] PROGMEM = " </td></tr> <tr><td><CENTER><input type=\"button\" class=\"tweak\" value=\"Red+\" onclick=\"adjRED(i_a);newRGB();updateFields();\">";
prog_char string_21[] PROGMEM = "<input type=\"button\" class=\"tweak\" value=\"Green+\" onclick=\"adjGRN(i_a);newRGB();updateFields();\"><input type=\"button\" class=\"tweak\" value=\"Blue+\"";
prog_char string_22[] PROGMEM = "onclick=\"adjBLU(i_a);newRGB();updateFields();\"> <select name=\"inc\" onchange=\"i_a = parseInt(document.colForm.inc.options";
prog_char string_23[] PROGMEM = "[document.colForm.inc.selectedIndex].value);\"> <option value=\"1\"";//selected
prog_char string_24[] PROGMEM = ">inc/speed = 1x <option value=\"5\"";
prog_char string_25[] PROGMEM = ">inc/speed = 5x <option value=\"10\"";
prog_char string_26[] PROGMEM = ">inc/speed = 10x <option value=\"25\"";
prog_char string_27[] PROGMEM = ">inc/speed = 25x <option value=\"50\"";
prog_char string_28[] PROGMEM = ">inc/speed = 50x <option value=\"100\"";
prog_char string_29[] PROGMEM = ">inc/speed = 100x <option value=\"150\"";
prog_char string_30[] PROGMEM = ">inc/speed = 150x <option value=\"200\"";
prog_char string_31[] PROGMEM = ">inc/speed = 200x <option value=\"250\"";
prog_char string_32[] PROGMEM = ">inc/speed = 250x</select><input type=";
prog_char string_33[] PROGMEM = "\"button\" class=\"tweak\" value=\"Red-\" onclick=\"adjRED(0-i_a);newRGB();updateFields();\"><input type=\"button\" class=\"tweak\" value=\"Green-\"";
prog_char string_34[] PROGMEM = "onclick=\"adjGRN(0-i_a);newRGB();updateFields();\"><input type=\"button\" class=\"tweak\" value=\"Blue-\" onclick=\"adjBLU(0-i_a);newRGB();updateFields();\">";
prog_char string_35[] PROGMEM = "</CENTER></td> <tr><td><CENTER>Fader<input type=\"radio\" name=\"fad\" value=\"1\"";
prog_char string_36[] PROGMEM = "/> On<input type=\"radio\" name=\"fad\" value=\"0\" ";
prog_char string_37[] PROGMEM = "/> Off</CENTER></td></tr> </tr></td> </tr> <input type=\"submit\" style=\" width:80;height:44px;background-color:FF0000;\" onclick=\"pulsRED();updateFields();\";>";
prog_char string_38[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:00FF00;\" onclick=\"pulsGRE();updateFields();\";>";
prog_char string_39[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:0000FF;\" onclick=\"pulsBLU();updateFields();\";>";
prog_char string_40[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:FFFF00;\" onclick=\"pulsYEL();updateFields();\";>";
prog_char string_41[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:FF00FF;\" onclick=\"pulsPIN();updateFields();\";>";
prog_char string_42[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:00FFFF;\" onclick=\"pulsCEL();updateFields();\";>";
prog_char string_43[] PROGMEM = "<input type=\"submit\" style=\" width:80;height:44px;background-color:FFFFFF;\" onclick=\"pulsWHI();updateFields();\";>";
prog_char string_44[] PROGMEM = "<tr><td><CENTER><input type=\"submit\" value=\"Set colors\"></CENTER></td></tr>   ";
prog_char string_45[] PROGMEM = "</table> </form> <script language=\"javascript\">newRGB(); updateFields(); ";
prog_char string_46[] PROGMEM = "i_a = parseInt(document.colForm.inc.options[document.colForm.inc.selectedIndex].value);</script>";
prog_char string_47[] PROGMEM = "<font size= 2>Powered by Open-Electronics.org - Boris Landoni</font>"; //please don't remove  ";
prog_char string_48[] PROGMEM  = "<br></center></body></html>";
prog_char string_49[] PROGMEM  = "";
prog_char string_50[] PROGMEM  = "";
prog_char string_51[] PROGMEM  = "";

PROGMEM const char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5,
string_6,
string_7,
string_8,
string_9,
string_10,
string_11,
string_12,
string_13,
string_14,
string_15,
string_16,
string_17,
string_18,
string_19,
string_20,
string_21,
string_22,
string_23,
string_24,
string_25,
string_26,
string_27,
string_28,
string_29,
string_30,
string_31,
string_32,
string_33,
string_34,
string_35,
string_36,
string_37,
string_38,
string_39,
string_40,
string_41,
string_42,
string_43,
string_44,
string_45,
string_46,
string_47,
string_48,
string_49,
string_50,
string_51
};

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);

void setup()
{
  // start the Ethernet connection and the server:
      Serial.begin(9600);
      Ethernet.begin(mac, ip,gateway,subnet);
      server.begin();
      Serial.println("Serial READY");
      Serial.println("Ethernet READY");
      Serial.println("Server READY");
      r = EEPROM.read(1);
      g = EEPROM.read(2);
      b = EEPROM.read(3);
      inc = EEPROM.read(4);
      fader = EEPROM.read(5);
} 

void loop()  {
//  // fade in from min to max in increments of 5 points:
//  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
//    // sets the value (range from 0 to 255):
//    //analogWrite(red, fadeValue);
//    // wait for 30 milliseconds to see the dimming effect
//    rgb(fadeValue,fadeValue,fadeValue);
//    delay(30);
//  }
//
//  // fade out from max to min in increments of 5 points:
//  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
//    // sets the value (range from 0 to 255):
//    //analogWrite(red, fadeValue);
//    // wait for 30 milliseconds to see the dimming effect
//    rgb(fadeValue,fadeValue,fadeValue);
//    delay(30);
//  } 

  if (fader==1){
    funcfader();
  }

      Client client = server.available();

      if (client) {
        Serial.println("client");
        // an http request ends with a blank line
        boolean current_line_is_blank = true;
        while (client.connected()) {

          if (client.available()) {

            char c = client.read();
            if (inString.length() < 50) {
            inString.concat(c);

            } 

            if (c == '\n' && current_line_is_blank) {
                char colorArr[5];
                String temp="";
                Serial.print("inString: ");
                Serial.println(inString);

                int Pos_r = inString.indexOf("r");
                int Pos_g = inString.indexOf("g");
                int Pos_b = inString.indexOf("b");
                int Pos_i = inString.indexOf("inc");
                int Pos_f = inString.indexOf("fad");
                int End = inString.indexOf("HTTP");
                Serial.print("Pos_r: ");
                Serial.println(Pos_r);
                Serial.print("Pos_g: ");
                Serial.println(Pos_g);
                Serial.print("Pos_b: ");
                Serial.println(Pos_b);
                Serial.print("Pos_i: ");
                Serial.println(Pos_i);
                Serial.print("Pos_f: ");
                Serial.println(Pos_f);
                Serial.print("End: ");
                Serial.println(End);

                if(Pos_r>=0){
                   temp=inString.substring((Pos_r+2), (Pos_g-1));
                   temp.toCharArray(colorArr, 5);
                   r=(atoi(colorArr));
                   Serial.print("red: ");
                   Serial.println(r);
                   EEPROM.write(1, r);
                }
                if(Pos_g>=0){
                   temp=inString.substring((Pos_g+2), (Pos_b-1));
                   temp.toCharArray(colorArr, 5);
                   g=(atoi(colorArr));
                   Serial.print("green: ");
                   Serial.println(g);
                   EEPROM.write(2, g);
                }         

                if(Pos_b>=0){
                   temp=inString.substring((Pos_b+2), (Pos_i-1));
                   temp.toCharArray(colorArr, 5);
                   b=(atoi(colorArr));
                   Serial.print("blue: ");
                   Serial.println(b);
                   EEPROM.write(3, b);
                }      

                if(Pos_i>=0){
                   temp=inString.substring((Pos_i+4), (Pos_f-1));
                   temp.toCharArray(colorArr, 5);
                   inc=(atoi(colorArr));
                   Serial.print("inc: ");
                   Serial.println(inc);
                   EEPROM.write(4, inc);
                } 

                if(Pos_f>=0){
                   temp=inString.substring((Pos_f+4), (End-1));
                   temp.toCharArray(colorArr, 5);
                   fader=(atoi(colorArr));
                   Serial.print("fader: ");
                   Serial.println(fader);
                   EEPROM.write(5, fader);
                }     

               if ((Pos_r>=0)&&(Pos_g>=0)&&(Pos_b>=0)) {
                 rgb(r,g,b);
               }
            printWebPage( &client);
            break;
            }
            if (c == '\n') {
            // we're starting a new line
            current_line_is_blank = true;
            } else if (c != '\r') {
            // we've gotten a character on the current line
            current_line_is_blank = false;
            }
          }
        }
        // give the web browser time to receive the data
        delay(1);

        inString = "";
        client.stop();
      }

}

void printWebPage(Client *client)
{
      int tmp=0;
      Serial.println("printWebPage");
      // send a standard http response header
      client->println("HTTP/1.1 200 OK");
      client->println("Content-Type: text/html");
      client->println();

      strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0]))); // Necessary casts and dereferencing, just copy.
      client->println( buffer );
      //Serial.println( buffer );
      for (int i = 1; i < 51; i++)
      {
          /*if (i==9)
          {
              strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])));  //butto tutto nell'array buffer
              for (tmp=0 ; tmp < sizeof(buffer); tmp++)
              {
                if (buffer[tmp]=='#')
                {
                  //Serial.println( "trovato ##### " ); 

                }

              }
          }
          else
          {
            strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
          }*/
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
          client->println( buffer );
          if (i==1)
          {
            client->print( r );client->print( "," );client->print( g );client->print( "," );client->print( b );
          }

          if (i==23){if (inc==1){client->print("selected");}}
          if (i==24){if (inc==5){client->print("selected");}}
          if (i==25){if (inc==10){client->print("selected");}}
          if (i==26){if (inc==25){client->print("selected");}}
          if (i==27){if (inc==50){client->print("selected");}}
          if (i==28){if (inc==100){client->print("selected");}}
          if (i==29){if (inc==150){client->print("selected");}}
          if (i==30){if (inc==200){client->print("selected");}}
          if (i==31){if (inc==250){client->print("selected");}}

          if (i==35)
          {
            if (fader==1){
              client->print("checked");
            }
          }
          if (i==36)
          {
            if (fader==0){
              client->print("checked");
            }
          }
//          switch(i){
//
//              case 1:
//                  //itoa (tempC, buffer, 10); client->print( buffer ); Serial.print( buffer ); client->print( "," ); Serial.print( "," ); itoa ((int(tempC * 100) % 100), buffer, 10); client->print( buffer ); Serial.print( buffer ); break;
//              case 2:
//                  //if(digitalRead(rele)) st4=41;
//                  //else st4=42;
//                  //strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st4]))); client->println( buffer ); Serial.println( buffer ); break;
//              case 3:
//                  //strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st6]))); client->println( buffer ); Serial.println( buffer ); break;
//              case 4:
//              case 5:
//              case 6:
//          }
          delay(30);
      }

}

void funcfader(){
    Serial.println("fader");
    if (rup==1){r+=1;}
    else{r-=1;}
    if (r>=255){rup=0;}
    if (r<=0){rup=1;}

    if (gup==1){g+=1;}
    else{g-=1;}
    if (g>=255){gup=0;}
    if (g<=0){gup=1;}

    if (bup==1){b+=1;}
    else{b-=1;}
    if (b>=255){bup=0;}
    if (b<=0){bup=1;}

    delay(inc*2);
    rgb(r, g, b);
}

void rgb(int r, int g, int b)
{

  Serial.print("RGB: ");
  Serial.print(r);
  Serial.print(" ");
  Serial.print(g);
  Serial.print(" ");
  Serial.print(b);
  if (r>255) r=255;
  if (g>255) g=255;
  if (b>255) b=255;
  if (r<0) r=0;
  if (g<0) g=0;
  if (b<0) b=0;

  analogWrite(red, r);
  analogWrite(green, g);
  analogWrite(blue, b);
}

 

 

 

The web page

We conclude seeing the commands and reports available on the web page, there are buttons to issue commands, the option radio to select mode and some boxes where you write parameters. We start from the top, where we find the seven buttons, each relating to a color: each of them set in the lamp the combination of the LEDs R, G and B to obtain the corresponding color; receiving the command Arduino sets its color. Below these buttons are three boxes, with the Calculate button to the right: from left to right, they represent the colors red, green and blue. In each box, you can write, with a number between 0 and 255, the intensity that we have employed the same light, for example, typing 255 in the middle box we illuminate at full intensity green light.
The value in each cell can be varied with the buttons below Red+ Green+ and Blue+ (which increases the light intensity, respectively, red, green and blue) or by Red- Green- and Blue- buttons that reduce the intensity. Clicking on the Calculate button, see what color will obtain, whereas with Set colors send a request for setting the color intensity corresponding to the combination of the three boxes.
The last section of the web page is that of the fader: it is the effect of color change continues, activated by clicking in the option box next to On the same name (Fader) to disable this function you must click Off. By activating the fader, we will see the light of the lamp shades change cyclically from the currently set color, you can also choose between multiple execution speed of the cycle, the drop down menu which is accessed by clicking the middle box inc/speed was above a Fader section.

To build the project

Open Electronics 20 Feb 14:15

IKEA lamp mod – STRÅLA

I love IKEA and her low cost products.

Last week I found this STRÅLA lamp.

The cost is $4.99, so I bought it.
Lighting the lamp I saw that it ‘s very pretty but also … too soft…

So I thought to modify the LED and add a RGB led.
With simple modify you can obtain a dinamic lamp.
I used an Arduino to do a fast work, but of course it isn’t necessary.
You can use a small microcontroller like a PIC12F675, or a ATTiny.

And this it the result:

How to

Before all, you have to buy a STRÅLA 

Open the package

And disassemble the original LED

As you can see the LED shape isn’t normal, but there is a cone in the center to better spread the light.
So I modify the RGB led to obtain the same effects and I also smoothed the surface.

Connect the wire to the led and reassemble all.

To connect the RGB led I used a strip wire and some pin.

And now you can connect this pin to PWM ports of Arduino.

The black, blue and white wire are the RGB pin of the LED.

The red one is the Anode.

 The sketch

/* IKEA Strala mods

 created 2011
 by Boris Landoni

 This example code is in the public domain.

http://www.open-electronics.org

http://www.futurashop.it

http://blog.elettronicain.it/

 */

#include <EEPROM.h>

int red = 9;    // RED LED connected to PWM pin 3
int green = 10;    // GREEN LED connected to PWM pin 5
int blue = 11;    // BLUE LED connected to PWM pin 6
int r=50; int g=100; int b=150;
int rup; int gup; int bup;
int fader=1;
int inc=10;
void setup()
{
  // start the Ethernet connection and the server:
      Serial.begin(9600);
      Serial.println("Serial READY");
      r = EEPROM.read(1);
      g = EEPROM.read(2);
      b = EEPROM.read(3);
      inc = EEPROM.read(4);
      fader = EEPROM.read(5);
      rgb(r, g, b);
} 

void loop()  { 

  if (fader==1){
    funcfader();
  }

}

void funcfader(){
    Serial.println("fader");
    if (rup==1){r+=1;}
    else{r-=1;}
    if (r>=255){rup=0;}
    if (r<=0){rup=1;}

    if (gup==1){g+=1;}
    else{g-=1;}
    if (g>=255){gup=0;}
    if (g<=0){gup=1;}

    if (bup==1){b+=1;}
    else{b-=1;}
    if (b>=255){bup=0;}
    if (b<=0){bup=1;}

    delay(inc*2);
    rgb(r, g, b);
}

void rgb(int r, int g, int b)
{

  Serial.print("RGB: ");
  Serial.print(r);
  Serial.print(" ");
  Serial.print(g);
  Serial.print(" ");
  Serial.print(b);
  if (r>255) r=255;
  if (g>255) g=255;
  if (b>255) b=255;
  if (r<0) r=0;
  if (g<0) g=0;
  if (b<0) b=0;

  analogWrite(red, r);
  analogWrite(green, g);
  analogWrite(blue, b);
}

Good modding

Open Electronics 09 Nov 17:27
arduino  featured  gadget  ikea  mods