Kaku (klik aan klik uit) bediening met keypad en Nokia 5110
3 berichten
• Pagina 1 van 1
Kaku (klik aan klik uit) bediening met keypad en Nokia 5110
Doel :
Een controller bouwen die via RF 433.92MHz zogenaamde Klik aan Klik uit ontvangers kan aansturen.
Men moet een reeks van lichtpunten, rolluiken en stopkontakten kunnen schakelen.
De schakeling moet op batterijvoeding werken.
Opbouw:
Met de Menu keuze drukknop scrolt men door de 3 menu’s.
Met Selection - + kiest men de beschikbare lichtpunten, rolluiken en stopkontakten.
Met de On (of Up voor de rolluiken) en Off (of Down) knop stuurt men de schakelcommando’s.
De bediening gaat na een op voorhand instelbare tijd van inactiviteit in slaapmodus (bv 10s).
Met de WakeUp knop doet u de bediening ontwaken. Wanneer de bediening wakker is, brandt de LCD verlichting. Het stroomverbruik in werking bedraagt +/- 16mA. In slaapmodus is dit 1.6mA. De on led op de ProMini werd nog niet gedemonteerd. Zonder deze zal het stroomverbruik zich vermoedelijk beperken tot enkele tientallen uA. Het geheel wordt momenteel gevoed door 4 AA batterijen van 2300mAh.
De schakelcommando’s, het aantal lichtpunten, rolluiken en stopkontakten zit vast geprogrammeerd in de code. Men kan deze met de Arduino IDE eenvoudig aanpassen. Alle schakelcodes zitten als commentaar bijgevoegd.
Momenteel is de bediening voorzien voor 24 lichtpunten (+ 8 not used +1 all on/off), 6 rolluiken (+1 all on/off) en 3 stopkontakten.
- Code: Alles selecteren
/*
Kaku Remote Controller 433.92MHz with Nokia 5110 LCD and Keypad
Goes to sleep after a time called 'Active Time'.
This makes it possible to use battery power.
Written for Arduino ProMini.
Transmitter is on pin 13.
Liquid Crystal is using pins 12,11,10,9,8.
Keys ars using analog input A0
----------------------------------------- +5 Volt
| | | | | |
1 \ 2 \ 3 \ 4 \ 5 \ 6 \
| | | | | |
GND---4k7---1k5---1k5---2k7---5k6---15k---
|
|
A0
Switches from left to right :
Selection + LP, RL or RM (1)
Selection - LP, RL or RM (2)
RF On (3)
RF Off (4)
Selection Menu (5)
Optional (6)
WakeUp switch (to ground) is on pin 2.
Powerconsumption awake : 16mA
Powerconsumption PWR down Mode : 1.6mA
The on led is continuously on. Not tried it without the led.
It is assumed that the Nokia 5110 LCD module is connected to
the following pins using a levelshifter or resistors to get the
correct voltage to the module.
SCK - Pin 8 (10kOhm)
MOSI - Pin 9 (10kOhm)
DC - Pin 10 (10kOhm)
RST - Pin 11 (10kOhm)
CS - Pin 12 (10kOhm)
Display led (LIGHT) is connected with 100 Ohm to pin 7.
VCC from the display (+3.3V) is connected to +5V with 3 times diode 1N4148 in serial.
Dipswitches systemcode :
OFF = 1 (open contact)
ON = 0 (closed contact)
Examples dipswitch settings (left to right is switch 1 to switch 5) :
ON ON ON ON ON = 00000 (00) In the manual this is systemcode 12345.
OFF OFF OFF OFF OFF = 11111 (31) In the manual this is systemcode 0.
ON OFF ON OFF ON = 01010 (10) In the manual this is systemcode 135.
ON ON ON OFF OFF = 11100 (28) In the manual this is systemcode 123.
These switch commands are the 'switch on' commands.
'Switch off' command is 'switch on + 3'
1361,4433,5201,5393, // 00000 00 (A, B, C, D)
17745,20817,21585,21777, // 00001 01 (A, B, C, D)
66897,69969,70737,70929, // 00010 02 (A, B, C, D)
83281,86353,87121,87313, // 00011 03 (A, B, C, D)
263505,266577,267345,267537, // 00100 04 (A, B, C, D)
279889,282961,283729,283921, // 00101 05 (A, B, C, D)
329041,332113,332881,333073, // 00110 06 (A, B, C, D)
345425,348497,349265,349457, // 00111 07 (A, B, C, D)
1049937,1053009,1053777,1053969, // 01000 08 (A, B, C, D)
1066321,1069393,1070161,1070353, // 01001 09 (A, B, C, D)
1115473,1118545,1119327,1119505, // 01010 10 (A, B, C, D)
1131857,1134929,1135697,1135889, // 01011 11 (A, B, C, D)
1312081,1315153,1315921,1316113, // 01100 12 (A, B, C, D)
1328465,1331537,1332305,1332497, // 01101 13 (A, B, C, D)
1377617,1380689,1381457,1381649, // 01110 14 (A, B, C, D)
1394001,1397073,1397841,1398033, // 01111 15 (A, B, C, D)
4195665,4198737,4199505,4199697, // 10000 16 (A, B, C, D)
4212049,4215121,4215889,4216081, // 10001 17 (A, B, C, D)
4261021,4264273,4265041,4265233, // 10010 18 (A, B, C, D)
4277585,4280657,4281425,4281617, // 10011 19 (A, B, C, D)
4457809,4460881,4461649,4461841, // 10100 20 (A, B, C, D)
4474193,4477265,4478033,4478225, // 10101 21 (A, B, C, D)
4523345,4526417,4527185,4527377, // 10111 22 (A, B, C, D)
4539729,4542801,4543569,4543761, // 10111 23 (A, B, C, D)
5244241,5247313,5248081,5248273, // 11000 24 (A, B, C, D)
5260625,5263697,5264465,5264657, // 11001 25 (A, B, C, D)
5309777,5312849,5313617,5313809, // 11010 26 (A, B, C, D)
5326161,5329233,5330001,5330193, // 11011 27 (A, B, C, D)
5506385,5509457,5510225,5510417, // 11100 28 (A, B, C, D)
5522769,5525841,5526609,5526801, // 11101 29 (A, B, C, D)
5571921,5574993,5575761,5575953, // 01111 30 (A, B, C, D)
5588305,5591377,5592145,5592337, // 11111 31 (A, B, C, D)
by on1bte 01/08/2014
*/
#include <EEPROM.h>
#include <LCD5110_Basic.h>
// http://www.henningkarlsen.com/electronics/download.php?f=LCD5110_Basic.rar
#include <RCSwitch.h>
// http://code.google.com/p/rc-switch/
#include <avr/sleep.h>
String ln0 = "KAKU V_1.26";
String ln1;
String ln2;
String ln3;
int keyboardPin = 0; // Analog input pin that the keypad is attached to
int WakeUp = 2; // WakeUp Pin
int displayled = 7; // Display Lightning leds
int Tx = 13; // Transmitter pin
int PulseLength = 315; // Transmitter Pulse Length
int Menu_addr = 0; // Menu eeprom saving address
int Menu; // Menu (Menu)
int Menu_Max = 3; // Fill in the maximum used menu entries
int LP_addr = 1; // Lightpoint Eeprom saving address
int LP; // LP (= Lightpoint)
int LP_Max = 33; // Fill in the maximum used Lightpoints
int RL_addr = 2; // Rol Eeprom saving address
int RL; // RL (Rolling shutter)
int RL_Max = 7; // Fill in the maximum used Rol's
int RM_addr = 3; // Remotes Eeprom saving address
int RM; // RM (Remotes)
int RM_Max = 3; // Fill in the maximum used Remotes
int ActiveTime = 10000; // Active time before going to sleep in milliseconds
int keypressed = 0; // Default keypressed = 0
int keyboardValue = 0; // value read from the keyboard
long StartTime; // From this point the active time starts counting
RCSwitch mySwitch = RCSwitch();
LCD5110 myGLCD(8,9,10,11,12);
extern uint8_t SmallFont[];
// initialize LightpointsmyLPs
char* myLPs[]={
"Keuken_Tafel", "Keuken_Wand", "Keuken_Micro", "Keuken_Wasbak", "Tussen_Hal",
"Inkom_Hal","Bureel_Slk", "Vestiaire", "Living_Salon", "Living_Tafel",
"Garage_Links", "Garage_Rechts", "Zolder", "Slaap_Ouders", "Slaap_Hanne",
"Slaap_Karen", "Nacht_Hal", "Hobby_Ruimte", "Hobby_Tafel", "Buiten_Terras",
"Buiten_Deur", "Buiten_Garage", "Badkamer", "Berging_Links", "Not_Used",
"Not_Used", "Not_Used", "Not_Used", "Not_Used", "Not_Used",
"Not_Used", "Not_Used", "All_On/Off"};
char* myRLs[]={
"Rolluik 1", "Rolluik 2", "Rolluik 3", "Rolluik 4", "Rolluik 5",
"Rolluik 6", "Rolluik All"};
char* myRMs[]={
"Remote 1", "Remote 2", "Remote 3"};
char* line1[]={
"01", "02", "03", "04", "05","06","07", "08", "09", "10",
"11", "12", "13", "14", "15","16", "17", "18", "19", "20",
"21", "22", "23", "24", "25","26", "27", "28", "29", "30",
"31", "32", "33"};
// initialize switch commands
unsigned long switch_bits = 24;
// switch commands are the 'switch on' commands
// switch off command is 'switch on + 3'
unsigned long switch_LP_commands [] = {
1394001,1397073,1397841,1398033, // 01111 15 (A, B, C, D)
4539729,4542801,4543569,4543761, // 10111 23 (A, B, C, D)
5326161,5329233,5330001,5330193, // 11011 27 (A, B, C, D)
5522769,5525841,5526609,5526801, // 11101 29 (A, B, C, D)
5571921,5574993,5575761,5575953, // 01111 30 (A, B, C, D)
345425,348497,349265,349457, // 00111 07 (A, B, C, D)
1131857,1134929,1135697,1135889, // 01011 11 (A, B, C, D)
1328465,1331537,1332305,1332497, // 01101 13 (A, B, C, D)
1115473}; // 01010 10 (A)
unsigned long switch_RL_commands [] = {
1049937,1053009,1053777,1053969, // 01000 08 (A, B, C, D)
1066321,1069393,1070161,1070353}; // 01001 09 (A, B, C, D)
unsigned long switch_RM_commands [] = {
4457809,4460881,4461649,4461841}; // 10100 20 (A, B, C, D)
//In the manual this is systemcode 245.
void setup()
{
//Serial.begin(115200); //hardware serial to PC
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
digitalWrite (WakeUp, HIGH); // pull-up the interrupt pin
pinMode(displayled, OUTPUT); // define displayled as an output
digitalWrite (displayled, LOW); // activate display leds
LP = EEPROM.read(LP_addr); // Read the last Lightpoint position
if(LP>LP_Max) LP=0; // When EEPROM read is higher then Max used LP's --> LP = 0
RL = EEPROM.read(RL_addr); // Read the last Rol position
if(RL>RL_Max) RL=0; // When EEPROM read is higher then Max used RL's --> RL = 0
RM = EEPROM.read(RM_addr); // Read the last Remote position
if(RM>RM_Max) RM=0; // When EEPROM read is higher then Max used RM's --> RM = 0
Menu = EEPROM.read(Menu_addr); // Read the last Menu position
if(Menu>Menu_Max) Menu=0; // When EEPROM read is higher then Max used Menu's --> Menu = 0
mySwitch.enableTransmit(Tx); // Transmitter pin enable
mySwitch.setProtocol(1); // Optional set protocol (default is 1, will work for most outlets)
mySwitch.setPulseLength(PulseLength); // Optional set pulse length.
//mySwitch.setRepeatTransmit(5); // Optional set number of transmission repetitions.
ln1 = "Domotica";
ln2 = "********";
lcd_write();
delay(3000);
if (Menu == 0)
{
ln1 = line1[LP];
ln2 = myLPs[LP];
ln3 = " ";
lcd_write();
}
else if (Menu == 1)
{
ln1 = line1[RL];
ln2 = myRLs[RL];
ln3 = " ";
lcd_write();
}
else
{
ln1 = line1[RM];
ln2 = myRMs[RM];
ln3 = " ";
lcd_write();
}
StartTime = millis(); // Startpoint
}
void loop()
{
keyboardValue = analogRead(keyboardPin); // read the keyboard value (0 - 1023)
while (keyboardValue < 75){
//do nothing until a key is pressed
keyboardValue = analogRead(keyboardPin);
if ((millis() - StartTime)>ActiveTime) sleepNow();
delay(50);
} //end of do nothing till a key is pressed
readkeyboard(); //get the value of key being pressed "keypressed"
{
StartTime = millis();
switch (keypressed) {
case 1: // +
if (Menu == 0)
{
if(LP==LP_Max-1) LP=LP+1-LP_Max;
else {LP=LP++;}
EEPROM.write(LP_addr, LP); // Hold the last Lightpoint position
ln1 = line1[LP];
ln2 = myLPs[LP];
ln3 = " ";
lcd_write();
}
else if (Menu == 1)
{
if(RL==RL_Max-1) RL=RL+1-RL_Max;
else {RL=RL++;}
EEPROM.write(RL_addr, RL); // Hold the last Rol position
ln1 = line1[RL];
ln2 = myRLs[RL];
ln3 = " ";
lcd_write();
}
else
{
if(RM==RM_Max-1) RM=RM+1-RM_Max;
else {RM=RM++;}
EEPROM.write(RM_addr, RM); // Hold the last Rem position
ln1 = line1[RM];
ln2 = myRMs[RM];
ln3 = " ";
lcd_write();
}
break;
case 2: // -
if (Menu ==0)
{
if(LP==0) LP=LP_Max-1; else {LP=LP-1;}
EEPROM.write(LP_addr, LP); // Hold the last Lightpoint position
ln1 = line1[LP];
ln2 = myLPs[LP];
ln3 = " ";
lcd_write();
}
else if (Menu == 1)
{
if(RL==0) RL=RL_Max-1; else {RL=RL-1;}
EEPROM.write(RL_addr, RL); // Hold the last Rol position
ln1 = line1[RL];
ln2 = myRLs[RL];
ln3 = " ";
lcd_write();
}
else
{
if(RM==0) RM=RM_Max-1; else {RM=RM-1;}
EEPROM.write(RM_addr, RM); // Hold the last Rem position
ln1 = line1[RM];
ln2 = myRMs[RM];
ln3 = " ";
lcd_write();
}
break;
case 3: // ^ used for the ON function (or UP for Rol)
if (Menu == 0)
{
ln1 = line1[LP];
ln2 = myLPs[LP];
ln3 = "ON";
lcd_write();
switching_LP_on ();
delay (200);
myGLCD.print(" ", CENTER, 40);
}
else if (Menu == 1)
{
ln1 = line1[RL];
ln2 = myRLs[RL];
ln3 = "UP";
lcd_write();
switching_RL_on ();
delay (200);
myGLCD.print(" ", CENTER, 40);
}
else
{
ln1 = line1[RM];
ln2 = myRMs[RM];
ln3 = "ON";
lcd_write();
switching_RM_on ();
delay (200);
myGLCD.print(" ", CENTER, 40);
}
break;
case 4: // _ used for the OFF function (or DOWN for Rol)
if (Menu == 0)
{
ln1 = line1[LP];
ln2 = myLPs[LP];
ln3 = "OFF";
lcd_write();
switching_LP_off ();
delay (200);
myGLCD.print(" ", CENTER, 40);
}
else if (Menu == 1)
{
ln1 = line1[RL];
ln2 = myRLs[RL];
ln3 = "DOWN";
lcd_write();
switching_RL_off ();
delay (200);
myGLCD.print(" ", CENTER, 40);
}
else
{
ln1 = line1[RM];
ln2 = myRMs[RM];
ln3 = "OFF";
lcd_write();
switching_RM_off ();
delay (200);
myGLCD.print(" ", CENTER, 40);
}
break;
case 5: // S (Select)
if(Menu==Menu_Max-1) Menu=Menu+1-Menu_Max;
else {Menu=Menu++;}
EEPROM.write(Menu_addr, Menu);
if (Menu == 0)
{
ln1 = line1[LP];
ln2 = myLPs[LP];
ln3 = " ";
lcd_write();
}
else if (Menu == 1)
{
ln1 = line1[RL];
ln2 = myRLs[RL];
ln3 = " ";
lcd_write();
}
else
{
ln1 = line1[RM];
ln2 = myRMs[RM];
ln3 = " ";
lcd_write();
}
break;
case 6: // R (Return)
// write action
break;
}
}
}
void lcd_write()
{
myGLCD.clrScr();
myGLCD.print(ln0,CENTER, 0);
myGLCD.print(ln1,CENTER, 16);
myGLCD.print(ln2,CENTER, 24);
myGLCD.print(ln3, CENTER, 40);
}
void switching_LP_on()
{
mySwitch.send(switch_LP_commands [LP], switch_bits);
} // end of the switching on routine lightpoints
void switching_LP_off()
{
mySwitch.send(switch_LP_commands [LP] + 3, switch_bits);
} // end of the switching off routine lightpoints
void switching_RL_on()
{
mySwitch.send(switch_RL_commands [RL], switch_bits);
} // end of the switching on routine rol
void switching_RL_off()
{
mySwitch.send(switch_RL_commands [RL] + 3, switch_bits);
} // end of the switching off routine rol
void switching_RM_on()
{
mySwitch.send(switch_RM_commands [RM], switch_bits);
} // end of the switching on routine remotes
void switching_RM_off()
{
mySwitch.send(switch_RM_commands [RM] + 3, switch_bits);
} // end of the switching off routine remotes
void wake()
{
sleep_disable(); // first thing after waking from sleep:
detachInterrupt (0); // stop many many interrupts
//Serial.println("Wakker");
} // end of the wake routine
void sleepNow()
{
myGLCD.clrScr(); // clear the display
digitalWrite (displayled, HIGH);
//Serial.println("Slapen");
//delay(1);
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register
attachInterrupt(0, wake, LOW);
sleep_mode(); // here the device is actually put to sleep!!
// awake : write active Menu to display
if (Menu == 0)
{
ln1 = line1[LP];
ln2 = myLPs[LP];
ln3 = " ";
lcd_write();
}
else if (Menu == 1)
{
ln1 = line1[RL];
ln2 = myRLs[RL];
ln3 = " ";
lcd_write();
}
else
{
ln1 = line1[RM];
ln2 = myRMs[RM];
ln3 = " ";
lcd_write();
}
digitalWrite (displayled, LOW);
StartTime = millis(); // set StartTime
} // end of the sleep now routine
// read the keyboard routine
void readkeyboard(){
keyboardValue = analogRead(keyboardPin); // read the value (0-1023)
//Serial.println(keyboardValue);
if ((keyboardValue >900)){keypressed = 1;}
if ((keyboardValue >701) && (keyboardValue < 900)){keypressed = 2;}
if ((keyboardValue >543) && (keyboardValue < 701)){keypressed = 3;}
if ((keyboardValue >382) && (keyboardValue < 543)){keypressed = 4;}
if ((keyboardValue >236) && (keyboardValue < 382)){keypressed = 5;}
if ((keyboardValue >75) && (keyboardValue < 236)){keypressed = 6;}
delay (200);
/* while (keyboardValue > 75) {
delay (100);
keyboardValue = analogRead(keyboardPin); // read the value (0-1023)
} // wait until key no longer being pressed before continuing
*/
} // end of read the keyboard routine
Advertisement
Re: Kaku (klik aan klik uit) bediening met keypad en Nokia 5
Hallo,
Heb je de power led al uitgeschakeld en wat is het resutaal dan in stroom verbruik/
Ik werkt namelijk ook met een promini en wil ook een laag stroom verbruik.
Graag een reactie
Groeten Jan Willen M
Heb je de power led al uitgeschakeld en wat is het resutaal dan in stroom verbruik/
Ik werkt namelijk ook met een promini en wil ook een laag stroom verbruik.
Graag een reactie
Groeten Jan Willen M
Re: Kaku (klik aan klik uit) bediening met keypad en Nokia 5
Neen, dit heb ik niet meer geprobeerd.
Gr.,
Patrick
Gr.,
Patrick
3 berichten
• Pagina 1 van 1
Terug naar Afgeronde projecten
Wie is er online?
Gebruikers in dit forum: Geen geregistreerde gebruikers en 27 gasten