(solved ) Issues getting temperature values over with Arduino and TMP36, also setting up USB connection

Hi all, basically i want the display temperature in degrees using my Arduino UNO and TMP36 sensor. i started this coding lark 2 days ago and have an ok understanding of coding what i need to do and it works fine in IDE.

Just using IDE i get the temperature and its correct when looking at serial monitor. The question is how do i get the correct values on my phone? Have no idea where to add the code to the one i have set up turning a relay on and off.

I found a relevant topic on it but he never got the right values.

Can any one help?

Here is the code that successfully turns the relay on and off, as i understand ive done nothing to this but to remap the sensor i have no idea, tried for about 2 hours but no luck!

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "5d97d0c0c3d348xxxxxxxxxxxxxxx";



void setup()
{
  SwSerial.begin(9600);
  Blynk.begin(auth);
  // Default baud rate is 9600. You could specify it like this:
  //Blynk.begin(auth, 57600);
}

void loop()

{
  Blynk.run();

}

Have a look at this project by another blynker, it might help you out.

http://community.blynk.cc/t/arduino-nano-usb-dht22-simple-temperature-humidity-watching/

Helped abit but if im not using a DHT22 what can i replace those elements with? I just have a TMP36 connected to A0…

You say you already have the temperature value writing to the serial monitor in your Ide correctly? So you should be able to use the same value that you are doing a Serial.write with, but now do a Blynk.virtualWrite command instead. Then set up a display widget on your dashboard with the virtual pin you are writing to.

Be careful not to cause a ‘flood’ by writing to the Blynk server too often. Set up a timer to do it once per second or something like that. Otherwise you will be disconnected.

#include <SimpleTimer.h>

// Do timer stuff in void doDHT every one second
byte timerDHT           = timer.setInterval(1000L,   doDHT);

void doDHT()
{
  temp = analogRead(A0);
  Blynk.virtualWrite(V0, temp);
}

That should be it. Put a Value display on your Dashboard attached to Pin 1 and have it set to update every second.

1 Like

Thanks for the response. I get a few errors with this… Apologise with weird code display, how do you get it cleaner like you’ve posted?

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>
#define DHTPIN   A0
const int sensorPin = A0;
#include <SimpleTimer.h>

// Do timer stuff in void doDHT every one second
byte timerDHT= timer.setInterval(1000L, doDHT);

void doDHT()
{
  temp = analogRead(A0);
  Blynk.virtualWrite(V0, temp);
}

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "5d97d0c0c3d34860a3715fa4968f8bfb";



void setup()
{
  SwSerial.begin(9600);
  Blynk.begin(auth);
  // Default baud rate is 9600. You could specify it like this:
  //Blynk.begin(auth, 57600);
}



void loop()

{
  Blynk.run();

}

The errors i get are

Arduino_Serial_USB_test_1.ino:67:16: error: ‘timer’ was not declared in this scope
Arduino_Serial_USB_test_1.ino: In function ‘void doDHT()’:
Arduino_Serial_USB_test_1.ino:71:3: error: ‘temp’ was not declared in this scope
Error compiling

You can clean up your code by beginning it with three backticks “`” and ending it the same way. It’ll make it up pretty nice :slight_smile:

I think the void doDHT should be after the loop(). I always do it that way. And you probably need to include/install the SimpleTimer library. And temp indeed should be

int temp = analogRead(A0);

Which should be substituted of course for the code you use to read your analog temperature sensor.

Right after around 4 hours of pulling out hair ive done it so thought id share the end result, could probably be cleaned up but im a complete novice. The set up is an Arduino UNO, TMP36 and running over USB.

A few things being a beginner this was a tad tricky so will share too, changing the COMport and running over USB. Will do a youtube vid when i get time.
-Locate blynk-ser.bat file, mine is located, C:\Program Files\Arduino\libraries\Blynk\scripts. Make sure you have full admin rights, open and change line 6 to your COMport, if unsure open Aruduino IDE, hook up your board and click “tools” then hoover over “port” and replace line 6 value with yours, in my case COM3 instead of the default COM1, pay attention to capitals, click save (may have issues if not acting as admin).
-to run on USB you need to upload the code, then hold in reset, open the blynk-ser.bat file (same as above) in my case located, C:\Program Files\Arduino\libraries\Blynk\scripts, make a short cut… and release the reset button. Note to upload a new code you need to close blynk-ser.bat, upload then do the reset set again…

In the below code add your Auth code that you get from the app, the only thing you need to change. Note the middle leg of TMP36 is hooked up to A0 on the UNO.

This is running Celsius but for Fahrenheit remove the last line and add, temp = temp * 0.48828125;

 #include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>
#include <SimpleTimer.h>
    
    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
    char auth[] = "5d97d0c0c3d34860a3715fa4968f8bfb"; // add your auth code from the app
    
    float temp;
    int tempPin = 1; //analog pin 1
    
    SimpleTimer timer;
    
    void setup()
    {
      Serial.begin(9600); // See the connection status in Serial Monitor
      Blynk.begin(auth);
    
      // Setup a function to be called every second
      timer.setInterval(1000L, sendUptime);
    }
    
    // that you define how often to send data to Blynk App.
    void sendUptime()
    {
     // shows the value temp on virtual pin 10
      Blynk.virtualWrite(10, temp); 
    }
    
    void loop()
    {
      Blynk.run(); // Initiates Blynk
      timer.run(); // Initiates SimpleTimer
      
       temp = analogRead(tempPin);
      temp = ((temp * 0.48828125)-32)/1.8;
     
      
    }

Thanks all for the help especilly Lichtsignaal and catoplepa to whom i used the code in this thread

1 Like

It may be even easier to get a DHT11 or DHT22 digital temp/humidity sensor :wink:

But on the other hand, you do need a library for that, so that will take up some resources.

Well, without your code to look at, it’s practically impossible for us to tell you anything about what goes right and wrong.