- makeITcircular 2024 content launched – Part of Maker Faire Rome 2024Posted 2 months ago
- Application For Maker Faire Rome 2024: Deadline June 20thPosted 3 months ago
- Building a 3D Digital Clock with ArduinoPosted 8 months ago
- Creating a controller for Minecraft with realistic body movements using ArduinoPosted 9 months ago
- Snowflake with ArduinoPosted 9 months ago
- Holographic Christmas TreePosted 9 months ago
- Segstick: Build Your Own Self-Balancing Vehicle in Just 2 Days with ArduinoPosted 10 months ago
- ZSWatch: An Open-Source Smartwatch Project Based on the Zephyr Operating SystemPosted 11 months ago
- What is IoT and which devices to usePosted 11 months ago
- Maker Faire Rome Unveils Thrilling “Padel Smash Future” Pavilion for Sports EnthusiastsPosted 11 months ago
Remote-controlled fiber-optic Ceiling Light with Arduino
Mauro Alfieri, who wants to partecipate to our iniziative “TiDiGino Contest”, sent us his new application with Arduino to demonstrate his skills in this field: a Remote-controlled fiber-optic Ceiling Light.
Mauro decribes himself:
Today my work is focused on open-source systems, supporting networking (CCNA) and scripting language programming, in small and mid-sized companies that use Linux/Aix.
Since I was 10 years old, I started mounting small electronic kits headed from my father and then – during my teens – by alone; recently I discovered Arduino that is for me the perfect combination in programming skills ( Bash, Csh, PHP, Perl, HTML, JavaScript, …) and electronics.
So I began to study and to use Arduino to control LED lighting: finally, I built my first project: this Remote-controlled fiber-optic Ceiling Light.
The Project
The idea was to built a ceiling lamp that lights with a little surprise: a starry sky in my living room, even in the dark nights.
To achieve my goal I used a wood table with many holes with different diameters that house the optical fibers. The size of the ceiling lamp (90 cmx 60 cm) did not allow me to use a single bundle of fibers and this is the reason of the two beams I used, each of which comes with a LEDs illuminator as shown:
Each element is made with four LEDs connected in common anode way as shown in the figure:
The schematic with Arduino and its control circuit is shown in the figure above: it is a very simple circuit that I built on a breadboard. To control the high-brightness LEDs I used 4 transistors TIP122 whose base is driven with a PWM signal generated by Arduino. Each Arduino PWM output in connected to the each transistor base via a resistor of 1 kohm. The same type of LEDs are connected in series and hosted one in the first illuminator and the other in the second. The line is connected to the positive external power supply via a 470 Ohm resistor.
The transistor connected to the white LEDs is connected to pin 10 of Arduino, the TIP122 of the red LEDs to pin 9, the green LEDs to pin 6, that of the blue LEDs to pin 5.
Finally, the IR receiver (TSOP31238) is connected to the positive line of Arduino with a resistor of 100 Ohm and whose output is connected to pin 11.
Sketch:
#include <IRremote.h> #define DELAY_CROMO 100 // Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param #define FNV_PRIME_32 16777619 #define FNV_BASIS_32 2166136261 int lettura; int pLettura; int pinLed[] = {9,6,5,10}; int fade[] = {255, 180, 128, 90, 64, 45, 32, 23, 16, 12, 8, 6, 4, 3, 2, 1,0}; int RECV_PIN = 11; boolean _loop = true; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { _initLeds(); // Init Led irrecv.enableIRIn(); // Start the receiver //Serial.begin(9600); } // Compare two tick values, returning 0 if newval is shorter, // 1 if newval is equal, and 2 if newval is longer // Use a tolerance of 20% int compare(unsigned int oldval, unsigned int newval) { if (newval < oldval * .8) { return 0; } else if (oldval < newval * .8) { return 2; } else { return 1; } } /* Converts the raw code values into a 32-bit hash code. * Hopefully this code is unique for each button. */ unsigned long decodeHash(decode_results *results) { unsigned long hash = FNV_BASIS_32; for (int i = 1; i+2 < results->rawlen; i++) { int value = compare(results->rawbuf[i], results->rawbuf[i+2]); // Add value into the hash hash = (hash * FNV_PRIME_32) ^ value; } return hash; } void _initLeds() { for (int i=0; i<4; i++) { pinMode(pinLed[i], OUTPUT); analogWrite(pinLed[i], LOW); } } void _LedRGBOn() { for (int i=0; i<3; i++) { analogWrite(pinLed[i], 255); } } void ledFade(int ledpin, int time_wait) { for (int i=0; i<17; i++) { int j=16; analogWrite(ledpin, fade[j-i]); delay(time_wait); } delay(time_wait); for (int i=16; i>=0; i--) { int j=16; analogWrite(ledpin, fade[j-i]); delay(time_wait); } } void twoLedFade(int ledpin1, int ledpin2, int time_wait) { for (int i=0; i<17; i++) { int j=16; analogWrite(ledpin1, fade[j-i]); analogWrite(ledpin2, fade[i]); delay(time_wait); } delay(time_wait); for (int i=16; i>=0; i--) { int j=16; analogWrite(ledpin1, fade[j-i]); analogWrite(ledpin2, fade[i]); delay(time_wait); } } void threeLedFade(int ledpin1, int ledpin2, int ledpin3, int time_wait) { if ( _loop ) { for (int i=0; i<17; i++) { int j=16; analogWrite(ledpin1, fade[j-i]); analogWrite(ledpin2, 0); analogWrite(ledpin3, 0); delay(time_wait); } delay(time_wait); } for (int i=16; i>=0; i--) { int j=16; analogWrite(ledpin1, fade[j-i]); analogWrite(ledpin2, fade[i]); analogWrite(ledpin3, 0); delay(time_wait); } delay(time_wait); for (int i=0; i<17; i++) { int j=16; analogWrite(ledpin1, 0); analogWrite(ledpin2, fade[i]); analogWrite(ledpin3, fade[j-i]); delay(time_wait); } delay(time_wait); for (int i=16; i>=0; i--) { int j=16; analogWrite(ledpin1, fade[i]); analogWrite(ledpin2, 0); analogWrite(ledpin3, fade[j-i]); delay(time_wait); } _loop = false; delay(time_wait); } void _LedWhiteOn() { analogWrite(pinLed[3], 255); } void loop() { if (irrecv.decode(&results)) { unsigned long hash = decodeHash(&results); switch (hash) { case 0xA4F80719: // Off lettura=0; break; case 0xB9F56762: // 0 (10) lettura=0; break; case 0x8B8510E8: // 9 lettura=9; break; case 0x6825E53E: // 8 lettura=8; break; case 0x4592E14C: // 7 lettura=7; break; case 0x2C452C6C: // 6 lettura=6; break; case 0x731A3E02: // 5 lettura=5; break; case 0xF5999288: // 4 lettura=4; break; case 0x273009C4: // 3 lettura=3; break; case 0xAD586662: // 2 lettura=2; break; case 0xE13DDA28: // 1 lettura=1; break; default: Serial.print("Unknown "); Serial.println(hash, HEX); } irrecv.resume(); // Resume decoding (necessary!) } if ( lettura != pLettura ) { _initLeds(); } Serial.print("Valore Corrente: "); Serial.print( lettura ); Serial.print(", Valore Precedente: "); Serial.println( pLettura ); pLettura = lettura; switch (pLettura) { case 0: _initLeds(); break; case 1: ledFade(pinLed[0], DELAY_CROMO); break; case 2: ledFade(pinLed[1], DELAY_CROMO); break; case 3: ledFade(pinLed[2], DELAY_CROMO); break; case 4: twoLedFade(pinLed[0], pinLed[1], DELAY_CROMO); break; case 5: twoLedFade(pinLed[1], pinLed[2], DELAY_CROMO); break; case 6: twoLedFade(pinLed[0], pinLed[2], DELAY_CROMO); break; case 7: threeLedFade(pinLed[0], pinLed[1], pinLed[2], DELAY_CROMO); break; case 8: _LedRGBOn(); break; case 9: _LedWhiteOn(); break; } }
I use a remote control from SAMSUNG whose signals, however, my library doesn’t recognize. So, to decode signals, I need to use decodeHash and appare functions.
By pressing button n. 1, red light starts fading.
By pressing button n. 2, green light starts fading.
By pressing button n. 3, blue light starts fading.
By pressing button n. 4, red and green LEDs light up in sequence.
By pressing button n. 5 green and blue LEDs light up in sequence.
By pressing button n. 6 red and blue LEDs light up in sequence.
By pressing button n. 7 red, green and blue LEDs light up in sequence.
By pressing button n. 8 all the red, green and blue LEDs light up.
By pressing button n. 9 the white LEDs light up.
By pressing button n. 0 or the OFF button on the remote control, all the LEDs turn OFF.
And here’s the lamp with white LEDs ON:
Download
Arduino Sketch | |
Library |
2 Comments