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);
79 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");
84 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
85 mySwitch.enableTransmit(10); // with sender wired in receiving doesn't work, pin #10
96 char serial_data[2]; // socket (0-9), state (0-1)
100 if (mySwitch.available()) {
101 Serial.print(mySwitch.getReceivedBitlength());
102 Serial.print(" bits ");
103 Serial.println(mySwitch.getReceivedValue(), BIN);
104 mySwitch.resetAvailable();
106 if (Serial.available() > 0) {
107 char input = Serial.read();
109 if (input == '?' || input == 'h') {
113 if ( input == 'T' ) {
114 Serial.print("DS18B20 temperature = ");
115 sensors.requestTemperatures();
116 Serial.println( sensors.getTempCByIndex(0) );
119 if ( input == 'B' ) {
120 Serial.readBytesUntil('\n', binary_data, sizeof(binary_data));
121 Serial.print("# send B");
122 Serial.println( binary_data );
123 mySwitch.send( binary_data );
126 // light sockets at 513 Mhz
128 send_513("1000100110110000000000010");
131 send_513("1011001001011111000000010");
136 Serial.print("temperature=");
137 Serial.print(dht.getTemperature());
138 Serial.print(" humidity=");
139 Serial.print(dht.getHumidity());
140 Serial.print(" status=");
141 Serial.println(dht.getStatusString());
144 if ( input >= 0x30 && input <= 0x39 ) {
145 input = input - 0x30; // ASCII to number
146 serial_data[serial_pos++] = input;
148 Serial.print("# ignore: ");
149 Serial.println(input, HEX);
152 if ( serial_pos == 2 ) {
153 Serial.print("socket=");
154 Serial.print(serial_data[0], DEC);
155 Serial.print(" state=");
156 Serial.println(serial_data[1] ? "on" : "off");
158 byte on = serial_data[1];
160 // switches, 433 Mhz set of 3
161 switch ( serial_data[0] ) {
163 on ? mySwitch.send("110101011101010000001100")
164 : mySwitch.send("110101011101010000000011");
167 on ? mySwitch.send("110101010111010000001100")
168 : mySwitch.send("110101010111010000000011");
171 on ? mySwitch.send("110101010101110000001100")
172 : mySwitch.send("110101010101110000000011");
175 on ? mySwitch.send("001111110000000011000000")
176 : mySwitch.send("001111110000000000000000");
179 Serial.print("# invalid switch on number ");
180 Serial.println(serial_data[0], DEC);