Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Joey Pongallo
Published

SMART Home LED Lighting System and More

A touchscreen in the wall that allows you to control each and every LED light in your ceiling independently and phone controllable!

IntermediateWork in progress4 hours18,278
SMART Home LED Lighting System and More

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
Bluetooth module
×1
KRIDA 8 Channel Dimmer
×1
Drop Ceiling LED Lamp
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Element14 7" touchscreen
×1

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

8Channel dimmer working on arduino with bluetooth

This is just a teaser image of the arduino hooked up to the bluetooth and 8 channel dimmer module. It is currently operating successfully.

Client side UI sample 7/3/2018

This is my progress so far with the UI that will appear on the touchscreen. I have bluetooth search functions built in.

Code

Main

C/C++
Place this code into an arduino ino file. Must reference the TimerOne library. Link in the code.
/*AC Light Control FOR 8 CHANNEL UNIT

Updated by Joey Pongallo
6/23/2018
JoeyPongallo@gmail.com

Revised code from Robert Twomey who Adapted from Ryan McLaughlin  

*/

#include  <TimerOne.h>			  // Avaiable from http://www.arduino.cc/playground/Code/Timer1
volatile int i = 0;               // Variable to use as a counter volatile as it is in an interrupt
volatile int i2 = 0;
volatile boolean zero_cross = 0;  // Booleans to store a "switch" to tell us if we have crossed zero
volatile boolean zero_cross2 = 0;

int channel1 = 4;                // Output to Opto Triac / Channels
int channel2 = 5;
int channel3 = 6;
int channel4 = 7;
int channel5 = 8;
int channel6 = 9;
int channel7 = 10;
int channel8 = 11;

int dim = 0;                    // Dimming level (0-128)  0 = on, 128 = 0ff
int dim2 = 0;
int dim3 = 0;
int dim4 = 0;
int dim5 = 0;
int dim6 = 0;
int dim7 = 0;
int dim8 = 0;


int freqStep = 65;    // This is the delay-per-brightness step in microseconds.
					  // For 60 Hz it should be 65
					  // It is calculated based on the frequency of your voltage supply (50Hz or 60Hz)
					  // and the number of brightness steps you want. 
					  // 
					  // Realize that there are 2 zerocrossing per cycle. This means
					  // zero crossing happens at 120Hz for a 60Hz supply or 100Hz for a 50Hz supply. 
					  // To calculate freqStep divide the length of one full half-wave of the power
					  // cycle (in microseconds) by the number of brightness steps. 
					  //
					  // (120 Hz=8333uS) / 128 brightness steps = 65 uS / brightness step
					  // (100Hz=10000uS) / 128 steps = 75uS/step


void setup() {                                    
	pinMode(channel1, OUTPUT);                          // Set the Triac pins as output
	pinMode(channel2, OUTPUT);
	attachInterrupt(1, zero_cross_detect, RISING);    // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
	Timer1.initialize(freqStep);                      // Initialize TimerOne library for the freq we need
	Timer1.attachInterrupt(dim_check, freqStep);
	// Use the TimerOne Library to attach an interrupt
	// to the function we use to check to see if it is 
	// the right time to fire the triac.  This function 
	// will now run every freqStep in microseconds.    
	Serial.begin(9600);
}

void zero_cross_detect() {
	zero_cross = true;               // set the boolean to true to tell our dimming function that a zero cross has occured
	zero_cross2 = true;
	i = 0;
	i2 = 0;
	digitalWrite(channel1, LOW);       // turn off TRIAC (and AC)
	digitalWrite(channel2, LOW);
}

// Turn on the TRIAC at the appropriate time
void dim_check() {
	if (zero_cross == true) {

		if (i >= dim) {
			//Serial.println(i);
			digitalWrite(channel1, HIGH); // turn on light       
			i = 0;  // reset time step counter                         
			zero_cross = false; //reset zero cross detection
		}
		else {
			i++; // increment time step counter                     
		}
	}

	if (zero_cross2 == true) {
		if (i2 >= dim2) {
			//Serial.println(i2);
			digitalWrite(channel2, HIGH); // turn on light       
			i2 = 0;  // reset time step counter                         
			zero_cross2 = false; //reset zero cross detection
		}
		else {
			i2++; // increment time step counter                     
		}
	}

}

void loop() {

	/*Serial.println(dim);
	Serial.println(dim2);
*/
/*if (dim >= 199)
	dim = 199;
if (dim <= 5)
	dim = 5;*/


	if (Serial.available() > 0) {

		//char data = Serial.read(); // reading the data received from the bluetooth module
		int value = Serial.parseInt();

		if (value > 1000 && value < 2000) {

			dim = value - 1000;
			dim = filterDimmingValue(dim);
			Serial.println("Channel1: " + dim);
		}

		if (value > 2000 && value < 3000) {
			dim2 = value - 2000;
			dim2 = filterDimmingValue(dim2);
			Serial.println("Channel2: " + dim);
		}

		// Turn all lights off
		if (value == 0) {
			dim = 128;
			dim2 = 128;
		}

		// Turn all lights on max
		if (value == 9999) {
			dim = 5;
			dim2 = 5;
		}


	}

	delay(5);
}


int filterDimmingValue(int value) {
	if (value > 128)
		value = 128;
	if (value < 5)
		value = 5;
	return value;
}

Credits

Joey Pongallo
5 projects • 5 followers

Comments