Skip to content

Commit 13e69f0

Browse files
authored
Add files via upload
Sketch for small USB-powered device to open Came gates with known codes - you need to put your codes in file after `// Defind gate codes` line. (You may use RCSwitch library to sniff gate code from air - it works fine for reception but I failed to use it for transmission so custom function is used). Device itself consists of Arduino Nano, 3x4 Keypad and 433 MHz transmitter. Each button have a 24-bit code assigned - this code is send via @433 MHz with Came-gate encoding. Pins from 3 to 9 are connected to Keypad, pin 11 is connected to trasmitter DATA pin. Transmitted is powered from GND and +5V pins of Arduino.
1 parent 63cea10 commit 13e69f0

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

Came_Gates_Control.ino

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#include <Keypad.h>
2+
//=================================================================================================
3+
#define TX_PIN 11
4+
#define LED_PIN 13
5+
#define BIT_LEN 320
6+
#define BLINK_INTERVAL 500
7+
//=================================================================================================
8+
// Setup Keypad
9+
const byte ROWS = 4;
10+
const byte COLS = 3;
11+
char keys[ROWS][COLS] =
12+
{
13+
{'1','2','3'},
14+
{'4','5','6'},
15+
{'7','8','9'},
16+
{'*','0','#'}
17+
};
18+
byte rowPins[ROWS] = {8, 3, 4, 6};
19+
byte colPins[COLS] = {7, 9, 5};
20+
21+
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
22+
//=================================================================================================
23+
// Defind gate codes
24+
#define GATE_MAIN_IN 0xAAAAAA
25+
#define GATE_MAIN_OUT 0xBBBBBB
26+
#define GATE_PARK_NEAR_IN 0xCCCCCC
27+
#define GATE_PARK_NEAR_OUT 0xDDDDDD
28+
#define GATE_PARK_FAR_IN 0xEEEEEE
29+
#define GATE_PARK_FAR_OUT 0xFFFFFF
30+
//=================================================================================================
31+
// Global variables
32+
unsigned long previousMillis = 0;
33+
int LED_state = LOW;
34+
//=================================================================================================
35+
// Send code vith help of 433 MHz transmitter connected to TX_PIN
36+
void SendCame(unsigned long code)
37+
{
38+
int repeat_count;
39+
repeat_count = 24;
40+
41+
for (int j=0; j<repeat_count; j++)
42+
{
43+
digitalWrite(TX_PIN, LOW);
44+
delayMicroseconds(BIT_LEN * 63);
45+
digitalWrite(TX_PIN, HIGH);
46+
delayMicroseconds(BIT_LEN);
47+
48+
//Sending bit by bit
49+
for (int i=23; i>=0; i--)
50+
{ // 0 -> 011, 1 -> 001
51+
byte b = bitRead(code, i);
52+
53+
digitalWrite(TX_PIN,LOW);
54+
delayMicroseconds(BIT_LEN);
55+
56+
if (!b)
57+
digitalWrite(TX_PIN,HIGH);
58+
delayMicroseconds(BIT_LEN);
59+
60+
digitalWrite(TX_PIN,HIGH);
61+
delayMicroseconds(BIT_LEN);
62+
}
63+
digitalWrite(TX_PIN,LOW);
64+
delay(16);
65+
}
66+
}
67+
//-------------------------------------------------------------------------------------------------
68+
void setup()
69+
{
70+
delay(200);
71+
72+
// Setup outpus for transmitter and LED pins
73+
pinMode(TX_PIN, OUTPUT);
74+
pinMode(LED_PIN, OUTPUT);
75+
76+
Serial.begin(9600); // Kept for keypad diagnostics
77+
}
78+
//-------------------------------------------------------------------------------------------------
79+
void loop()
80+
{
81+
unsigned long currentMillis = millis();
82+
83+
char key = keypad.getKey();
84+
85+
if (key)
86+
{
87+
Serial.println(key); // Just for diagnostics
88+
89+
switch (key)
90+
{
91+
case '3':
92+
SendCame(GATE_MAIN_IN);
93+
break;
94+
case '6':
95+
SendCame(GATE_MAIN_OUT);
96+
break;
97+
case '9':
98+
SendCame(GATE_PARK_NEAR_IN);
99+
break;
100+
case '#':
101+
SendCame(GATE_PARK_NEAR_OUT);
102+
break;
103+
case '8':
104+
SendCame(GATE_PARK_FAR_IN);
105+
break;
106+
case '0':
107+
SendCame(GATE_PARK_FAR_OUT);
108+
break;
109+
}
110+
}
111+
112+
// Simply blink LED to show that board is alive
113+
if (currentMillis - previousMillis >= BLINK_INTERVAL)
114+
{
115+
previousMillis = currentMillis;
116+
if (LED_state == LOW)
117+
LED_state = HIGH;
118+
else
119+
LED_state = LOW;
120+
digitalWrite(LED_PIN, LED_state);
121+
}
122+
}
123+
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)