3 Connect Arduino ProMini 3.3V 8Mhz Atmega328 to Raspberry Pi
13 // 3 433Mhz outdoor temperature sensor receiver # DISABLED
25 #include <DallasTemperature.h>
27 RCSwitch mySwitch = RCSwitch();
31 DallasTemperature sensors(&oneWire);
34 // 513Mhz light sockets
38 int int_0 = 300; // ms
39 int int_1 = 900; // ms
40 int wait = 2000; // ms
41 int repeat = 5; // times
43 void send_513(char *code) {
44 Serial.print("send 513Mhz ");
47 // we have to send same signal at least two times
48 for(int r = 0; r < repeat; r++ ) {
50 digitalWrite(LED_PIN, HIGH);
52 for(int i = 0; i < strlen(code); i++) {
55 if (code[i] == '1' ) {
59 digitalWrite(TX_PIN, HIGH);
60 delayMicroseconds(i1);
61 digitalWrite(TX_PIN, LOW);
62 delayMicroseconds(i2);
65 delayMicroseconds(wait); // guess
68 digitalWrite(LED_PIN, LOW);
80 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
81 mySwitch.enableTransmit(10); // with sender wired in receiving doesn't work, pin #10
89 Serial.print("press buttons on remote or send AB where A = socket (0..9), B = state (0 = off, 1 = on)\nB00...00 (24 digits) to send binary\n");
93 char serial_data[2]; // socket (0-9), state (0-1)
97 if (mySwitch.available()) {
98 Serial.print(mySwitch.getReceivedBitlength());
99 Serial.print(" bits ");
100 Serial.println(mySwitch.getReceivedValue(), BIN);
101 mySwitch.resetAvailable();
103 if (Serial.available() > 0) {
104 char input = Serial.read();
105 if ( input == 'T' ) {
106 Serial.print("DS18B20 temperature = ");
107 sensors.requestTemperatures();
108 Serial.println( sensors.getTempCByIndex(0) );
111 if ( input == 'B' ) {
112 Serial.readBytesUntil('\n', binary_data, sizeof(binary_data));
113 Serial.print("send B");
114 Serial.println( binary_data );
115 mySwitch.send( binary_data );
118 // light sockets at 513 Mhz
120 send_513("1000100110110000000000010");
123 send_513("1011001001011111000000010");
128 Serial.print("temperature=");
129 Serial.print(dht.getTemperature());
130 Serial.print(" humidity=");
131 Serial.print(dht.getHumidity());
132 Serial.print(" status=");
133 Serial.println(dht.getStatusString());
136 if ( input >= 0x30 && input <= 0x39 ) {
137 input = input - 0x30; // ASCII to number
138 serial_data[serial_pos++] = input;
140 Serial.print("ignore: ");
141 Serial.println(input, HEX);
144 if ( serial_pos == 2 ) {
145 Serial.print("socket: ");
146 Serial.print(serial_data[0], DEC);
147 Serial.print(" state: ");
148 Serial.println(serial_data[1] ? "on" : "off");
150 byte on = serial_data[1];
152 // switches, 433 Mhz set of 3
153 switch ( serial_data[0] ) {
155 on ? mySwitch.send("110101011101010000001100")
156 : mySwitch.send("110101011101010000000011");
159 on ? mySwitch.send("110101010111010000001100")
160 : mySwitch.send("110101010111010000000011");
163 on ? mySwitch.send("110101010101110000001100")
164 : mySwitch.send("110101010101110000000011");
167 on ? mySwitch.send("001111110000000011000000")
168 : mySwitch.send("001111110000000000000000");
171 Serial.print("invalid switch on number ");
172 Serial.println(serial_data[0], DEC);