code don't work on my d18b20 temperature sensor - arduino

The simple code for arduino is down the page and everything works (it shows me temperature as it is), but in this example I include ethernet and begin internet and it doesn't show me temperature anymore....in serial monitor it just shows me temperature -127.00, so it mean it doesn't work. I am very new at programming, so I am sorta noob and maybe it's some banal question and answer, but I don't get it, why I cant start ethernet in setup function. I only need that for my other project which will include mqtt, so I will need ethernet. Please help and thanks for answers.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Ethernet.h>
// Data wire is plugged into pin 12 on the Arduino
#define ONE_WIRE_BUS 12
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 80);
void setup(void)
{
Serial.begin(9600); //Begin serial communication
Ethernet.begin(mac, ip);
Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
sensors.begin();
}
void loop(void)
{
// Send the command to get temperatures
sensors.requestTemperatures();
Serial.print("Temperature is: ");
Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Update value every 1 sec.
delay(1000);
}

Related

ESP32: dsb1820 temperature sensor giving constant negative 127 reading

I am trying to get a temperature reading using a single dsb1820 temperature sensor attached to an esp32 micro controller. The sensor is attached to GPIO-4 of the esp32. I intend to send the temperature reading to a cloud.
The problem i am facing is that the temperature reading always gives the value -127.
I read somewhere online that when the dsb1820 returns -127 it means that the sensor is not connected.
Am I using the wrong pin to connect the sensor?
#include "OneWire.h"
#include "DallasTemperature.h"
#include <WiFi.h>
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASSWORD"
OneWire oneWire(4);
DallasTemperature tempSensor(&oneWire);
void setup(void)
{
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
tempSensor.begin();
}
void loop(void)
{
tempSensor.requestTemperaturesByIndex(0);
Serial.print("Temperature: ");
Serial.print(tempSensor.getTempCByIndex(0));
Serial.println(" C");
delay(2000);
}
Check your cables and:
const int oneWireBus = 32; // on pin 32 /GPIO7/D0 on pcb (a 4.7K resistor is necessary)
OneWire oneWire(oneWireBus);
and it should be the middle pin of the sensor (see my graphic)
EDIT
The DevKit has no pin 4 either you use GPIO4 (4 on the pcb) which is in Arduino 24 BUT
The following strapping pins: 0, 2, 4, 5 (HIGH during boot), 12 (LOW
during boot) and 15 (HIGH during boot) are used to put the ESP32 into
bootloader or flashing mode. Don't connect peripherals to those pins!
If you do, you may have trouble trying to upload code, flash or reset
the board.
Connect to 32 (GPIO7 or D0 on the pcb) as this is safe for testing
If you have that wrong or no/wrong resistor it will give you -127 (or you killed the sensor/it was DOA).

Transmitting data between arduino's using hm-10 BLE

I am working on a project whereby I have an arduino recording the humidity and temperature levels of a room (using a DHT11 sensor), and a second arduino that recieve this data via bluetooth.
I am using the hm-10 BLE modules.
So far the data-collector can transmit data over BLE, and the reciever can recieve BLE data from my phone, but I can't figure out how to pair the two modules so that the receiver can receive data from the data-collector.
All of the solutions I have found online involve using the AT instruction set, whereas I am using the SoftwareSerial.h library.
The code for my data gatherer is as follows:
//Include the DHT (humidity and temperature sensor) library, and the serial library
#include <dht.h>
#include <SoftwareSerial.h>
//Define the constants for the input (DHT11) and output pins
#define RXpin 7
#define TXpin 8
#define DHT11_PIN 9
//Initialise a Serial channel as softSerial
SoftwareSerial softSerial(RXpin, TXpin);
//Initialise DHT object
dht DHT;
//Set initial measurement to be temperature (not humidity)
bool humidity = false;
void setup() {
//Start the serial function
Serial.begin(9600);
//Start the softSerial channel
softSerial.begin(9600);
}//void setup()
void loop() {
//Reset the reading variable
float(reading);
//Take in the values recorded by the DHT11
int chk = DHT.read11(DHT11_PIN);
//Store the necessary measurement in the reading variable
if (!humidity) {
reading = DHT.temperature;
} else {
reading = DHT.humidity;
}
//Output the reading on the softSerial channel
softSerial.print(reading);
//The DHT11 can only take one measurement per second, so waiting two seconds ensures there will be no null readings
delay(2000);
//Swap current measurement
humidity = !humidity;
}//void loop()
Any ideas on how I can connect it with another hm10 module so they can exchange information without having to re-write everything to the AT instruction set would be greatly appreciated.
You need to learn AT commands to configure the HM-10 in master or slave mode, all these can still be done using the SoftSerial library, get the HM-10 datasheet for AT commands and check these site for help.
http://www.instructables.com/id/How-to-Use-Bluetooth-40-HM10/
https://www.hackster.io/achindra/bluetooth-le-using-cc-41a-hm-10-clone-d8708e
See sample code below:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(4, 5);
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
BTSerial.write("AT+DEFAULT\r\n");
BTSerial.write("AT+RESET\r\n");
BTSerial.write("AT+NAME=Controller\r\n");
BTSerial.write("AT+ROLE1\r\n");
BTSerial.write("AT+TYPE1"); //Simple pairing
}
void loop()
{
if (BTSerial.available())
Serial.write(BTSerial.read());
if (Serial.available())
BTSerial.write(Serial.read());
}

RFID does not respond after Ethernet.begin(mac, ip) initialization

Good day, I have this problem with my simple project. I have a database with all RFID number of employee. What I want to do is to use an rfID to check if it is registered in the database. If it is, it would return a value of 1 else would be a value of 0.
I tried with arduino HanRun Ethernet shield. I was able to get a response from the php web server to the serial monitor. Tried the seeedrfid it successfully get the rfcard number. However, when i tried to combine the two, it would hang on Ethernet.begin(mac, ip) initialization. My code is below.
#include <Ethernet.h>
#include <SoftwareSerial.h>
#include <SeeedRFID.h>
#define RFID_RX_PIN 10
#define RFID_TX_PIN 11
SeeedRFID RFID(RFID_RX_PIN, RFID_TX_PIN);
char state = '0';
char c;
byte mac[] = {0x60, 0xF8, 0x1D, 0xBA, 0x1D, 0x52};
IPAddress ip(192, 168, 20, 228);
EthernetClient client;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Serial set up");
Ethernet.begin(mac, ip);
Serial.print("My IP Address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
long rfID;
// put your main code here, to run repeatedly:
if (RFID.isAvailable()) {
rfID = RFID.cardNumber();
Serial.println(rfID);
}
}
Serial.println(rfID) is not executed unless I remove the Ethernet.begin(mac, ip). Can anybody point me to the right direction?
Thank you everyone for helping out. My supervisor who gave me the shield just remembered that there might be a pin changes(or anything you call it). That I might need to try other pin in order for the rf reader and ethernet shield to work together. now its working fine..

Unable to communicate: Arduino with Bluetooth HC-06

I wrote a program that can capture moisture through a DHT11 sensor connected to an Arduino Uno. The captured value will be sent to an Android application using a Bluetooth HC-06 module. Everything works fine except that the latter (HC-06) does not send the captured moisture.
Can someone help me and thank you
The code is as follows:
#include <SoftwareSerial.h>
/* to communicate with the Bluetooth module's TXD pin */
#define BT_SERIAL_TX 10
/* to communicate with the Bluetooth module's RXD pin */
#define BT_SERIAL_RX 11
/* Initialise the software serial port */
SoftwareSerial BluetoothSerial(BT_SERIAL_RX, BT_SERIAL_TX);
// DHT-11 Configuration
#include <DHT.h> // lightweight DHT sensor library
#define DHTTYPE DHT11 // DHT 11
#define TEMPTYPE 0 // Use 0 for Celsius, 1 for Fahrenheit
#define DHTPIN 2
DHT dht(DHTPIN, DHTTYPE); // Define Temp Sensor
void setup() {
BluetoothSerial.begin(115200); // Initialise BlueTooth
Serial.begin(9600);
//delay(1000);
dht.begin(); // Initialize DHT Teperature Sensor
BluetoothSerial.print("Starting ...");
}
void loop() {
// Take readings
float h = dht.readHumidity(); // Read humidity
BluetoothSerial.println(h);
delay(500);
}

Arduino Ethernet Shield 2 not working

I am currently trying to get the Ethernet Shield working on my Mega. I was trying to run the Webserver example but the program seems to stuck at one point, so I tried to start from scratch.
This is my test code:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0F, 0xF6, 0x3D
};
byte subnet[] = { 255,0,0,0 };
byte gateway[] = { 2,0,0,1 };
IPAddress ip(2, 0, 0, 1);
EthernetServer server(80);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway, subnet);
Serial.println("Ethernet started");
server.begin();
Serial.println("Server started");
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Loop");
}
The output I get from the serial console is:
Etrted
Ethernet started
So I think the program gets stuck inside the EthernetServer::begin() function.
I am aware that there are earlier versions of ethernet shields which are not compatible to the mega, but the vendor of my shield says it is.
Also I don't understand, why it outputs the first line.
Thanks for your hints!
Arduino.cc and Arduino.org are not the same... Arduino.org, who is selling the ethernet shield 2, has their own IDE with the correct library! You can download it at http://www.arduino.org/downloads and the source can be found at https://github.com/arduino-org/Arduino/tree/1.7.4/libraries
Try this code form (http://www.arduino.cc/en/Tutorial/DhcpAddressPrinter):
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop() {
}
And post what the serial monitor output is.
Try this:
NB. You can reuse your code written for Arduino Ethernet Shield, simply replacing
#include <Ethernet.h> --> #include <Ethernet2.h>
#include <EthernetUdp.h> --> #include <EthernetUdp2.h>
See this: http://labs.arduino.org/Arduino+Ethernet+Shield+2

Resources