ESP32: dsb1820 temperature sensor giving constant negative 127 reading - arduino

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).

Related

How does my ESP8266/NodeMCU communicate with my GSM Module SIM800L?

so I want to connect my SIM800L GSM Module to my NodeMCU. I bought a LM2596 DC-DC voltage regulator to convert the output voltage to ~4V for the SIM800L. Input voltage for the regulator is 9V/1A.
Everything is connected: RX from GSM to D5 (GPIO14), TX to D6 (GPIO12) and RST to D7 (GPIO13). The GPIOs are deliberately chosen, since I've read online, that the RX/TX Pins on the NodeMCU are used internally. I tried matching RX/TX pins before, but it's the same result (that's why I am certain, it has to be my code that is defect). A SIM card is also inserted in the GSM Module (with PIN).
I'm coding on the Arduino IDE and I'm using the GSMSim and SoftwareSerial libraries for connecting to the GSM Module. I've tried the example sketches from the GSMSim to communicate to the GSM Module, but I'm not getting any answer on my serial monitor.
I also tried manually sending commands to the GSM Module.
#include <GSMSim.h>
#include <SoftwareSerial.h>
// You can use any Serial interface. I recommended HardwareSerial. Please use the library with highiest baudrate.
// In examples, i used HardwareSerial. You can change it anymore.
#define RX 14
#define TX 12
#define RESET 13
SoftwareSerial serial(RX, TX);
GSMSim gsmModule(serial, RESET);
void setup() {
serial.begin(115200); // If you dont change module baudrate, it comes with auto baudrate.
while(!serial) ;
Serial.begin(115200); // Serial for debug...
while(!Serial) ;
Serial.println("");
Serial.println("serial begin");
// Init module...
gsmModule.init(); // use for reseting module. Use it if you dont have any valid reason.
delay(100);
gsmModule.sendATCommand("AT+GMR");
if(serial.available()) Serial.println(serial.readString());
Serial.println("Sent AT");
}
OUTPUT:
serial.begin
Sent AT
Another example with the modified GSMSim_HTTP sketch:
#include <GSMSim.h>
#include <SoftwareSerial.h>
// You can use any Serial interface. I recommended HardwareSerial. Please use the library with highiest baudrate.
// In examples, i used HardwareSerial. You can change it anymore.
#define RX 14
#define TX 12
#define RESET 13
SoftwareSerial serial(RX, TX);
GSMSim http(serial, RESET);
static volatile int num = 0;
void setup() {
serial.begin(115200); // If you dont change module baudrate, it comes with auto baudrate.
while(!serial) {
; // wait for module for connect.
}
Serial.begin(115200); // Serial for debug...
// Init module...
http.init(); // use for init module. Use it if you dont have any valid reason.
Serial.print("Set Phone Function... ");
Serial.println(http.setPhoneFunc(1));
//delay(1000);
Serial.print("is Module Registered to Network?... ");
Serial.println(http.isRegistered());
//delay(1000);
Serial.print("Signal Quality... ");
Serial.println(http.signalQuality());
//delay(1000);
Serial.print("Operator Name... ");
Serial.println(http.operatorNameFromSim());
//delay(1000);
//Serial.print("GPRS Init... ");
//Serial.println(http.gprsInit("internet")); // Its optional. You can set apn, user and password with this method. Default APN: "internet" Default USER: "" Default PWD: ""
//delay(1000);
Serial.print("Connect GPRS... ");
Serial.println(http.connect());
//delay(1000);
Serial.print("Get IP Address... ");
Serial.println(http.getIP());
delay(1000);
Serial.print("Get... ");
Serial.println(http.get("sera.erdemarslan.com/test.php"));
delay(1000);
Serial.print("Get with SSL and read returned data... ");
Serial.println(http.getWithSSL("erdemarslan.com/test.php", true));
delay(1000);
Serial.print("Post... ");
Serial.println(http.post("sera.erdemarslan.com/test.php", "name=Erdem&surname=Arslan", "application/x-www-form-urlencoded"));
delay(1000);
Serial.print("Post with SSL and read returned data... ");
Serial.println(http.post("erdemarslan.com/test.php", "name=Erdem&surname=Arslan", "application/x-www-form-urlencoded", true));
delay(1000);
Serial.print("Close GPRS... ");
Serial.println(http.closeConn());
//delay(1000);
// For other methods please look at readme.txt file.
}
void loop() {
// Use your Serial interface...
if(serial.available()) {
String buffer = "";
buffer = Serial1.readString();
num = num + 1;
Serial.print(num);
Serial.print(". ");
Serial.println(buffer);
}
// put your main code here, to run repeatedly:
}
OUTPUT:
serial.begin
Set Phone Function... 0
is Module Registered to Network?... 0
Signal Quality... 99
Operator Name... NOT CONNECTED
Connect GPRS... 0
Get IP Address...
Get module date time... ERROR:NOT_GET_DATETIME
Set timezone and time server... 0
Sync date time from server... AT_COMMAND_ERROR
Get module date time after sycn... ERROR:NOT_GET_DATETIME
Close GPRS... 0
I hope it's something obvious, since I am not familiar with AT commands at all.
Thanks!

Arduino Mega and RS485 Modbus Sensor

I'm trying to connect a soil sensor using RS485 communication to arduino mega and I can't get it to work. I'm using the SparkFun RS485 breakout: https://www.sparkfun.com/products/10124
I've connected TX to pin 18, RS to pin 19 and RTS to pin 8.
I've tried to adapt the code from here: https://www.youtube.com/watch?v=tBw15SfmuwI using the sensor's manufacturers default setting:
Modbus address fixed to 0
The communication configuration is 9600,N,8,1(9600bps, no check bit, 8 data bits,
1 stop bit)
Communication protocol is Modbus-RTU
While the addresses I need to read are 0x0000-0x0002.
However, I get random characters as output when I open the serial monitor "?", any idea why? I'd appreciate any help reading the sensor's output.
This is the code I've used:
#include <ModbusMaster.h>
#define MAX485_DE 8
#define MAX485_RE_NEG 8
ModbusMaster node;
void preTransmission () {
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission () {
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup() {
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial.begin(9600);
node.begin(0,Serial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop() {
uint8_t resultMain;
resultMain = node.readInputRegisters(0x0000, 3);
if (resultMain == node.ku8MBSuccess) {
Serial.println("-------");
Serial.print("Temp: ");
Serial.println(node.getResponseBuffer(0x00) /100);
Serial.print("VWC: ");
Serial.println(node.getResponseBuffer(0x01) /100);
Serial.print("EC: ");
Serial.println(node.getResponseBuffer(0x02) /100);
}
}
The arduino mega has 3 serial ports:
Serial
Serial1
Serial2
You could think of it as Serial as Serial0 (the zero is never written). This port is hardwired to the USB port on the arduino mega.
Your RS485 breakout board is connected to Serial1. You may notice the screenprinting on the mega next to pins 18 and 19 says TX1 and RX1.
So when you initialize your node at this line:
node.begin(0,Serial);
you should pass it Serial1 instead of Serial
eg
node.begin(0,Serial1);

How can I activate a 24V electric lock with Arduino?

Good! I have a circuit in which I connect an Arduino to an NFC Shield and it is to a protoboard. My goal is to activate an electric lock that works with 10-24V AC and DC, for this I have placed a transistor 2N2222 and a resistance of 330 Ohms. The problem that I have esque when I connect the plate protoboard to the lock, the LED is turned on, but the lock is immovable.
This is the scheme on which I have based myself to assemble everything.
And this is the image of how I have it armed:
And finally I have the code that I am using:
#include <PN532.h>
#include <SPI.h>
/*Chip select pin can be connected to D10 or D9 which is hareware optional*/
/*if you the version of NFC Shield from SeeedStudio is v2.0.*/
#define PN532_CS 10
PN532 nfc(PN532_CS);
#define NFC_DEMO_DEBUG 1
const int control = 7 ;
const int speed = 200;
void setup(void) {
pinMode(control, OUTPUT) ;}
void loop(void) {
digitalWrite(control, HIGH);
delay(2000);
digitalWrite(control, LOW);
delay(1000);
}
it doesn't happends because your supply in +5v (from USB) and can not change state of +24v equipment.
you should connect a +12v supply to the collector of your transistor.
do like this :

Using a "big sound" module with arduino to create a decibel meter

I am trying to create a sound meter to measure the decibels in a room and I am currently using a nodemcu 12e as I want to insert those measures to a row in a mySQL server and a "big sound module" (https://tkkrlab.nl/wiki/Arduino_KY-038_Microphone_sound_sensor_module).
The only thing I have achieved so far is to get the raw values of the sensor, as they don't seem to change, although I have tried to adjust the gain turning the screw in the microphone, with no result, as it seems to stay in the same values even when playing loud music.
It seems to react to loud noises, and clapping makes the output to spike up - allowing me to control that lighting up the connected led:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "yourssid";
const char* password = "yourpass";
ESP8266WebServer server(80);
const int led = 13;
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = D7; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
});
//SETUP SOUND SENSOR
pinMode (ledPin, OUTPUT);
}
void loop(void){
sensorValue = analogRead (sensorPin);
Serial.println (sensorValue);//, DEC);
if (sensorValue > 100){
digitalWrite (ledPin, HIGH);
delay (1000);
digitalWrite (ledPin, LOW);
}
}
I am reading the analog value of the sensor and I tried to get the lower values possible as seen I was trying to calibrate the mic. The values I am constantly getting are between 19 and 20:
As you can see, on clapping I get a spike of the value.
The thing is that the values don't change at all when loud music is playing, only getting different values when it detects a loud noise (like clapping). How can I change the code or system to get the values in decibels?
You might not get this running with this microphone module.
The mdule act as a switch. The switching threshold is set by the potentiometer on board of the microphone module.
What you would need is a low-level amlified microphone. Then you would get an input range from 0 (no noise) to 1023 (loud noise). This value then could be mapped to decibel. But again - not with this module.
Regards
Harry
To read a stream of audio signal via analog0 input you need a board that has an analog output. The board you're using has a Digital output which outputs a signal whenever it's threshold it's exceed the limit you set on the potentiometer (yes the potentiometer you were moving just set the limit when the microphone will output a digital pulse).
So you have you should purchase another microphone like this one.
The one you have only tells you if there is sound or no sound.

NRF24L01 with ATTiny and Uno not connecting

I have an ATTiny85 connected to an NRF24L01+ module using this wiring diagram: diagram. The ATTiny85 periodically goes in and out of sleep to send some value to a receiver, an Arduino Uno. If the ATTiny is running off the Arduino power supply (3.3v), everything works correctly. When I run the ATTiny off of a separate CR2032 coin cell that delivers around 3v, the Arduino never receives any data. I have a status LED hooked up to the ATTiny to ensure that the ATTiny is waking correctly, which it is. Here's the code for both:
EDIT:
Connecting it to an external 3.3v not from the Uno makes everything work - why wouldn't the coin cell's voltage work? I think everything is rated below 2.8v, the CR2032 minimum.
ATTiny Code
#include <avr/sleep.h>
#include <avr/interrupt.h>
// Routines to set and claer bits (used in the sleep code)
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define CE_PIN 3
#define CSN_PIN 3 //Since we are using 3 pin configuration we will use same pin for both CE and CSN
#include "RF24.h"
RF24 radio(CE_PIN, CSN_PIN);
byte address[11] = "SimpleNode";
unsigned long payload = 0;
void setup() {
radio.begin(); // Start up the radio
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openWritingPipe(address); // Write to device address 'SimpleNode'
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(500);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(500);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(1000);
setup_watchdog(6);
}
volatile int watchdog_counter = 0;
ISR(WDT_vect) {
watchdog_counter++;
}
void loop()
{
sleep_mode(); //Go to sleep!
if(watchdog_counter >= 5)
{
digitalWrite(4, HIGH);
watchdog_counter = 0;
payload = 123456;
radio.write( &payload, sizeof(unsigned long) ); //Send data to 'Receiver' ever second
delay(1000);
digitalWrite(4, LOW);
}
}
//Sleep ATTiny85
void system_sleep() {
cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
sleep_mode(); // System actually sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON
}
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {
byte bb;
int ww;
if (ii > 9 ) ii=9;
bb=ii & 7;
if (ii > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;
MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR = bb;
WDTCR |= _BV(WDIE);
}
Receiver Code
#define CE_PIN 7
#define CSN_PIN 8
#include <SPI.h>
#include "RF24.h"
RF24 radio(CE_PIN, CSN_PIN);
byte address[11] = "SimpleNode";
unsigned long payload = 0;
void setup() {
while (!Serial);
Serial.begin(115200);
radio.begin(); // Start up the radio
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openReadingPipe(1, address); // Write to device address 'SimpleNode'
radio.startListening();
Serial.println("Did Setup");
}
void loop(void){
if (radio.available()) {
radio.read( &payload, sizeof(unsigned long) );
if(payload != 0){
Serial.print("Got Payload ");
Serial.println(payload);
}
}
}
Is the problem here that the ATTiny and Uno need to be turned on at the same time to establish a connection, or is it something to do with the battery, or something else entirely? Any help would be appreciated.
I'm experiencing the same problem when running Arduino Nano from a battery.
Nano has a 3.3V pin that I'm using for powering the NRF24L01+ module.
When the voltage from my battery-pack drops under 3.3V, the 3.3V pin voltage also drops. After few minutes, the RF module is not sending any messages.
I fixed the problem temporarily by routing the battery through a 12V step-up regulator that I bought earlier for a different project. These 12V then go to the "UN" pin on Nano which accepts 6-20V. This setup works nicely but is definitely not optimal.
Therefore I'm planning to use a 3.3V step-up regulator such as Pololu 3.3V Step-Up Voltage Regulator U1V11F3 which, according to the supplier, can efficiently generate 3.3V from input voltages as low as 0.5V.
I think this might be helpful to your project as well.

Resources