# Arduino code to send voltage, current and power to the things network with uplink

**URL:** <https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130>\
**Category:** End Devices (Nodes)\
**Created:** [August 10, 2020, 10:47am UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130 "2020-08-10T10:47:33Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [August 11, 2020, 6:57pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/23 "2020-08-11T18:57:58Z")

</div>

Please please please can you confirm:

> [@descartes](#):
>
> Are you seeing the `EV_TXCOMPLETE (includes waiting for RX windows)` message

as at this stage, we don’t even know if the device is actually transmitting.

And then please please please confirm that you are seeing the transmitted data in the web console - as that will confirm that all the transmission settings are correct.

---

<div class="post-metadata">

**Author:** ![cherechi](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cherechi/32/26988_2.png) [@cherechi](https://www.thethingsnetwork.org/forum/u/cherechi)\
**Post date:** [August 11, 2020, 6:59pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/24 "2020-08-11T18:59:52Z")

</div>

I am seeing my transmitted data both on the serial monitor and on the web interface,  
when i send downlink i also see it scheduled. but it will not get to the node… ![serial monitor](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/6/f/6fc3db3de73924763bd6cd7d2a59968228993b07.png)

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [August 11, 2020, 7:34pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/25 "2020-08-11T19:34:44Z")

</div>

> [@cherechi](#):
>
> on the web interface

Only in the gateway’s Traffic page, or also in the application/device’s **Data** page? Only when you see it in the Data page in TTN Console, you know for sure that the device’s configuration matches the secrets that TTN knows, and that TTN has accepted the value of your uplink counter. (The latter check may be disabled, [for testing](https://www.thethingsnetwork.org/forum/t/abp-node-stopped-working-fixed-by-creating-new-abp-why/3200/7).)

> [@cherechi](#):
>
> when i send downlink i also see it scheduled

Here, it’s the other way around: are you only seeing it in the application/device’s Data page, or also in the gateway’s **Traffic** page? (Or even in the gateway’s log files?) Screenshots will help confirm all this.

Aside:

> [@cherechi](#):
>
> I want to also turn on 2 LEDS on the nodes.

Beware that, after testing, you’re only allowed to do this [at most 10 times per 24 hours](https://www.thethingsnetwork.org/forum/t/limitations-data-rate-packet-size-30-seconds-uplink-and-10-messages-downlink-per-day-fair-access-policy-guidelines/1300).

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [August 12, 2020, 9:43am UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/26 "2020-08-12T09:43:59Z")

</div>

Morning @cherechi, I think we are really close to solving this.

As Arjan said, just for peace of mind because the downlink will never work if the credentials aren’t correct, can you confirm that you are seeing the uplink on the Device’s Data tab - note, this only shows real time, so you won’t see anything until there is an uplink whilst the page is open.

I use almost exactly the same code base for Arduino 328P + RFM95 setups so I am quite familiar with the issues - it took me a while to get things going but once I did, it works nicely. Whilst you check the console, I’ll get one out so I can dip in to the code myself.

---

<div class="post-metadata">

**Author:** ![cherechi](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cherechi/32/26988_2.png) [@cherechi](https://www.thethingsnetwork.org/forum/u/cherechi)\
**Post date:** [August 12, 2020, 11:23am UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/27 "2020-08-12T11:23:12Z")

</div>

Thanks alot for your concern, I do get the uplinks on the data tab, also i do see the downlinks on the gateway log as shown in the image below as it is sent at 869.525MHz but it never arrives at the node to turn on the LED. But this morning, I tried sending a downlink, my node recieved it and the LED was turned on. now i cannot turn it off anymore as the dowlink will not get to the node again ![DOWNLINK](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/c/3/c3d693fc59cf3a4d91933cb0faf4cb3b3fceb994.png) ![serial monitor](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/1/f/1f904d8debd6e55c679eebc8f5c490515e275599.png)

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [August 12, 2020, 12:00pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/28 "2020-08-12T12:00:36Z")

</div>

Woo hoo!

So we know it can work, we just need to make it work more reliably, so I’d look at Arjan’s comment about the timing tuning:

> [@Arduino code to send voltage, current and power to the things network with uplink](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/22):
>
> Assuming TTN Console (or some gateway log) showed that a downlink should have been transmitted, you need to figure out why your device is not receiving it. You can start by adding the following to the setup, for example after the line for LMIC\_setDrTxpow: // Make LMIC start its RX windows a bit earlier, and listen longer, to // compensate for an inaccurate clock. // // Beware that a specific value may work for a slow data rate, but not // for faster ones, and remember that RX1 may use differen…

But also, as I should have mentioned sooner, you should limit downlinks as they render the gateway totally deaf whilst transmitting. So what is the LED for? Can it operate locally?

---

<div class="post-metadata">

**Author:** ![cherechi](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cherechi/32/26988_2.png) [@cherechi](https://www.thethingsnetwork.org/forum/u/cherechi)\
**Post date:** [August 12, 2020, 12:05pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/29 "2020-08-12T12:05:20Z")

</div>

let me ask this question, If I have a server such as chirpstack installed locally on my gateway with the need to transmit to the things network, will i be able to send more frequent downlinks. this downlink is supposed to be sent for control purposes. such as alarm or control a servo…

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [August 12, 2020, 12:35pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/30 "2020-08-12T12:35:19Z")

</div>

If you have your own network & application server then you will only be limited by your local laws / regulations for transmissions as you won’t be using TTN.

However if you have your own server, then you won’t be on TTN so you will need to have a reliable server & internet connection.

---

<div class="post-metadata">

**Author:** ![cherechi](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cherechi/32/26988_2.png) [@cherechi](https://www.thethingsnetwork.org/forum/u/cherechi)\
**Post date:** [August 12, 2020, 12:41pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/31 "2020-08-12T12:41:14Z")

</div>

Thank you so much for this reply, you have been very helpful. so back to the LED. since i can only send 10 downlinks in 24 hours, i just want to confirm that my downlink can turn on and off the LEDS. this will not be up to 10 dowlinks.

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [August 12, 2020, 12:46pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/32 "2020-08-12T12:46:18Z")

</div>

Not sure I fully understand your meaning.

TTN fair use policy is for 10 downlinks per 24 hour period per device.

What you send and what it does is entirely up to you - LEDs, pump, MP3 player, siren and so much more.

But you should consider the consequences that the device happens not to transmit & therefore receive on the schedule you expect or does, but doesn’t get the downlink. So nuclear reactors etc aren’t a good idea.

---

<div class="post-metadata">

**Author:** ![bubba198](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/bubba198/32/45323_2.png) [@bubba198](https://www.thethingsnetwork.org/forum/u/bubba198)\
**Post date:** [December 29, 2020, 3:17am UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/33 "2020-12-29T03:17:33Z")

</div>

@cherechi I find this discussion very helpful, one point of interest - AnalogRead by default returns a float and in your example you’re using uint32\_t as the return value from AnalogRead - that’s 4 bytes for float compared to 2 for uint32\_t

Isn’t there an issue of accuracy meaning being cable to capture the entire range of the ADC?

Also if I may share - I have found that doing the match is much easier with a decoder function rather than do it at firmware level. TTN has awesome decoder capability. My example below does the same thing on a 3.3v board:

```
function Decoder(bytes, port) { 
var decoded = {};

bytes[2];
decoded.battery_voltage = 
((bytes[0]*256+bytes[1])*2)*0.0032258064516129;

  return decoded; 
}
```

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [December 29, 2020, 3:55pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130/34 "2020-12-29T15:55:38Z")

</div>

> [@bubba198](#):
>
> AnalogRead by default returns a float

Perhaps not:

> **[analogRead() - Arduino Reference](https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

[Previous page](https://www.thethingsnetwork.org/forum/t/arduino-code-to-send-voltage-current-and-power-to-the-things-network-with-uplink/39130.md?page=1)
