Hello,
I am new to Arduino. The first thing I am doing is to monitor temperature using DS18B20 sensor.
I have uploaded the following sketch to the Arduino Uno board:
#include <OneWire.h>
String path = "/api/Temperature/";
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
OneWire ds2(DS18S20_Pin); // on digital pin 2 (IN)
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
float temperature = getTemp();
Serial.print(path + round(temperature));
//writeString(path + round(temperature));
delay(5000); // Envía la temperatura cada 5 segundos
}
/*
void writeString(String stringData) {
for (int i = 0; i < stringData.length(); i++)
{
Serial.write(stringData[i]); // Push each char 1 by 1 on each loop pass
}
}
*/
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds2.search(addr)) {
//no more sensors on chain, reset search
ds2.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds2.reset();
ds2.select(addr);
ds2.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds2.reset();
ds2.select(addr);
ds2.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds2.read();
}
ds2.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
All works perfectly. When I use serial monitor, I can see the data displayed. I see even the TX led in the board flashing.
When I disconnect USB cable from the PC, TX led stops flashing immediately.
On the other hand, I have other device that has a RS232 interface (it is actually a MODEM). I need to send the serial data from the Arduino to that MODEM. I connected both by a USB - RS232 cable.
Since in this case I don’t have USB power, I used an AC/DC adapter whose output is 12 V (I have read that voltage is OK) plugged in the power barrel. When I power the Arduino in this way, the green LED goes on showing that it is powered.
What is going on here? why transmission stops immediately when I disconnect the USB cable from the PC? Because of that, obviously when connecting the cable to the MODEM, it will not work also.
Any help will be appreciated, thanks
Jaime