This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rfbox-multiprobe.ino.old
281 lines (252 loc) · 7.26 KB
/
rfbox-multiprobe.ino.old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
* * Generic Sender code : Send a value (counter) over RF 433.92 mhz
* Fréquence : 433.92 mhz
* Protocole : homepi
* Licence : CC -by -sa
* Auteur : Yves Grange * https://github.com/Yves911/generic_433_sender
* Version : 0.1
* Lase update : 10/10/2014
* rfbox source https://github.com/incmve/generic-rfbox
* Based on: Valentin CARRUESCO aka idleman and Manuel Esteban aka Yaug (http://manuel-esteban.com) work
* used the code from (https://github.com/koffienl/pimatic-probe) to enable/disable modules
*/
// Includes
#include <OneWire.h> // http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip
#include <DallasTemperature.h> // http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_LATEST.zip
#include <dht.h> // http://playground.arduino.cc/Main/DHTLib#.UyMXevldWCQ
// Define vars
#define DHT11_PIN 9
#define senderPin 4 //
const int ledPin = 13; // internal LED PIN
#define ONE_WIRE_BUS 5 // DS18B20 PIN
#define echoPin 11 // Echo Pin
#define trigPin 12 // Trigger Pin
long codeKit = 1000; // Your unique ID for your Arduino node
int Bytes[30];
int BytesData[30];
int maximumRange = 200; // Maximum range sonar
int minimumRange = 0; // Minimum range sonar
long duration, distance; // Duration used to calculate distance
// Config which modules to use
boolean DHT11 = true;
boolean DS18B20 = true;
boolean ultrasonic = false;
// Start includes
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature
dht DHT;
DeviceAddress insideThermometer;
void itob(unsigned long integer, int length)
{
for (int i=0; i<length; i++){
if ((integer / power2(length-1-i))==1){
integer-=power2(length-1-i);
Bytes[i]=1;
}
else Bytes[i]=0;
}
}
void itobCounter(unsigned long integer, int length)
{
for (int i=0; i<length; i++){
if ((integer / power2(length-1-i))==1){
integer-=power2(length-1-i);
BytesData[i]=1;
}
else BytesData[i]=0;
}
}
unsigned long power2(int power){ //gives 2 to the (power)
unsigned long integer=1;
for (int i=0; i<power; i++){
integer*=2;
}
return integer;
}
/**
* Crée notre signal sous forme binaire
**/
void buildSignal()
{
Serial.println(codeKit);
// Converti les codes respectifs pour le signal en binaire
itob(codeKit, 14);
for(int j=0;j < 14; j++){
Serial.print(Bytes[j]);
}
Serial.println();
}
// Convert 0 in 01 and 1 in 10 (Manchester conversion)
void sendPair(bool b) {
if(b)
{
sendBit(true);
sendBit(false);
}
else
{
sendBit(false);
sendBit(true);
}
}
//Envois d'une pulsation (passage de l'etat haut a l'etat bas)
//1 = 310µs haut puis 1340µs bas
//0 = 310µs haut puis 310µs bas
void sendBit(bool b) {
if (b) {
digitalWrite(senderPin, HIGH);
delayMicroseconds(650); //506 orinally, but tweaked.
digitalWrite(senderPin, LOW);
delayMicroseconds(2024); //1225 orinally, but tweaked.
}
else {
digitalWrite(senderPin, HIGH);
delayMicroseconds(650); //506 orinally, but tweaked.
digitalWrite(senderPin, LOW);
delayMicroseconds(4301); //305 orinally, but tweaked.
}
}
/**
* Transmit data
* @param boolean positive : if the value you send is a positive or negative one
* @param long Counter : the value you want to send
**/
void transmit(boolean positive, unsigned long Counter, int BytesType[], int repeats)
{
int ii;
for(ii=0; ii<repeats;ii++)
{
int i;
itobCounter(Counter, 30);
// Send the unique ID of your Arduino node
for(i=0; i<14;i++)
{
sendPair(Bytes[i]);
}
// Send protocol type
for(int j = 0; j<4; j++)
{
sendPair(BytesType[j]);
}
// Send the flag to mark the value as positive or negative
sendPair(positive);
// Send value (ie your counter)
for(int j = 0; j<30; j++)
{
sendPair(BytesData[j]);
}
// Send the flag "End of the transmission"
digitalWrite(senderPin, HIGH);
delayMicroseconds(650);
digitalWrite(senderPin, LOW);
delayMicroseconds(8602);
}
}
void setup()
{
pinMode(senderPin, OUTPUT);
pinMode(ledPin, OUTPUT);
buildSignal();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
if (DS18B20) {
//start up temp sensor
sensors.begin();
sensors.getAddress(insideThermometer, 0);
int reso = sensors.getResolution(insideThermometer);
Serial.println("Sensor resolution");
Serial.println(reso);
if (reso != 12) {
Serial.print("Resolution of DS18B20 is not 12 but ");
Serial.println("Sensor resolution");
Serial.println(reso);
Serial.println(" changing to 12\n");
sensors.setResolution(insideThermometer, 12);
Serial.print("Done\n");
}
}
}
void loop()
{
if (DS18B20) {
Serial.println("Begin ds18b20");
// Read DS18B20 and transmit value as sensor 1
float temperature;
sensors.requestTemperatures(); // Get the temperature
temperature = sensors.getTempCByIndex(0); // Get temperature in Celcius
int CounterValue;
int BytesType[] = {0,0,0,1}; // type = 1
if (temperature >= 0.0) {
CounterValue = temperature * 10;
Serial.println("Positive temp");
Serial.println(CounterValue);
transmit(true, CounterValue, BytesType, 6);
}
if (temperature < 0.0) {
CounterValue = temperature * -10;
Serial.println("Negative temp");
Serial.println("-");
Serial.println(CounterValue);
transmit(false, CounterValue, BytesType, 6);
}
Blink(ledPin,1);
delay(10000); // wait for 10 seconds to go to next sensor
}
if (DHT11) {
Serial.println("Begin DHT11");
// Read DHT11 and transmit value as sensor 2
int chk = DHT.read11(DHT11_PIN);
Serial.println(chk);
switch (chk)
{
case DHTLIB_OK:
float humfloat = DHT.humidity;
int CounterValue = humfloat * 10;
int BytesType[] = {0,0,1,0}; // type = 2
transmit(true, CounterValue, BytesType, 6);
Blink(ledPin,2);
Serial.println(CounterValue);
delay(10000); // wait for 10 seconds to go to next sensor
break;
}
}
if (ultrasonic) {
// Read Sonar and transmit value as sensor 3
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the pace of sound. http://www.instructables.com/id/Using-a-SR04/
distance = duration/58.2;
if (distance >= maximumRange || distance <= minimumRange){
/* Send a negative number to computer and Turn LED ON
to indicate "out of range" */
Serial.println("Out of range");
}
else {
/* Send the distance to the computer using Serial protocol, and
turn LED OFF to indicate successful reading. */
int BytesType[] = {0,0,1,1}; //transmit value as sensor 3
transmit(true, distance, BytesType, 6);
Serial.println(distance);
Blink(ledPin,3);
}
}
Serial.println("End of Loop");
delay(1800000); // wait for 30 minutes to restart loop, be aware if to short RF pollution will occur.
}
void Blink(int led, int times)
{
for (int i=0; i< times; i++)
{
digitalWrite(ledPin,HIGH);
delay (250);
digitalWrite(ledPin,LOW);
delay (250);
}
}