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
82 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");
87 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
88 mySwitch.enableTransmit(10); // with sender wired in receiving doesn't work, pin #10
99 char serial_data[2]; // socket (0-9), state (0-1)
100 char binary_data[24];
103 if (mySwitch.available()) {
104 Serial.print(mySwitch.getReceivedBitlength());
105 Serial.print(" bits ");
106 Serial.println(mySwitch.getReceivedValue(), BIN);
107 mySwitch.resetAvailable();
109 if (Serial.available() > 0) {
110 char input = Serial.read();
112 if (input == '?' || input == 'h') {
116 if ( input == 'T' ) {
117 Serial.print("DS18B20 temperature = ");
118 sensors.requestTemperatures();
119 Serial.println( sensors.getTempCByIndex(0) );
122 if ( input == 'B' ) {
123 Serial.readBytesUntil('\n', binary_data, sizeof(binary_data));
124 Serial.print("# send B");
125 Serial.println( binary_data );
127 mySwitch.send( binary_data );
131 // light sockets at 315 Mhz
133 send_315("1000100110110000000000010");
136 send_315("1011001001011111000000010");
141 Serial.print("temperature=");
142 Serial.print(dht.getTemperature());
143 Serial.print(" humidity=");
144 Serial.print(dht.getHumidity());
145 Serial.print(" status=");
146 Serial.println(dht.getStatusString());
149 if ( input >= 0x30 && input <= 0x39 ) {
150 input = input - 0x30; // ASCII to number
151 serial_data[serial_pos++] = input;
153 Serial.print("# ignore: ");
154 Serial.println(input, HEX);
157 if ( serial_pos == 2 ) {
158 Serial.print("switch=");
159 Serial.print(serial_data[0], DEC);
160 Serial.print(" state=");
161 Serial.println(serial_data[1] ? "on" : "off");
163 byte on = serial_data[1];
167 // switches, 433 Mhz set of 3
168 switch ( serial_data[0] ) {
170 on ? mySwitch.send("110101011101010000001100")
171 : mySwitch.send("110101011101010000000011");
174 on ? mySwitch.send("110101010111010000001100")
175 : mySwitch.send("110101010111010000000011");
178 on ? mySwitch.send("110101010101110000001100")
179 : mySwitch.send("110101010101110000000011");
182 on ? mySwitch.send("001111110000000011000000")
183 : mySwitch.send("001111110000000000000000");
186 Serial.print("# invalid switch number ");
187 Serial.println(serial_data[0], DEC);