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 // 315Mhz light sockets
37 #define LED_ON digitalWrite(LED_PIN, HIGH);
38 #define LED_OFF digitalWrite(LED_PIN, LOW);
40 int int_0 = 300; // ms
41 int int_1 = 900; // ms
42 int wait = 2000; // ms
43 int repeat = 20; // times (5 times seem a little low for sensors which are more than 10m away)
45 void send_315(char *code) {
46 Serial.print("send 315Mhz ");
49 // we have to send same signal at least two times
50 for(int r = 0; r < repeat; r++ ) {
52 digitalWrite(LED_PIN, HIGH);
54 for(int i = 0; i < strlen(code); i++) {
57 if (code[i] == '1' ) {
61 digitalWrite(TX_PIN, HIGH);
62 delayMicroseconds(i1);
63 digitalWrite(TX_PIN, LOW);
64 delayMicroseconds(i2);
67 digitalWrite(LED_PIN, LOW);
69 delayMicroseconds(wait); // guess
79 #include "RunningAverage.h"
81 RunningAverage temp_avg(10);
82 RunningAverage hum_avg(10);
87 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");
92 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
93 mySwitch.enableTransmit(10); // with sender wired in receiving doesn't work, pin #10
94 mySwitch.setRepeatTransmit(repeat); // or change to be different for 433 and 315 MHz
102 temp_avg.addValue( dht.getTemperature() );
103 hum_avg.addValue( dht.getHumidity() );
108 char serial_data[2]; // socket (0-9), state (0-1)
109 char binary_data[32];
110 int dht22_errors = 0;
112 unsigned long time = millis();
115 if ( millis() - time > 2000 ) {
116 float t = dht.getTemperature();
117 if ( dht.getStatus() == 0 )
118 temp_avg.addValue( t );
120 float h = dht.getHumidity();
121 if ( dht.getStatus() == 0 )
122 hum_avg.addValue( h );
127 if (mySwitch.available()) {
128 Serial.print(mySwitch.getReceivedBitlength());
129 Serial.print(" bits ");
130 Serial.println(mySwitch.getReceivedValue(), BIN);
131 mySwitch.resetAvailable();
133 if (Serial.available() > 0) {
134 char input = Serial.read();
136 if (input == '?' || input == 'h') {
140 if ( input == 'T' ) {
141 Serial.print("DS18B20 temperature = ");
142 sensors.requestTemperatures();
143 Serial.println( sensors.getTempCByIndex(0) );
146 if ( input == 'B' ) {
147 Serial.readBytesUntil('\n', binary_data, sizeof(binary_data));
148 Serial.print("# send B");
149 Serial.println( binary_data );
151 mySwitch.send( binary_data );
155 if ( input == 'R' ) {
156 Serial.readBytesUntil('\n', binary_data, sizeof(binary_data));
157 Serial.print("# send 315 binary ");
158 Serial.println( binary_data );
159 send_315( binary_data );
162 // light sockets at 315 Mhz
164 send_315("1000100110110000000000010");
167 send_315("1011001001011111000000010");
172 Serial.print("temperature=");
173 Serial.print(temp_avg.getAverage());
174 Serial.print(" humidity=");
175 Serial.print(hum_avg.getAverage());
176 Serial.print(" errors=");
177 Serial.println(dht22_errors);
180 if ( input >= 0x30 && input <= 0x39 && serial_pos < 2 ) {
181 input = input - 0x30; // ASCII to number
182 serial_data[serial_pos++] = input;
184 Serial.print("# ignore: ");
185 Serial.println(input, HEX);
188 if ( serial_pos == 2 ) {
189 Serial.print("switch=");
190 Serial.print(serial_data[0], DEC);
191 Serial.print(" state=");
192 Serial.println(serial_data[1] ? "on" : "off");
194 byte on = serial_data[1];
198 // switches, 433 Mhz set of 3
199 switch ( serial_data[0] ) {
201 on ? mySwitch.send("110101011101010000001100")
202 : mySwitch.send("110101011101010000000011");
205 on ? mySwitch.send("110101010111010000001100")
206 : mySwitch.send("110101010111010000000011");
209 on ? mySwitch.send("110101010101110000001100")
210 : mySwitch.send("110101010101110000000011");
213 on ? mySwitch.send("001111110000000011000000")
214 : mySwitch.send("001111110000000000000000");
218 cca. 320Mhz 4 channel 4.8A 220V relay
220 A 1101001010011010011100010
221 B 1101001010011010011101000
222 C 1101001010011010011100100
223 D 1101001010011010011110000
224 off 1101001010011010011111000
225 on 1101001010011010011100110
228 case '0': send_315( "1101001010011010011111000" );
229 case '1': send_315( "1101001010011010011100110" );
230 case 'A': send_315( "1101001010011010011100010" );
231 case 'B': send_315( "1101001010011010011101000" );
232 case 'C': send_315( "1101001010011010011100100" );
233 case 'D': send_315( "1101001010011010011110000" );
234 default: Serial.println("# ERROR: use 0-off 1-on A B C D");
237 Serial.print("# invalid switch number ");
238 Serial.println(serial_data[0], DEC);