Created
March 10, 2023 15:27
-
-
Save djdunc/970790c2a74985e92f7a1b5690568069 to your computer and use it in GitHub Desktop.
TTN Arduino Things Uno (Leonardo) with TMP36 sending to TTN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Circuit: | |
* TMP36 middle pin attached to pin A0, left to VCC, right to GND | |
created Feb 2023 | |
by Duncan Wilson | |
*/ | |
#include <TheThingsNetwork.h> | |
// Set your AppEUI and AppKey | |
const char *appEui = "xxx"; | |
const char *appKey = "xxx"; | |
#define loraSerial Serial1 | |
#define debugSerial Serial | |
// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915 | |
#define freqPlan TTN_FP_EU868 | |
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan); | |
//TMP36 Pin Variables | |
int sensorPin = A0; //the analog pin the TMP36's Vout (sense) | |
void setup() | |
{ | |
loraSerial.begin(57600); | |
debugSerial.begin(9600); | |
// Wait a maximum of 10s for Serial Monitor | |
while (!debugSerial && millis() < 10000) | |
; | |
debugSerial.println("-- STATUS"); | |
ttn.showStatus(); | |
debugSerial.println("-- JOIN"); | |
ttn.join(appEui, appKey); | |
} | |
void loop() | |
{ | |
debugSerial.println("-- LOOP"); | |
// converting that reading to voltage, for 5.0v arduino use 5.0 | |
int reading = analogRead(sensorPin); | |
float voltage = reading * 5.0; | |
voltage /= 1024.0; | |
// now print out the temperature | |
float tempC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset | |
//to degrees ((voltage - 500mV) times 100) | |
// Read sensor values and multiply by 100 to effictively have 2 decimals | |
uint16_t temperature = tempC * 100; | |
// Split both words (16 bits) into 2 bytes of 8 | |
byte payload[2]; | |
payload[0] = highByte(temperature); | |
payload[1] = lowByte(temperature); | |
debugSerial.print("Temperature: "); | |
debugSerial.println(temperature); | |
ttn.sendBytes(payload, sizeof(payload)); | |
delay(60000); // wait a minute | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment