/
Long_Range_Wireless_1_Channel_Counter_Arduino.ino
69 lines (64 loc) · 1.83 KB
/
Long_Range_Wireless_1_Channel_Counter_Arduino.ino
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
///this code is written and tested for ncd.io IoT Long Range Wireless One Channel Counter Transmitter with arduino due
///sensor data structure can be found here https://ncd.io/long-range-iot-wireless-one-channel-counter-with-reset-product-manual/
/// sensor can be found here https://store.ncd.io/product/iot-long-range-wireless-one-channel-counter-transmitter/
uint8_t data[29];
int k = 10;
int i;
void setup()
{
Serial1.begin(9600);
Serial.begin(9600);
Serial.println("ncd.io IoT Arduino Wireless One Channel Counter Transmitter");
}
void loop()
{
if (Serial1.available())
{
data[0] = Serial1.read();
delay(k);
if(data[0]==0x7E)
{
while (!Serial1.available());
for ( i = 1; i< 29; i++)
{
data[i] = Serial1.read();
delay(1);
}
if(data[15]==0x7F) /////// to check if the recive data is correct
{
if(data[22]==0x23) //////// make sure the sensor type is correct
{
long int count_1 = ((data[24]<<24) + (data[25]<<16) + (data[26]<<8) + (data[27])) ;
float battery = ((data[18] * 256) + data[19]);
float voltage = 0.00322 * battery;
Serial.print("Sensor Number ");
Serial.println(data[16]);
Serial.print("Sensor Type ");
Serial.println(data[22]);
Serial.print("Firmware Version ");
Serial.println(data[17]);
Serial.print("Number of counts on Channel One :");
Serial.print(count_1);
Serial.print("ADC value:");
Serial.println(battery);
Serial.print("Battery Voltage:");
Serial.print(voltage);
Serial.println("\n");
if (voltage < 1)
{
Serial.println("Time to Replace The Battery");
}
}
}
else
{
for ( i = 0; i< 29; i++)
{
Serial.print(data[i]);
Serial.print(" , ");
delay(1);
}
}
}
}
}