text:
How to get data from a device using ethernet connection with arduino
I have a question,
I know how to flush the result of a device(using PIN mode) / control a device with help of an Ethernet shield of arduino.
Now, the thing I want is I need to read a device which communicates only via Ethernet. so i have now connected the device with a router and I have the IP address of the device. I need to read the data from the device using arduino + Ethernet shield.
In fine: How to read data from a device connected to a arduino + Ethernet Sheild via lan cable and flash the result in web server or serial portal. Doesn't matter.
Please suggest a solution or help me with code.
regards,
J

What device? A web server? An IP Camera? A NAS? The question is what protocol you need to use: HTTP, FTP, TELNET, SMB, .... until then, your question is unanswerable.

The device is called "SCS EM Aware" - it sense  the electric field. The protocol can be HTTP.

Please, post a link to the exact device your are using.

http://staticcontrol.descoindustries.com/SCSCatalog/Monitors/ESD-Event-Monitors/EM-Aware-Monitor/770063/#.WnxIJKinGUk

That device communicates with their own custom server software (running in Windows) using their own custom protocol. You would need to spend a long time decoding their protocol using network sniffing software. Not a task for a beginner.

You are out of luck: The device talks SMP (Static Managment Program), which is a close-source product of the same vendor.
The protocol used by SMP is not documented. The only way to access it is via the vendor own Windows software management.
Decoding the protocol is out of question.


text:
Using TFT touchscreen with Arduino Uno R3 via I2C
I've recently gotten into Arduino, due to a friend asking to be part of a project. The project requires a few 24V LED strips to be controllable via PWM, probably over MOSFETs (we have someone else in the team that will look after the electronics, I will be mostly responsible for the code) and also various sensors to measure the environment. However, the project should also include a touchscreen that will be used for programming these LEDs based on time and date, and displaying the data from these sensors, or program further events based on their input.
As far as I understand it should be possible to drive a TFT touchscreen via I2C? I've done some googling over the past two hours or so and could barely find any information about what screens to use for such projects, no tutorials, nor if there are any libraries available.
Is it doable to do a project of this magnitude with a Uno R3, or should I consider a Due or Mega?
I have a touchscreen shield right here, but it leaves me with only one PWM and one analogue pin if I don't plan on using the SD card that is on its back.
Maybe I'll find the answer myself, but I have literally only joined the Arduino/microcontroller fun a few days ago and am reading up on the whole topic in a 'for dummies' book which is very interesting, but it only touches on I2C at the very end and I don't want to confuse myself too much by jumping ahead and reading about stuff that doesn't directly answer my questions. So I turn to you guys for at least pointing me in the right direction on what I should read up on or linking me to tutorials.
Also, if you guys have any books to recommend on the topic I'll be glad to take recommendations.
Thanks in advance

A TFT touchscreen actually normally consists of two completely separate items:

TFT Display
Touchscreen and optional interface chip

While you can get both of those together on a board with both using I2C it is quite rare. It is far more common to find boards with either SPI or 8- (or 16-) bit parallel interfaces for the TFT screen, and SPI (or sometimes 4 channel analog - a direct connection to the touch screen itself) for the touch screen.
I2C is really only used for very small screens. The slow speed of the I2C protocol means that updating the display is very slow, which results in very poor performance for anything bigger than, say 128x128 pixels. It's usually used for things like small OLED displays rather than larger TFT displays.
Touchscreens with I2C are normally capacitative rather than the cheap resistive, so tend to be a little more expensive and harder to work with. The most common touch screen chip, the XPT2046, is SPI.
Fitting everything you want to do into an Uno is going to be tight, and not just because of the number of IO pins a display usually demands. Working with displays usually means lots of graphics (icons, symbols, fonts, etc), and that means a lot of flash memory. A Mega2560 would be a better choice for that if you want to remain with 8-bit.
However better graphical results would be obtained using a more powerful board. The Arduino Due, with its 32-bit ARM chip, would allow you to do much more graphical manipulation, such as drawing nice graphs etc.
My personal preference, though, is to use a PIC32 based board and the chipKIT core, coupled with my own powerful DisplayCore library. But then I'm biased.

I see, thanks a lot for your comment. I've also found out that SPI is more suited for our targeted screensize.

I think for now I'm going to stay with Arduino since I'm still new to all of this, and having so many tutorials and books at my disposal is great until I understand better how all of it works.
I've already ordered a Mega since I already understood that it's going to be tight with I/O anyway if we want to control x amount of LED strips, tho I do also know about shiftregisters capable of PWM such as the TLC5490, which is also underway. Mega will be nice for prototyping anyway.

Absolutely, though I have to plug my stuff when I can ;) The TLC5490 is nasty to work with. The TLC59116 is far far better.

In what way is it nasty to work with? I'll look into the TLC59116 too.

From what I remember the protocol is custom and very awkward to use. The TLC59116 is just plain I2C.

Actually I may be confusing it with some early addressable LEDs that used a protocol that needed constantly refreshing. The TLC5940 is just like a shift register, with all the down sides that come with that (having to refresh the entire chain to just change one LED). It's not as bad as I was remembering, but the TLC59116 is still better being I2C that lets you address each output individually.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
How I can divide information stream from bluetooth hc-06?
All good afternoon or evening. I am having a problem writing a sketch for Arduino using Arduino UNO and Bluetooth HC - 06.
My program does not divide the input stream of information into several variables. No matter how many variables I specify, they are considered as one.
Maybe I do not know all subtleties of the use of Serial.read(). Apparently from a sketch given below I get through Bluetooth two variables of color and var. A microcontroller perceives these two variables as one and as a result does not execute before him task. As a result we will be able to choose the color and change delay of blinking by this color.
If anybody knows how to correct this problem or can point me to a similar project I will be very thankful for any rendered help
const int rPin = 3;
const int gPin = 5;
const int bPin = 6;
int chosed_color;
int val;
int color;

void setup()
{
  Serial.begin(9600);
  pinMode( rPin, OUTPUT );
  pinMode( gPin, OUTPUT );
  pinMode( bPin, OUTPUT );

}

void loop()
{
while(Serial.available()>0)
  {
     color = Serial.read();
   if(color==1)
      {
       chosed_color = rPin;
      digitalWrite( rPin, HIGH );
      digitalWrite(rPin, LOW);
       return chosed_color;
      }
        else if(color==2)
      {
       chosed_color = bPin;
       digitalWrite( bPin, HIGH );
      digitalWrite(bPin, LOW);
       return chosed_color;
      }
         else if(color==3)
      {
        chosed_color = gPin;
       digitalWrite( gPin, HIGH );
       digitalWrite(gPin, LOW);
       return chosed_color;
      }
  }
if(Serial.available()>0)
{
  val = Serial.read();
}

      digitalWrite( rPin, HIGH );
      delay(val);
      digitalWrite(rPin, LOW);
      delay(val);
}

Your code have various issues.
This:
   if(color==1)
      {
       chosed_color = rPin;
      digitalWrite( rPin, HIGH );
      digitalWrite(rPin, LOW);
       return chosed_color;
      }

means that when you find a color, you exit loop() instead of reading the val variable.
Serial.read
Serial.read read only one byte. If you need to read an arbitrary integer, need Serial.parseInt or some elaborate solution. As it, you are only able to read one-digit integer values.
Worse, when you type "1" in the Serial Monitor, what the program received is the value 49 (the ascii code for char 1).
Also, you have to filter non interesting chars, like LF, CR, commas or whatever char you use as delimitir.
Please, read the excelent post by Majenko about Reading Serial on the Arduino.
Here a better version of your code. It is very basic and lacks all error checking, etc.
const int rPin = 3;
const int gPin = 5;
const int bPin = 6;
int pins[3] = {rPin, gPin, bPin};

void setup()
{
    Serial.begin(9600);
    pinMode(rPin, OUTPUT);
    pinMode(gPin, OUTPUT);
    pinMode(bPin, OUTPUT);
}

void loop()
{
    if(Serial.available()>0) {
        int color = Serial.read();
        int chosed_color = pins[color-1];
        digitalWrite(chosed_color, HIGH);
        digitalWrite(chosed_color, LOW);

        if(Serial.available()>0) {
            int val = Serial.read();
            digitalWrite(chosed_color, HIGH); // I suppose you want this
            delay(val);
            digitalWrite(chosed_color, LOW);
            delay(val);
        }
    }
}

this code doesn't work. I agree that it is more perfect but I don't see any result.

@AndrewGoroshko. As I said, you have a lot to work to do. I just simplify your code (and some cleanup). For example, the code assume that val will be always available, but that is not always the case. Also, it doesn't taken in account the missing char to int conversion at Serial.read() ... if you write the char 1 at the Serial Monitor, your code receive 49. It's full of traps. Sorry

I send int variable from my phone but not char, although I am so appreciate you for solving several my problems

You have a misconception, how serial communication works. The data is transmitted one byte at a time and not in one bunch (even if you type it in the Serial Monitor in as one string). So, when you use distinct if- or while-statements for each variable, the data may arrive at any step in these statements, without any possibility to distinguish between the variables.
You have to ways dealing with serial messages (I prefer the latter for it is more flexible):

Constant message length: You can always send messages with the same length. This is suitable for small projects with only one functionality, so that you always send the same amount of data. In this case you can wait for all bytes of a message to arrive and then treat the message as a whole:

if(Serial.available() >= 2){
  variable1 = Serial.read();
  variable2 = Serial.read();
}

Using a delimiter character for each message: After each message you can send an extra byte, which value you treat as a delimiter for a message. Normally with this method you save each available byte in an extra buffer, until you receive your delimiter character (often the newline character is used '\n'):

void setup(){
  String message="";
}

void loop(){
  while(Serial.available>0){
    char c = Serial.read();
    if(c == '\n'){
      // Message is complete in buffer variable
      // Extract values from it
      if(message.length>0){
        byte variable1 = message[0];
      }
      if(message.length>2){
        int variable2 = (message[1] << 8) | message[2];
      }
      // Reset buffer variable
      message = "";
    } else {
      // Message is not complete, add byte to buffer variable
      message += c;
    }
  }
}

As said in the other answers you have to decide, how to send numerical data.

You can send direct byte data as I used in the code above. When you are sending a bigger value to the Arduino than 1 byte, you can take the corresponding number of bytes from the buffer and put them into one variable (<< 8 shifts the byte data 8 bytes to the left (in the direction of the MSB); | makes a bytewise or, that puts the bytes together in this code).
If you want to type in values in the serial monitor, you have to consider, that these are simple ASCII encoded strings. In this case you can use the String.toInt() function and it's siblings on a substring of your message, that contains the numerical value.

Communication is done only with bytes. A byte is ALWAYS a numerical value and you cant' transmit more than one byte at a time.
Saying that, you have two points to understand:
1) how do you want to "see" the result, from a human point of view?
2) how can you transmit more than one byte?
Just test this little sketch:
 void setup() {
Serial.begin(9600);
Serial.println(65);
Serial.println("65");
Serial.println("A");

Serial.write(65);
Serial.write('A');
}

void loop()
{
}

You will get on the serial monitor:
65
65
A
AA
Check for ASCII table on the internet and you'll see a list of code for letters representation.
Now: Serial.println("65"); don't print the number 65. It prints the "letters" for human representation of this number. In fact, 65 is a number but here is the "human word".
If you have 65 potatoes in a bag, a french will say "soixante cinq". An Englisman will say "sixty five" and a portuges will say "sesenta y cinquo". But they have all the same number of potatoes.
So the computer has the number but the human has the visual representation of the number.
Serial.print convert automaticly the numerical value in a "letter value". So when you do Serial.print(65) you don't print ONE byte... but TWO! First one is the human representation of 6 (which has the ASCII value of 54) and the the human representation of 5 (which has the ASCII value of 53)
Then the next line also print 65 because I have had "quote". So Serial.print dsplay this as a text.
The third write "A" which is a "text"
Then we use Serial.write(). Serial.write don't try to create a "human" point of view. So it uses directly the number as an ASCII value.
As 65 is the ASCII value for A, Serial.write(65) send only ONE byte and show it as the ASCII letters so A.
And of course Serial.write('A') give the same result.
For transmission, this is the very first point to understand: if you transmit a byte with value of 65 you'll get this same value on the other side. But depending on the way you display, you can be fooled and believe transmission was wrong ("I send 'A' and receive 65!")
For the second point ("how can I transmit more than a byte"): if you have 2 values to send and each one is on one byte, you have to send two bytes.
While receiving, you put the first byte coming in, in a variable, and the second in an other.
If you have to transmit a values using an INT so two bytes, you have to "break" the INT into bytes.
Eg the INT as a value of 3154 (in décimal). Its Hexa representation is 0x0C52.
You can break this in two blocks: 0x0C it the value of half of the INT and 0x52 is the other part.
So you can transmit 0x0C (higher part of the INT), then 0x52 (lower part of the INT) and while receiving you use the two bytes to "build again" the INT value.
To send 0x0C52 (INT) and 0xF345AC12 (LONG) you must send:
0x0C, 0x52, 0xF3, 0x45, 0xAC and 0x12 so a total of 6 bytes. Then while receiving you "build back" the value.
Of course, if you don't remember the way you "break for sending", you can be confused.
Because 0x0C, 0x52, 0xF3, 0x45, 0xAC and 0x12 can be seen as:

six bytes
three INT (0x0C52, 0xF345 and 0xAC12),
one long and two bytes (0x0C52F345, 0xAC and 0x12)
etc...

So you must "rebuild" according to the way you "break" the data while sending!
Hope this will help understanding.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Where can I find the complete list of Arduino Serial Command & Query Strings?
I am planning to use the Arduino as a replacement for a USB-Controlled Digital I/O device, which will be integrated into an existing C++ software package that I created. I understand that the Arduino acts like a Serial device to a PC. Every serial device can be controlled by its own set of commands and queries. However, the only commands and queries that I've found for the Arduino involve flashing one-time programming to it from the "inside" rather than providing real-time automated control from the "outside."
Can anyone tell me where can I find the complete list of Arduino serial command & query strings? Thanks.

You probably want to write your own application-specif command interpreter on the Arduino. You may want to take a look at this Simple Arduino command line interpreter for inspiration.

The Arduino has no "standard" serial commands.
It is a programmable device which you have to program yourself. The only serial commands it can respond to are the serial commands you yourself program it to respond to.
There are projects around that provide a serial interface, but they are generally designed for one specific purpose, and the commands or protocol they implement are unique to that project.
The closest to what you are asking for is the Firmata firmware, which comes with the IDE, and can be used to control the Arduino through the serial port using programs on your PC.

Arduino is a computer. It is designed to run programs that interact with real world via multiple digital and analog pins.
It has a USB port (Arduino UNO) to connect with a desktop computer. You develop programs for Arduino with your Windows/Mac/Linux computer and download them to Arduino vía USB port.
So, Arduino do only what you program it to do. No command or query string involved.
An Arduino sketch access use the USB port as a Serial port. It's normally used for debugging purposes (sending back information to the PC) or for configuration/control, if you want not to add a keypad and display to your project.
Some Arduinos doesn't comes with a USB interface.

Don't tell him it's a computer, he'll try and install Microsoft Word on it...

Or turn it into a Minecraft server.


text:
LoRa stops working after several hours. Arduino reset button ineffective
I am designing a master-slave LoRa link between two Arduino Pro Minis. The goal is to control a car heater a few hundred meters from my home. The master sends a command to the slave as needed. The slave acknowledges the command.
If no ACK is received in 5 sec the command is resent. In addition to this the master queries the slave every minute to verify the link.
This library is used to control the DRF1278F
I presume that a receive callback or a call to LoRa.parsePacket() returns either nothing or a complete packet, so I do not ever have to handle partial packets.
Chinese Arduino Pro Mini 3.3V 8MHz boards are used.
I am using a module DRF1278F module which contains an RFIC SX1278
Connections
Arduino --> LoRa module
----------------------------------
  SS 10 --> NSEL 10k pullup to Vcc
 SCK 13 --> SCK
MISO 12 --> SDO 100k pulldown to GND
MOSI 11 --> SDI
 INT  3 --> IO0
 RST  6 --> RST

The device is built on a piece of PCB acting as a ground plane, all GND connections are done to this plane.
It is constructed with short direct wiring.

Problem.
After several hours of operation either the master or the slave sort of hangs up. No radio operations any more. There is activity on the SPI but very different to normal operation. I have tested for weeks and not yet survived for one night.
Pushing the reset button does not restore operations. Removing 3.3V power always restore normal operation, even a very brief short circuit of 3.3V.
There is no need to rest in power down, so probably not an overheat issue.
It can be either the master or the slave end that hangs up. Power cycling only the hung up unit will restore communications. My simple protocol will then resyncronize itself and continue running.
The arduino watch dog timer is activated, however it does not trigger when the hangup occurs as the arduino program loop still runs.
Things tested.
The 3.3 V supply has less than 50mV p-p ripple as checked with an oscilloscope set to infinite persistence for 8 hours, while a hangup occurred.
The interface can be run either polled or interrupt driven, no difference.
No String objects are used.
Using different Vcc like 3.0V and 3.6V makes no difference.
Extra Vcc decoupling made no improvement.
Lowering SPI speed from 8MHz to 4MHz made no difference.
Removed Arduino LED on pin 13.
My problem symptoms are similar to this old question
What can I do to resolve this issue?
Slave code:
/*
Relay controller, remote end of link
*/
#include <SPI.h>
#include <LoRa.h>
#include <avr/wdt.h>

//#define TTT

#define csPin 10
#define resetPin 6
#define irqPin 3         // must be a hardware interrupt pin
#define myLED 8
#define GNDRET 7
#define powerPin 9

unsigned long LEDtime;
const unsigned long LEDonTime = 500;

char outgoing[40];
byte msgCount = 0;
unsigned long lastLoopTime = 0;
unsigned long heaterStarted = 0l;
const unsigned long heaterTime = 60 * 60 * 1000L; // One hour in ms
unsigned interval = 2000;
int temp = 2310;
byte localAddress = 0x11, destination = 0xAA;
unsigned long ttt;

volatile char incoming[40];
volatile int recipient;
volatile byte sender, incomingMsgId,
incomingLength, gotMsg, ovrn;

void setup()
{
    Serial.begin(9600);
    while (!Serial);
    pinMode(myLED, OUTPUT);
    digitalWrite(myLED, LOW);
    pinMode(GNDRET, OUTPUT);
    digitalWrite(GNDRET, LOW);
    pinMode(powerPin, OUTPUT);
    digitalWrite(powerPin, LOW);

    Serial.println("LoRa Switch 0.1");

    LoRa.setPins(csPin, resetPin, irqPin);
/*
    LoRa.setTxPower(10);
    LoRa.setSpreadingFactor(12);
    LoRa.setCodingRate4(8);
    LoRa.setSPIFrequency(4E6);
    LoRa.enableCrc();
*/
    wdt_enable(WDTO_1S);

    if (!LoRa.begin(433E6))
    {
        Serial.println("LoRa init failed. Check your connections.");
        {
            // blinking in panic
            LEDtime = millis();
            while (millis() - LEDtime < 75)
            {
                digitalWrite(myLED, HIGH);
            }
            while (millis() - LEDtime < 150)
            {
                digitalWrite(myLED, LOW);
            }
        }
    }

    LoRa.onReceive(onReceive);  // Assign callback
    LoRa.receive();
    Serial.println("LoRa init succeeded.");
}

void loop()
{
    if (millis() - lastLoopTime > 1000)
    {
        // Once per second loop
        lastLoopTime = millis();
    }

//  onReceive(LoRa.parsePacket()); // Polling

    if (gotMsg)  // Flag from CallBack routine
    {
        digitalWrite(myLED, HIGH);
        LEDtime = millis();

#ifdef TTT
        Serial.print("Received from: 0x");
        Serial.println(sender, HEX);
        Serial.print("Sent to: 0x");
        Serial.println(recipient, HEX);
        Serial.print("Message ID: ");
        Serial.println(incomingMsgId);
        Serial.print("Message length: ");
        Serial.println(incomingLength);
        Serial.print("Message: <<");
        for (int i = 0; incoming[i] != 0; i++)
            Serial.write(incoming[i]);
        Serial.println(">>");
        Serial.print("RSSI: ");
        Serial.println(LoRa.packetRssi());
        Serial.print("Snr: ");
        Serial.println(LoRa.packetSnr());
        Serial.println();
#endif
        // Command processing
        if (incomingLength == 4)
        {
            // Start heater, it will either timeout or be stopped by a message
            if ((byte)incoming[0] == 0x55 && (byte)incoming[1] == 0xAA)
            {
                Serial.println("Set on");
                digitalWrite(powerPin, HIGH);
                heaterStarted = millis();
            }

            if ((byte)incoming[0] == 0xCC && (byte)incoming[1] == 0x99) // Stop heater
            {
                Serial.println("Set off");
                digitalWrite(powerPin, LOW);
                heaterStarted = 0L;
            }
            // Build ack answer

            if (heaterStarted > 0L)
            {
                // Compute session time in minutes
                ttt = millis() - heaterStarted;
                ttt /= (1000L * 60L); // minutes since start
            }
            else
                ttt = 0L;
            outgoing[0] = (heaterStarted > 0L) ? 'T' : 'F'; // Heater state
            snprintf(outgoing + 1, 30, "%3lu", ttt);

            incoming[0] = 0; // We are done, clear flags
            gotMsg = 0;

            sendAck(outgoing);
        }
        LoRa.receive();

    }

    if (LEDtime) // LED timeout
    {
        if (millis() - LEDtime > LEDonTime)
        {
            digitalWrite(myLED, LOW);
            LEDtime = 0;
        }
    }

    if (heaterStarted) // Heater timeout
    {
        if (millis() - heaterStarted > heaterTime)
        {
            digitalWrite(powerPin, LOW);
            heaterStarted = 0L;
        }
    }
    wdt_reset();
    // END of loop
}

void sendMessage(char *outgoing)
{
    LoRa.beginPacket();                   // start packet
    LoRa.write(destination);              // add destination address
    LoRa.write(localAddress);             // add sender address
    LoRa.write(msgCount++);                 // add message ID
    LoRa.write(bsize(outgoing));        // add payload length
    LoRa.print(outgoing);                 // add payload
    LoRa.endPacket();                     // finish packet and send it
}

void sendAck(char *outgoing)
{
    Serial.println("Send ACK");
    LoRa.beginPacket();
    LoRa.write(destination);
    LoRa.write(localAddress);
    LoRa.write(incomingMsgId);            // report ID
    LoRa.write(bsize(outgoing));        // add payload length
    LoRa.print(outgoing);                 // add payload
    LoRa.endPacket();
}

byte bsize(char *ooo)
{
    byte i = 0;
    while (ooo[i++]);
    return i - 1;
}

byte bsize(volatile char *oo)
{
    return bsize((volatile char *)oo);
}

byte insptr;
void onReceive(int packetSize) // has to be a non blocking function
{
    if (packetSize == 0) return;     // if there's no packet, return
    if (gotMsg) ovrn = true; // gotMsg should be reset by consumer by now

    // read packet header bytes:
    recipient = LoRa.read();         // recipient address
    sender = LoRa.read();            // sender address
    incomingMsgId = LoRa.read();     // incoming msg ID
    incomingLength = LoRa.read();    // incoming msg length

    insptr = 0;

    while (LoRa.available())
    {
        if (insptr < 38)
            incoming[insptr++] = (char)LoRa.read();
        else
            LoRa.read();  // Flush
    }
    incoming[insptr] = 0;  // End of C string
    gotMsg = true;

}

/*
void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
void setFrequency(long frequency);
void setSpreadingFactor(int sf);
void setSignalBandwidth(long sbw);
void setCodingRate4(int denominator);
void setPreambleLength(long length);
void setSyncWord(int sw);
void enableCrc();
void disableCrc();
*/

Master code:
/*
Relay controller, Controller and GUI base
*/
#include <SPI.h>
#include <LoRa.h>
#include <avr/wdt.h>

#define TTT

#define csPin  10
#define resetPin 6
#define irqPin 3         // must be a hardware interrupt pin
#define ackLED 9
#define LEDGND 8
#define remoteLED 7

unsigned long LEDtime;
const unsigned long LEDonTime = 500;

char outgoing[40];
byte msgSequ = 0, mincnt, ack_TO;
unsigned long lastLoopTime = 0;
unsigned interval = 2000;
byte localAddress = 0xAA, destination = 0x11;
unsigned long ttt;

volatile char incoming[40];
volatile int recipient;
volatile byte sender, incomingMsgId, incomingLength, isACKed, gotMsg, ovrn;

char cc;

void setup()
{
    Serial.begin(9600);
    while (!Serial);
    pinMode(ackLED, OUTPUT);
    digitalWrite(ackLED, LOW);
    pinMode(remoteLED, OUTPUT);
    digitalWrite(remoteLED, LOW);
    pinMode(LEDGND, OUTPUT);
    digitalWrite(LEDGND, LOW);
    isACKed = 1;
    Serial.println("LoRa Master 0.1");

    LoRa.setPins(csPin, resetPin, irqPin);
/* no specials
    LoRa.setTxPower(10);
    LoRa.setSPIFrequency(4E6);
    LoRa.setSpreadingFactor(12);
    LoRa.setCodingRate4(8);
    LoRa.enableCrc();
*/
    wdt_enable(WDTO_1S);

    if (!LoRa.begin(433E6))
    {
        Serial.println("LoRa init failed. Check your connections.");
        {
            // blinking in panic
            LEDtime = millis();
            while (millis() - LEDtime < 75)
            {
                digitalWrite(ackLED, HIGH);
            }
            while (millis() - LEDtime < 150)
            {
                digitalWrite(ackLED, LOW);
            }
        }
    }

    LoRa.onReceive(onReceive);  // Assign callback
    LoRa.receive();
    Serial.println("LoRa init succeeded.");
}

void loop()
{
    digitalWrite(ackLED, isACKed == 0);

    if (millis() - lastLoopTime > 1000)
    {
        // Once per second loop
        lastLoopTime = millis();

        if (isACKed == 0)
        {
            if (ack_TO++ > 5)
            {
                sendMessage(outgoing); // Resend
                LoRa.receive();
                ack_TO = 0;
                Serial.println("Resend...");
            }
        }

        if (mincnt++ > 60)
        {
            // Once per minute loop
            mincnt = 0;
            if (isACKed)  // Free to ask
            {
                // Heartbeat
                cmdAsk();
                isACKed = 0;
            }
        }
    }

    if ((cc = Serial.read()) > 0)  // Test version, cmd
    {
        if (cc == '1')
        {
            cmdOn();
            isACKed = 0;
        }
        else if (cc == '0')
        {
            cmdOff();
            isACKed = 0;
        }
        else if (cc == 'Q')
        {
            cmdAsk();
            isACKed = 0;
        }
    }
//  onReceive(LoRa.parsePacket()); // Polling

    if (gotMsg)  // Flag from onReceive routine
    {
#ifdef TTT
        Serial.print("Received from: 0x");
        Serial.println(sender, HEX);
        Serial.print("Sent to: 0x");
        Serial.println(recipient, HEX);
        Serial.print("Message ID: ");
        Serial.println(incomingMsgId);
        Serial.print("Message length: ");
        Serial.println(incomingLength);
        Serial.print("Message: <<");
        for (int i = 0; incoming[i] != 0; i++)
            Serial.write(incoming[i]);
        Serial.println(">>");
        Serial.print("RSSI: ");
        Serial.println(LoRa.packetRssi());
        Serial.print("Snr: ");
        Serial.println(LoRa.packetSnr());
        Serial.println();
#endif
        // Command processing
        if (incomingLength == 4)
            if (incomingMsgId == msgSequ - 1) // Ack is on last sent
            {
                if (incoming[0] == 'T') digitalWrite(remoteLED, HIGH);
                if (incoming[0] == 'F') digitalWrite(remoteLED, LOW);
                isACKed = 1;
            }
        incoming[0] = 0; // Message is processed, clear flags
        gotMsg = 0;
    }

    if (LEDtime) // LED timeout
    {
        if (millis() - LEDtime > LEDonTime)
        {
            LEDtime = 0;
        }
    }
    wdt_reset();
}   // END of loop

void cmdOn()
{
    outgoing[0] = 0x55; // Heater  on
    outgoing[1] = 0xAA;
    outgoing[2] = 'X';
    outgoing[3] = 'Y';
    sendMessage(outgoing);
    LoRa.receive();
}

void cmdOff()
{
    outgoing[0] = 0xCC; // Heater  off
    outgoing[1] = 0x99;
    outgoing[2] = 'A';
    outgoing[3] = 'B';
    sendMessage(outgoing);
    LoRa.receive();
}

void cmdAsk()
{
    outgoing[0] = 0x0F;
    outgoing[1] = 0xF0;
    outgoing[2] = '7';
    outgoing[3] = '7';
    sendMessage(outgoing);
    LoRa.receive();
}

void sendMessage(char *outgoing)
{
    LoRa.beginPacket();                   // start packet
    LoRa.write(destination);              // add destination address
    LoRa.write(localAddress);             // add sender address
    LoRa.write(msgSequ++);                 // add message ID
    LoRa.write(bsize(outgoing));        // add payload length
    LoRa.print(outgoing);                 // add payload
    LoRa.endPacket();                     // finish packet and send it
}

byte bsize(char *ooo)
{
    byte i = 0;
    while (ooo[i++]);
    return i - 1;
}

byte bsize(volatile char *oo)
{
    return bsize((volatile char *)oo);
}

unsigned char insptr;
void onReceive(int packetSize) // is a non blocking function
{
    if (packetSize == 0) return;     // if there's no packet, return
    if (gotMsg) ovrn = true; // gotMsg should be reset by consumer by now

    // read packet header bytes:
    recipient = LoRa.read();         // recipient address
    sender = LoRa.read();            // sender address
    incomingMsgId = LoRa.read();     // incoming msg ID
    incomingLength = LoRa.read();    // incoming msg length

    insptr = 0;

    while (LoRa.available())
    {
        if (insptr < 38)
            incoming[insptr++] = (char)LoRa.read();
        else
            LoRa.read();  // Flush
    }
    incoming[insptr] = 0;
    gotMsg = true;
}

/*
void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
void setFrequency(long frequency);
void setSpreadingFactor(int sf);
void setSignalBandwidth(long sbw);
void setCodingRate4(int denominator);
void setPreambleLength(long length);
void setSyncWord(int sw);
void enableCrc();
void disableCrc();

RSSI always a value between -30 ( very close) and - 120
SNR 0 is noise floor… max = 10

*/

If pressing Reset on the Arduino doesn't help it seems likely to me that the Lora part is the problem. Pressing Reset wouldn't reset that (necessarily).

does it always hang up after the same amount of time?

Removing 3.3V power always restore normal operation - to which end? Sending or receiving?

between two Arduino Pro Micros ... Chinese Arduino Pro Mini 3.3V 8MHz boards are used - which is it? Mini or Micro?

maybe it has something to do with a sequence counter of some kind reaching an overflow condition

@Nick Gammon How to edit  the code segments like you did?

@jsotola The time to hangup seems random and quite long. Also which side, master or slave, that hangs up seems unpredictable.

The DRF1278F has a reset pin. Just connect that pin to one of the Arduino pins. Then in the setup set the pin to OUTPUT and LOW, wait a ms, then turn it back into an INPUT. That way the DRF1278F also resets, when the arduino resets. E.g. through a WDT event, which you're already using.

@Gerben LoRa.begin() pulses NRST, however it does not seem to work when hung up. WDT is not triggered by the hangup.

How to use markdown

i would have the lora turn off for 50 seconds, then on for 10, in a loop. saves power 80%, ensures "fresh boot", with only a min of lag max to start the heater. might also consider ESPNOW instead of LORA.

I feel I want to report the probable solution to this problem.
I hope an answer to my own question is appropriate.
After much testing I found an interaction between the boot loader and the watchdog. This post describes it well: Watchdog timer blog post
So, replacing the boot loader seems to remove the hangup, so far ...
Why the watchdog triggers in the first place remains to be found out but presently it does little or no harm.
A side note, the reset button seems to reset the ProMini if pushed reasonably soon after the hangup. If pushed hours later it has no effect.

Has been running continiously for over a year now wihout any hangup.


text:
UID value arduino uno
How to read UID value in arduino uno to PHP language?
before, thanks for a lot

Use this library: https://github.com/rubberneck/php-serial
On GNU/Linux, you may need to be a member of the ‘dialout’ group. Ubuntu solves this problem by making its users members of every group, so you may not need to edit /etc/group
Once you have connected via a USB or USB-TTL cable (the latter will not force a reset upon connect), use a buffer to store all the reads, then parse them.

I using OS Windows sir, How?

@AsepERoni Nevermind, try that library. It will work on Linux, OSX, Windows.

wheter have his way? step by step, because I fairly new for this is..

@AsepERoni Connect to COM1 (or whatever port is used), read data into a buffer, parse it, use it.

@AsepERoni Is the question answered? If yes, please mark it as such.

i having trouble, at the time of convert Heksadecimal to normal number? how?

@AsepERoni It’s internally just in binary. Define a format with e.g. sprintf( bar, “%i”, foo ), or if using serial, Serial.print( foo, DEC ). Split the UID into a 7-byte array with strtok(). There’s no reason to use decimal for the UID...

do you have example?

@AsepERoni for ( int i=0; i<7; i++) Serial.println( uid[i] ) ... it will be null-terminated so try while ( uid[i++] != ‘\0’ ) Serial.println( uid[i] ) as well. I don’t remember the type used in the PN532 example, IIRC char array. It doesn’t matter... format the output to be adequate for your PHP script, and if you need it to be non-blocking, look in the PN532.cpp file. Change the timeout.

why 7 in looping for?

@AsepERoni use the variable uidLength instead of 7. The variable uid is a char array IIRC, so will have no problem with it. PHP is like Perl, so just use join() and split() equivalents.


text:
Can not initialize ESP module in Arduino SoftwareSerial
Can not initialize ESP module in Arduino SoftwareSerial's example sketch in configuring WiFi module.
In the sketch it tells:
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(11,12); // RX, TX
#endif

I plugged jumper wires in from esp8266 RX to Digital 11 of mega which is RX and TX of esp8266 to Digital 12 of mega, and I compile the code and looked at the Serial Monitor, but it says:
[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module

Advise is greatly appreciated.

it is not SoftwareSerial on Mega. Mega has Serial1. did you connect ground? connect Rx to TX and TX to RX. use pins of hardware  Serial1 of Mega

Yes i connect the ground, my esp01 responds if the connection is RX of esp01 to TX of mega and TX of esp01 to RX of mega.

#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(11,12); // RX, TX
#endif

Because your Mega has a Hardware Serial1 port, HAVE_HWSERIAL1 is defined. Thus the lines inside that preprocessor conditional will not be compiled. This means you should connect the ESP8266 to the Serial1 lines on your Mega:
Mega | ESP8266
--------------
19   | TX
18   | RX

I try to plug it in mega's 18 with esp01's TX and 19 with esp01's RX  and reverse but still gives me time out :( i don't know what to do now.

And also it gives me :error compiling for board arduino /genuino mega or mega2560. please sir help.

first of all the sketch with WiFiEsp library must compile. what are the error details?

I download the library in this link:https://github.com/bportaluri/WiFiEsp and tried the ConnectWPA example.

Then i connect the RX of esp01 to TX 19 of mega and TX of esp01 to RX of mega but still no success.

and the compile error? changing connections is for nothing if the code doesn't compile and upload


text:
LCD not displaying text
I am working with an Arduino due and currently using the Arduino liquid crystal library to display data on an LCD screen (mc42004A6wk-bnmlw) which uses the Hitachi HD44780 controller. The LCD has been update to v2 and is now using the Sitronix ST7066U controller.
From what I have read the two controllers are compatible and the liquid crystal library should work for both. I am using the same software and hardware setup as before but the screen will not display anything.
The software I use is quite complex so I moved to a simple hello world program (below) to test and I still have the same issues. Any advice would be greatly appreciated.
#include <LiquidCrystal.h>
#include <Arduino.h>

LiquidCrystal lcd(30, 31, 32, 33, 46, 47);

void setup()
{

  pinMode(36,OUTPUT);

  digitalWrite(36, LOW);

  delay(5000);

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  lcd.clear();

  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{

  delay(5000);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

Did you adjust the contrast?

I did indeed, no luck. I think its a problem with how the liquid crystal library initializes the screen. Just cant nail down the reason.

So after further investigation into the IDE, Libraries, board manager, hardware etc I discovered what was causing the issue.
On the initial hardware design the hardware engineer placed a capacitor on the enable leg between the LCD screen and the microcontroller. I have no idea why as I have not seen this done in any wiring diagrams but removing it has done the trick. The V2 board now works with all the original code and libraries.

Try using this code, I have edited some parts of your code so this should work.
#include <LiquidCrystal.h>

const int rs = 30, en = 31, d4 = 32, d5 = 33, d6 = 46, d7 = 47;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{

  pinMode(36, OUTPUT);
  digitalWrite(36, LOW);
  delay(5000);    //Its okay to use delay here since its in the setup() function and will run only once

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

For this Hello World sketch, avoid using delay(); statement in the void loop() as it is not good to use when you have the millis(); used.
If the above wont work, check your LCD Wiring, many problems usually arouse from wrong wirings.
Also I may suggest you to use some cheap LCD I2C Backpacks as this will ease the coding and will use less wire and pins on your Arduino. Here is a example

If your'e going to use a I2C LCD Backpack, here is a working sample code.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN     13

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

// Creat a set of new characters
const uint8_t charBitmap[][8] = {
   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }

};

void setup()
{
   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

  // Switch on the backlight
  pinMode ( BACKLIGHT_PIN, OUTPUT );
  digitalWrite ( BACKLIGHT_PIN, HIGH );

  //lcd.begin(16,2);
  lcd.begin(20,4); // initialize the lcd

   for ( int i = 0; i < charBitmapSize; i++ )
   {
      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
   }

  lcd.home ();                   // go home
  lcd.print("LCD TESTER - BY:");
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print ("ABBAS (PRJCT.ME)");
  delay ( 3000 );
}

void loop()
{
   lcd.home ();
   // Do a little animation by writing to the same location
   //for ( int i = 0; i < 2; i++ )
    for ( int i = 0; i < 4; i++ )
   {
      //for ( int j = 0; j < 16; j++ )
      for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 1 );
       for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 2 );
       for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 3 );

   }
   delay (200);
}

Hi EngrAbbas, thank you so much for the reply and code.Removing the delay has given me some progress. The screen is not printing correctly but is now printing random chars on screen such as "?/?/ooo|||" etc. I'm really starting to think that the liquid crystal library is not compatible with the screen. Using the previous version I have no issues, even when using delays and milli's.

I did notice that the controllers have different timing with regards to initialization. Do you think this could be causing the issue?                                Initializing by Instruction - Wait time after power on
ST7066U = Wait time > 40mS       , Hitachi HD44780 = Wait time > 15mS
. Initializing by Instruction - Wait time after first function set
ST7066U = Wait time > 37uS      , Hitachi HD44780 = Wait time > 4.1mS

I had so many troubles with a 20x4 LCD that required numerous data lines. It would work once then I'd power it down & up again & it wouldn't work -- instead showing nothing. I checked all the wiring and tried it again and then got same result as @user1649972 with the random characters showing up.  I thought I had fried the LCD.  I ordered the I2C version (https://amzn.to/2MAOAjL).  It is so much easier. But, I still wanted to see if my orig. LCD worked.  I connected a line from each data line from the new I2C LCD to the old one and lo & behold, it worked!. If any data line isn't 100% it fails.


text:
Missing character when introducing delay in the code
I am using the following code for reading any incoming message, and doing something after decoding the incoming string. There is a delay of 10sec in the code. When this delay is not introduced in the code, it is working nice. In this case, the output is like below.
+CIEV: "MESSAGE",1

+CMT: "+919080404532",,"2018/02/09,19:30:51+06"
This is an incoming test message

When the delay is introduced, I am unable to see the message on the serial monitor, and subsequent action is not taken by the code. The output is like below.
+CIEV: "MESSAGE",1
+CMT: "+919080404532",,"2018/02/09,1

It is clear that, I am missing some character in serial monitor. If delay is reduced to 400 ms, the output is like below.
+CMT: "+919080404532",,"2018/02/09,19:30:51+06"
This is an incoI am working other job

I checked the following, but did not get any improvement.

Serial.flush and mySerial.flush
Increased both hardware, and software aerial buffer size
used if (!mySerial.available() before delay
Changed baud rate for both
Instead of of Serial.readString(), I used Serial.read() character by    character inside function loop

Without use of the delay, it is working nice. I Think you guys are experienced, and can sort out the problem easily.
//while Introducing any delay in function loop, incoming message cant be read
//working with power failure but with serial monitor
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);  // TX-Pin11, RX-Pin10
String str="";
void updateSerial()
{
  delay(2000);
  while (Serial.available()) {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }

}

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
  modemsetup();
}

void loop()
{
 Serial.println("I am working other job");
 //delay(10000);            //If you give this delay, then incoming message cant be read
 smstask();
}

void smstask()
{
if(mySerial.available())
{
str=mySerial.readString();
Serial.println(str);
int bra = str.indexOf('@');
int ket = str.indexOf('#');
String str1=str.substring(bra+1,ket);

if(str1=="server")
{
Serial.println(str);
int i=random(1,500);
String str2=(String)i;
String str3="@deviceA#"+str2;
mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
updateSerial();
mySerial.println("AT+CMGS=\"+917602304567\"\r"); // Replace x with mobile number
updateSerial();
mySerial.println(str3);// The SMS text you want to send
updateSerial();
mySerial.println((char)26);// ASCII code of CTRL+Z
updateSerial();
mySerial.println("AT+CMGD=1,4"); // AT Command to receive a live SMS
updateSerial();
}
}

}

void modemsetup()
{
  for(int i=0;i<3;i++)
  {
  mySerial.println("AT");          //Once the handshake test is successful, it will back to OK
  updateSerial();

  mySerial.println("AT+CSQ");      //Signal quality test, value range is 0-31, 31 is the best
  updateSerial();

  mySerial.println("AT+CCID");    //Read SIM information to confirm whether the SIM is plugged
  updateSerial();

  mySerial.println("AT+CREG?");    //Check whether it has registered in the network
  updateSerial();

  mySerial.println("AT+SNFS=0");  //Adjust to earphone mode(AT+SNFS=1 is microphone mode)
  updateSerial();

  mySerial.println("AT+CRSL=2");  //Adjust volume, volume range is 0-15, maximum:15
  updateSerial();

  mySerial.println("AT+CMGF=1");
  updateSerial();

  mySerial.println("AT+CMGD=1,4");
  updateSerial();
  }

  mySerial.println("AT+CMGS=\"+917602304567\"\r");
  updateSerial();

  mySerial.println("I am SMS from GSM Module");
  updateSerial();

  mySerial.println((char)26);// ASCII code of CTRL+Z
  updateSerial();

}

What is the purpose of delay(2000) in updateSerial()?

That is response time of gsm modem. But that delay is not creating any problem.Problem is the delay inside loop

What I was getting at is that sprinkling long delays like you are doing is poor practice, and when you are using the UART like this, you are bound to run into problems. Instead of pausing the entire CPU while you wait for an external device to maybe answer... instead, just check if it has an answer, and if not, check again later. That is, if (Serial.available()) { ... }, rather than delay(20000) and then drain the buffer.

Yes, that is a good practice. But actual problem is , if any message is received when arduino is busy with doing other stuff, character is missing.

This is not true -- the Arduino has a serial buffer which holds bytes until your code can get around to processing them. However, you have to structure your code so that it doesn't use a lot of long delay() calls, otherwise, it will miss characters, as you are experiencing. It's possible for the Arduino to collect characters one or two at a time, and only deal with the string when you get a character that defines the end of a logical command/result (such as a newline or carriage-return).

I  tried reading character by character also, but getting same error. Actually I am using both lora and GSM with same arduino. LoRA code consists of a  a delay of 2 sec inside loop.  Instead of using full loRA code, I just have introduced a delay intentionally.

If serial data is coming in, and your code is doing a delay, the incoming data is stored in a buffer (of 64 bytes). But if you wait too long, the buffer will fill-up. Once it's full, any further incoming serial data isn't stored, and will be lost.
In your third output example, you get exactly 63 characters. Which is the maximum size a 64-byte cyclic buffer can store.

Thank you for your reply. But I increased buffer size to 256 bytes from SoftwareSerial.h


text:
ILI9341 backlight flickers when using USB power from Laptop
I've developed a project using am ILI9341, ESP12F and Arduino. Everything works fine except a very annoying issue. The LCD flickers when I use the laptop's USB. But when I use a USB charger it's much better.
I use https://github.com/Bodmer/TFT_eSPI library for SPI driver and AMS1117 as regulator (with 1uf in the input, and 10uf in output).
I don't think the software has a problem because I don't refresh anything on the display (just draw something in the setup function, not in loop) and also it changes with different power sources. The problem is the backlight.
When I move the USB cable it goes crazier sometimes. I've checked it with many different cables and computers. Is this because of noise or something from the USB port? How can I fix this?
It's very important for me to be able to use the USB port as the power source.
Update
When I'm uploading the code to the ESP8266 (using TXD & RXI), the LCD doesn't flicker event a little bit! And immediately after finishing the upload, the LCD brightness decreases and starts flickering!
The circuit is pretty simple and LCD pins are connected directly as listed here

Is it the backlight that flickers, or the TFT display?

Just backlight, no problem with display

Try adding a capacitor between Vcc and gnd, near the display.

That happens because not all USB ports can supply more than 500mA of current.
When you use a charger's USB port, it is designed to provide more than 500mA of current(ex. 1-2amps in most chargers). Try using a USB port that can provide more than 500mA of current. Most PCs and Laptops will only supply 500mA at maximum unless specified so.
More information regarding USB power can be read here on Wikipedia.
Cheers!

I don't have anything except an ili9341 & ESP12. Is it normal to need this much power!

Maybe there is a fault with your board. try to measure its current from the USB input using a multimeter. Be sure to put your multimeter in >500mA Mode to not damage it(the multimeter ^_^ )
Adding also a capacitor between the supply and ground may solve the problem also

I solve the problem controlling the frecuency of refresh with the led pin. With a timer of 10ms disappears flickering

I'd vote this up if I understood it and it looked like it addressed the question, but it's not really clear that it does.  Did your controlling of the frequency of refresh solve a problem that had to do with how your project was powered like the poster had?

I fixed this issue finally. The USB could supply both ESP and ILI9341, but the regulator could not. AMS1117 is not able to handle both EPS and ILI9341, we could connect ILI9341 directly to v5 (which it's not good and it would be hot!) or we can use another cheap regulator like XC6206P332MR just for the LCD.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Grove A12-200 current sensor
I am trying to measure current from an LFG with Arduino Uno and Grove current sensor (A12-200). I found a code at this link you can see Arduino code here.
The code works, but there are some operations that I don't understand. Let me copy and paste the code here (for further information, please follow the link above).
/****************************************************************************/
//  Function: Measure the amplitude current of the alternating current and
//            the effective current of the sinusoidal alternating current.
//  Hardware: Grove - Electricity Sensor
//  Date:    Jan 19,2013
//  by www.seeedstudio.com
#define ELECTRICITY_SENSOR A0 // Analog input pin that sensor is attached to

float amplitude_current;               //amplitude current
float effective_value;       //effective current

void setup()
{
    Serial.begin(9600);
    pins_init();
}
void loop()
{
    int sensor_max;
    sensor_max = getMaxValue();
    Serial.print("sensor_max = ");
    Serial.println(sensor_max);
    //the VCC on the Grove interface of the sensor is 5v
    amplitude_current=(float)sensor_max/1024*5/800*2000000;
    effective_value=amplitude_current/1.414;//minimum_current=1/1024*5/800*2000000/1.414=8.6(mA)
                        //Only for sinusoidal alternating current
    Serial.println("The amplitude of the current is(in mA)");
    Serial.println(amplitude_current,1);//Only one number after the decimal point
    Serial.println("The effective value of the current is(in mA)");
    Serial.println(effective_value,1);
}
void pins_init()
{
    pinMode(ELECTRICITY_SENSOR, INPUT);
}
/*Function: Sample for 1000ms and get the maximum value from the SIG pin*/
int getMaxValue()
{
    int sensorValue;             //value read from the sensor
    int sensorMax = 0;
    uint32_t start_time = millis();
    while((millis()-start_time) < 1000)//sample for 1000ms
    {
        sensorValue = analogRead(ELECTRICITY_SENSOR);
        if (sensorValue > sensorMax)
        {
            /*record the maximum sensor value*/
            sensorMax = sensorValue;
        }
    }
    return sensorMax;
}

effective_value=amplitude_current/1.414

I don't understand why dividing amplitude_current by 1.414 we'll get effective_current.
And in the function getMaxValue(), I know what it does, but I don't understand why we just need maxvalue.

it is a degraded without understanding modified copy-pasted example. btw: the sensor measures to 10 A at 230 V

I don't understan what you mean?

You are measuring a sinusoidal "signal" that is alternating in polarity. What the code notes as "effective" current the equivalent DC current for purposes of measuring power consumption. In EE, it's called "RMS" or Root Mean Square, and it's the mathematical derivation to calculate consumed power or current in a situation where the current flows symmetrically back and forth, and thus a time average would give zero.
It's dividing the peak current by the square-root of 2 (1.414).


text:
My outputs are not outputting any current at only two of my pinmodes but work fine on the others
My pinMode output 5 and 6 don't works with this code but will work when they are stand alone.
What is causing the Arduino to not output anything from these outputs within my code?
#include <SoftwareSerial.h>                    // use the software serial library
SoftwareSerial mySerial(3,4); // receive data at pin 3; transmit data at pin 2
int setpoint;
float val;
int roomtemp;
int UCL;
int LCL;

float salinity;
void setup()
{
    // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(5,OUTPUT);
    pinMode(6,OUTPUT);
    pinMode(3,OUTPUT);
    pinMode(2, OUTPUT);
    roomtemp=25;
    setpoint=7.0291*roomtemp+334.73;
    UCL=setpoint+6.12;
    LCL=setpoint-6.12;
    Serial.print("Setpoint =");
    Serial.print(setpoint);
    Serial.print("Degrees Celsius");
    Serial.print("UCL =");
    Serial.print(UCL);
    Serial.print("Degrees Celsius");
    Serial.print("LCL =");
    Serial.print(LCL);
    Serial.print("Degrees Celsius");
    mySerial.begin(9600);
    delay(500);           // set data rate to 9600 baud; wait for bootup
    mySerial.write(254);
    mySerial.write(128);
    mySerial.write(254);
    mySerial.write(1);    // clear screen & move to top left position
    mySerial.write(254);
    mySerial.write(132);
    mySerial.print("LCL");
    mySerial.write(254);
    mySerial.write(139);
    mySerial.print("SP");
    mySerial.write(254);
    mySerial.write(144);
    mySerial.print("UCL");
    mySerial.write(254);
    mySerial.write(192);
    mySerial.print("S:");
    mySerial.write(254);
    mySerial.write(195);
    mySerial.print(0.072,3);
    mySerial.write(254);
    mySerial.write(201);
    mySerial.print(0.100,3);
    mySerial.write(254);
    mySerial.write(207);
    mySerial.print(0.108,3);
    mySerial.write(254);
    mySerial.write(148);
    mySerial.print("T:");
    mySerial.write(254);
    mySerial.write(152);
    mySerial.print("24.1");
    mySerial.write(254);
    mySerial.write(158);
    mySerial.print("25.0");
    mySerial.write(254);
    mySerial.write(164);
    mySerial.print("25.9");
    mySerial.write(254);
    mySerial.write(212);
    mySerial.write(254);
    mySerial.write(212);
    mySerial.print("S=");
    mySerial.write(254);
    mySerial.write(220);
    mySerial.print("T=");
}

void loop()
{
    Serial.println();
    int val=analogRead(5);
    Serial.print("Analog Value =");
    Serial.print(val);
    Serial.print("Temperature =");
    Serial.println((0.14227*val)-47.621);

    if(val<LCL) { digitalWrite(3,HIGH); }
    else if(val>UCL) { digitalWrite(3,LOW); }

    mySerial.write(254);
    mySerial.write(227);

    if(val<LCL) { mySerial.write("H= ON"); }

    mySerial.write(254);
    mySerial.write(227);

    if(val>UCL) { mySerial.write("H=OFF"); }

    digitalWrite(2, HIGH);
    delay(100);
    int analogS=analogRead(4);
    digitalWrite(2, LOW);
    Serial.println(analogS);
    delay(1000);
    salinity = 2.0955*pow(10,-19)*pow(analogS,5.8106)*100.000;
    Serial.print("Salinity =");
    Serial.println(salinity);
    mySerial.write(254);
    mySerial.write(214);
    mySerial.print(salinity);
    mySerial.write(254);
    mySerial.write(222);
    mySerial.print((0.14227*val)-47.621,1);
    Serial.println("analog value");
    Serial.print(analogRead(4));
    float target= (salinity-(salinity-.1)*.60);
    float numer=((((target)*.08585-(salinity)*.08585)/(.1-(.1*.15+salinity*.85)))*60.0);
    float denom= ((.1));
    float valve= ((numer/denom)/10.00);

    if(.096<salinity>.104) {
        delay(5000);
    }

    if(salinity>.104) {
        Serial.print("Entering DIon Function");
        digitalWrite(6,HIGH);
        delay(valve);
        digitalWrite(6,LOW);
        delay(5000);
    }

    if(salinity<.096) {
        Serial.print("Entering Saltyon Function");
        digitalWrite(5,HIGH);
        delay(valve);
        digitalWrite(5,LOW);
        delay(5000);
    }

    Serial.print("time");
    Serial.println(valve);
}

So you are sure that the code parts in which a digitalWrite with 5 or 6 pin is executed, but you don't see the pin values chaning? Can you print out the value of valve, too, or put more delay after setting it HIGH?

And what is printed out to serial monitor?

What does if(.096<salinity>.104)  evaluate (in plain english)?

@Juraj analogRead(5) selects the same ADC pin as analogRead(A5), which is the same as analogRead(19). (Even analogRead(13) will work). As it will subtract 14 if the value is bigger or equal to 14, and only use the lower 3 bits.

@Gerben, yes I remembered and deleted the comment (somehow wrong, because it is still there :-) )

I think the problem is not in the output pin (which you say works elsewhere) but in your calculations. I made a Minimal, Complete, and Verifiable example of the part of the code that does the calculations, testing every possible reading you might have got from analogRead(4) (mainly because I found the calculations code rather obscure). Here it is:
float salinity;
void setup()
  {
  Serial.begin(9600);
  }

void loop()
  {
  for (int analogS=0; analogS < 1024; analogS++)
    {
    Serial.print ("analogS = ");
    Serial.print (analogS);
    salinity = 2.0955*pow(10,-19)*pow(analogS,5.8106)*100.000;
    Serial.print (", Salinity = ");
    Serial.print (salinity);
    float target= (salinity-(salinity-.1)*.60);
    float numer=((((target)*.08585-(salinity)*.08585)/(.1-(.1*.15+salinity*.85)))*60.0);
    float denom= ((.1));
    float valve= ((numer/denom)/10.00);
    Serial.print(",  valve = ");
    Serial.println(valve);
    }
   Serial.flush ();
   exit (1);
  }

Testing that reveals:
analogS = 0, Salinity = 0.00,  valve = 3.64
analogS = 1, Salinity = 0.00,  valve = 3.64
analogS = 2, Salinity = 0.00,  valve = 3.64
analogS = 3, Salinity = 0.00,  valve = 3.64
... some lines omitted ...
analogS = 1016, Salinity = 6.21,  valve = 3.64
analogS = 1017, Salinity = 6.25,  valve = 3.64
analogS = 1018, Salinity = 6.28,  valve = 3.64
analogS = 1019, Salinity = 6.32,  valve = 3.64
analogS = 1020, Salinity = 6.35,  valve = 3.64
analogS = 1021, Salinity = 6.39,  valve = 3.64
analogS = 1022, Salinity = 6.43,  valve = 3.64
analogS = 1023, Salinity = 6.46,  valve = 3.64

As you can see, valve is always 3.64, so you will be doing this:
    digitalWrite(6,HIGH);
    delay(3);
    digitalWrite(6,LOW);

In other words, port 6 will be HIGH for 3 milliseconds, probably too short a time for you to notice. Ditto for port 5.

Also this doesn't do what I suspect you think it does:
if(.096<salinity>.104) {
    delay(5000);
}

That will evaluate .096 < salinity to be 0 or 1. Then it will evaluate:
0 > 0.104
1 > 0.104

This is not what you are intending, I think. Try:
if(salinity < .096 || salinity > .104) {
    delay(5000);
}

If that is what you mean, I can't be sure - maybe you mean the opposite:
if(salinity > .096 && salinity < .104) {
    delay(5000);
}

If you write things out clearly, without trying to do shortcuts, it will be much more obvious what the test really is.

When I first saw .096<salinity>.104 I thought it was a oscure new C++ feature, like a range validator operand. So neat: is salinity in this range? But no, ii means another thing. BTW, Java doesn't accept such expression, because it compares a boolean with a float. The problem with C/C++ is too much power for the unexperienced guy. Think of you trying to debug a program like these. C/C++ is full of traps.

I don't mean to demean the OP, whom is just a beginner, but the many C/C++ pitfalls.

I think Cobol used to work like that, however that is pretty old. :)


text:
just get my mkr1000 in macOS Sierra 10.13 and no way to connect
I have connected the device via USB, downloaded the latest version of Arduino IDE (1.8.5) installed (automatically offered) the drivers for the mkr, and there's nothing in the serial port selector besides the bluetooth. I've also installed the FTDI drivers but the same scenario.
What else can I try?
Error message:
Arduino: 1.8.5 (Mac OS X), Board: "Arduino/Genuino MKR1000"

Sketch uses 9624 bytes (3%) of program storage space. Maximum is 262144 bytes.
Couldn't find a Board on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload.

Seems like it is trying the bloutooth port
PORTS {/dev/cu.Bluetooth-Incoming-Port, /dev/tty.Bluetooth-Incoming-Port, } / {/dev/cu.Bluetooth-Incoming-Port, /dev/tty.Bluetooth-Incoming-Port, } => {}

UPDATE this is a system report screenshot:

Also the FTDI kext is loaded
sudo kextload /Library/Extensions/FTDIUSBSerialDriver.kext
kextstat | grep FTDI
  194    0 0xffffff7f85e62000 0x7000     0x7000     com.FTDI.driver.FTDIUSBSerialDriver (2.4.2) E16D9540-AF63-36AD-94C4-B1164FBD6078 <109 55 5 4 3 1>

Does plugging and unplugging the USB device cause any messages in the kernel debug messages to appear (dmesg -w, see https://discussions.apple.com/thread/4170078)?

007942.764202 Bluetooth USB Host Controller@14300000: IOUSBHostDevice::forcePowerGated: allowing power level to float
007942.764217 Bluetooth USB Host Controller@14300000: IOUSBHostDevice::forcePowerGated: kPowerStateSuspended completed with 0x00000000 after 0ms

the device is correctly listed in USB devices in settings

Which device is correctly listed? Can you edit your main question include logs and or a screenshot? Above messages indicate that you're seeing something about your Bluetooth controller? Or are those really the messages you get at the exact moment you plug/unplug the Arduino? (I'm trying to figure out here if the USB device is recognized at all, maybe your board is dead.)

@MaximilianGerhardt I've added a screenshot

So the MKR1000 gets listed somewhere in your Mac, but you cannot select it as a port in the Arduino IDE? Can you edit your question to include the output of ls /dev/. Also, maybe https://arduino.stackexchange.com/a/13825/30175 is relevant?

well ls /dev/ is a very long result, a lot of ttyuX devices, I've already tried with FTDI drivers also

After rebooting, have no idea why, the device is listed on the list and I'm able to use it


text:
My shield does not have further female headers? How do I stack more shields?
I purchased a motor shield (L293D) and it doesn't have the female header which I can connect to another shield. What can I do to stack up more shields?
For being more specific I ordered my shield from here:
https://www.amazon.in/Simple-Labs-SLAEX039-Shield-Arduino/dp/B00K2Z3GAE/ref=sr_1_1?ie=UTF8&qid=1518767182&sr=8-1&keywords=motor+shield+for+arduino+uno&dpID=41h0ag2SCgL&preST=_SX342_QL70_&dpSrc=srch
And please tell me how to do it because it is new for me. A guide or something?

Many shields cannot be stacked, even if you replace the headers. The biggest reason is that the shield uses most of, if not all, the available pins. Motor shield often fall into this category, so they don't add the pointless expense of stackable headers.
Before you consider stacking any shields, whether they have stackable headers or not, you first need to learn how the shields work and what pins they require to ensure there are no conflicts.


text:
Determine an earthquake intensity/magnitude level using ADXL345 and Arduino
I want to create a project using Arduino that monitor the Earthquake. I used an ADXL345 Accelerometer to detect if there is an earthquake. I used the Adafruit ADXL345 example to determine a acceleration of x-axis, y-axis and z-axis in terms of m/s^2. I want to used the Japan Meteorological Agency seismic intensity scale to determine the intensity level of the earthquake because it gives the Peak Ground Acceleration. If there is a way to determine the earthquake intensity level using ADXL345?

Also asked at https://stackoverflow.com/questions/48365221/accelerometer-using-adxl345-for-earthquake-detection (Jan 21, and already answered)

[Copied from https://stackoverflow.com/questions/48365221/accelerometer-using-adxl345-for-earthquake-detection]
That sensor is not suitable. It has 13 bit resolution at +-16g full range. That gives you a sensitivity of 0.002g for the lsb. In order to detect an earthquake directly below you, you need approx. a few milli-g (e.g. see here), even less for earthquakes with an epicentre elsewhere.
You want a sensor which is much more sensitive by a factor of 100 and probably with more resolution (better ADC), too.
(And you should have been able to do this quick google-search analysis yourself ;) )

Thanks for your answer but this is the one I brought on online store. But I can used it but I state that this sensor is not precisely detect magnitude.


text:
Using the physical serial port on a BSFrance LoRa32u4?
I can use the serial-over-USB channel by simply using Serial in my code.
The LoRa32u4 has an RXD1 and TXD1 pair on pins 20/21 (Arduino 0/1).

https://docs.bsfrance.fr/documentation/11296_LORA32U4/LoRa32u4_pinout_diagram.pdf
How do I configure and use this serial port (for receiving NMEA GPS)?

[ATmega32U4-based boards use] Serial1 to communicate via TTL (5V) serial on pins 0 (RX) and 1 (TX). Serial is reserved for USB CDC communication. For more information, refer to the Leonardo getting started page and hardware page.


text:
How to measure electrical conductivity using Arduino?
I want to measure TSS (Total soluble salt) in the soil. I have found in some literature that, through measuring of electrical conductivity, it is much easier to measure TSS. So, I thought, If I can measure electrical conductivity, it might be possible to find out TSS.
Logic behind the TSS is that, pure water is poor conductor of electric, increasing of soluble salt in water proportionately lift up the conductivity. So are there any sensors that readily measure conductivity? A point I also want to mention, can a voltmeter be useful for that?

imho, you would want to use RC timings over analogRead, which tends to be more precise. micros() is high-res and reliable, built-in ADCs are not.

Whats parameters or values change for get it working with esp32

The answer is Three Dollar EC - PPM Meter [Arduino]. I tried it against a consumer level EC meter and got the same results after calibration. It's cheap and simple.

The only warning is that there is several scales in use to measure EC, so results may not be comparable between diferentes devices and you have to read carefully the EC recomendations for your water solution.
EC units
Electrical conductivity can be expressed using a number of different units, but the typical unit is siemens per meter2 per mole (S/m2/mole) or millisiemens per centimetre (mS/cm). The mS/cm unit is generally used in Europe as a guide to the concentration of nutrients in water. In North America, conductivity is converted into a count of the ions in the water using parts per million (which can also be converted into units including mg/l etc.). This is done by converting the EC into a value based on the ions contained in the solution. Fortunately, there is a fixed calculation for the relationship between all these units, which is given in the table below.

Code for the EC meter
/*
  ElCheapo Arduino EC-PPM measurments

  This scrip uses a common USA two prong plug and a 47Kohm Resistor to measure the EC/PPM of a Aquaponics/Hydroponics Sytem.
  You could modift this code to Measure other liquids if you change the resitor and values at the top of the code.

  This Program will give you a temperature based feed controller. See Read me in download file for more info.

  28/8/2015  Michael Ratcliffe  Mike@MichaelRatcliffe.com

          This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .

    Parts:
    -Arduino - Uno/Mega
    -Standard American two prong plug
    -1 kohm resistor
    -DS18B20 Waterproof Temperature Sensor

    Limitations:
    -
    -

    See www.MichaelRatcliffe.com/Projects for a Pinout and user guide or consult the Zip you got this code from

*/

#include <OneWire.h>
#include <DallasTemperature.h>

//************************* User Defined Variables ********************************************************//

int R1= 1000;
int Ra=25;          //Resistance of powering Pins
int ECPin= A0;
int ECGround=A1;
int ECPower =A4;

//*********** Converting to ppm [Learn to use EC it is much better**************//
// Hana      [USA]        PPMconverion:   0.5
// Eutech    [EU]         PPMconversion:  0.64
// Tranchen  [Australia]  PPMconversion:  0.7
// Why didnt anyone standardise this?

float PPMconversion=0.5;

//*************Compensating for temperature ************************************//
// The value below will change depending on what chemical solution we are measuring
// 0.019 is generaly considered the standard for plant nutrients [google "Temperature compensation EC" for more info
float TemperatureCoef = 0.019; //this changes depending on what chemical we are measuring

//********************** Cell Constant For Ec Measurements *********************//
// Mine was around 2.9 with plugs being a standard size they should all be around the same
// But If you get bad readings you can use the calibration script and fluid to get a better estimate for K
float K=2.34;

//************ Temp Probe Related *********************************************//
#define ONE_WIRE_BUS 10          // Data wire For Temp Probe is plugged into pin 10 on the Arduino
const int TempProbePossitive =8;  //Temp Probe power connected to pin 9
const int TempProbeNegative=9;    //Temp Probe Negative connected to pin 8

//***************************** END Of Recomended User Inputs *****************************************************************//

OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.

float Temperature=10;
float EC=0;
float EC25 =0;
int   ppm =0;

float raw= 0;
float Vin= 5;
float Vdrop= 0;
float Rc= 0;
float buffer=0;

//*********************************Setup - runs Once and sets pins etc ******************************************************//
void setup()
{
    Serial.begin(9600);
    pinMode(TempProbeNegative , OUTPUT);  //seting ground pin as output for tmp probe
    digitalWrite(TempProbeNegative , LOW); //Seting it to ground so it can sink current
    pinMode(TempProbePossitive , OUTPUT); //ditto but for positive
    digitalWrite(TempProbePossitive , HIGH);
    pinMode(ECPin,INPUT);
    pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
    pinMode(ECGround,OUTPUT);//setting pin for sinking current
    digitalWrite(ECGround,LOW);//We can leave the ground connected permanantly

    delay(100);// gives sensor time to settle
    sensors.begin();
    delay(100);
    //** Adding Digital Pin Resistance to [25 ohm] to the static Resistor *********//
    // Consule Read-Me for Why, or just accept it as true
    R1=(R1+Ra);// Taking into acount Powering Pin Resitance

    Serial.println("ElCheapo Arduino EC-PPM measurments");
    Serial.println("By: Michael Ratcliffe  Mike@MichaelRatcliffe.com");
    Serial.println("Free software: you can redistribute it and/or modify it under GNU ");
    Serial.println("");
    Serial.println("Make sure Probe and Temp Sensor are in Solution and solution is well mixed");
    Serial.println("");
    Serial.println("Measurements at 5's Second intervals [Dont read Ec morre than once every 5 seconds]:");
}

void loop()
{
    GetEC();          //Calls Code to Go into GetEC() Loop [Below Main Loop] dont call this more that 1/5 hhz [once every five seconds] or you will polarise the water
    PrintReadings();  // Cals Print routine [below main loop]
    delay(5000);
}

void GetEC()
{
    sensors.requestTemperatures();          // Send the command to get temperatures
    Temperature=sensors.getTempCByIndex(0); //Stores Value in Variable
    //************Estimates Resistance of Liquid ****************//
    digitalWrite(ECPower,HIGH);
    raw= analogRead(ECPin);
    raw= analogRead(ECPin);// This is not a mistake, First reading will be low beause if charged a capacitor
    digitalWrite(ECPower,LOW);

    //***************** Converts to EC **************************//
    Vdrop= (Vin*raw) / 1024.0;
    Rc = (Vdrop*R1) / (Vin-Vdrop);
    Rc = Rc-Ra; //acounting for Digital Pin Resitance
    EC = 1000/ (Rc*K);

    //*************Compensating For Temperaure********************//
    EC25  =  EC / (1+ TemperatureCoef*(Temperature-25.0));
    ppm=(EC25)*(PPMconversion*1000);
}

//***This Loop Is called From Main Loop- Prints to serial usefull info ***//
void PrintReadings()
{
    Serial.print("Rc: ");
    Serial.print(Rc);
    Serial.print(" EC: ");
    Serial.print(EC25);
    Serial.print(" Simens  ");
    Serial.print(ppm);
    Serial.print(" ppm  ");
    Serial.print(Temperature);
    Serial.println(" *C ");
};

Code for calibration
/*
  ElCheapo Arduino EC-PPM measurments Calibration

  This Script is used for calibration of the sensor and fine tuning of the Cell Constant K
  Submerge the sensor and temperature probe in the calibration solution and leave for a while so the temperature probe can settle
  Change the value of the calibration solution to suit the solutiton strength
  Stir the probe to make sure the solution is well mixed and upload the code to the arduino
  Open the terminal for an update of the estimated Cell Constant K [should be around 3] and use this new value in the main EC code.

  28/8/2015  Michael Ratcliffe  Mike@MichaelRatcliffe.com

          This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .

    Parts:
    -Arduino - Uno/Mega
    -Standard American two prong plug
    -1 kohm resistor
    -DS18B20 Waterproof Temperature Sensor

    See www.MichaelRatcliffe.com/Projects for a Pinout and user guide or consult the Zip you got this code from

*/

//************************** Libraries Needed To Compile The Script [See Read me In Download] ***************//
// Both below Library are custom ones [ SEE READ ME In Downloaded Zip If You Dont Know how To install Use them or add a pull up resistor to the temp probe

#include <OneWire.h>
#include <DallasTemperature.h>

//************************* User Defined Variables ********************************************************//

float CalibrationEC = 0.762; //EC value of Calibration solution is s/cm

//##################################################################################
//-----------  Do not Replace R1 with a resistor lower than 300 ohms    ------------
//##################################################################################
int R1 = 1000;
int Ra = 25; //Resistance of powering Pins
int ECPin = A0;
int ECGround = A1;
int ECPower = A4;

//*************Compensating for temperature ************************************//
//The value below will change depending on what chemical solution we are measuring
//0.019 is generaly considered the standard for plant nutrients [google "Temperature compensation EC" for more info
float TemperatureCoef = 0.019; //this changes depending on what chemical we are measuring

//************ Temp Probe Related *********************************************//
#define ONE_WIRE_BUS 10          // Data wire For Temp Probe is plugged into pin 10 on the Arduino
const int TempProbePossitive = 8; //Temp Probe power connected to pin 9
const int TempProbeNegative = 9;  //Temp Probe Negative connected to pin 8

//***************************** END Of Recomended User Inputs *****************************************************************//

OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.

float TemperatureFinish = 0;
float TemperatureStart = 0;
float EC = 0;
int ppm = 0;

float raw = 0;
float Vin = 5;
float Vdrop = 0;
float Rc = 0;
float K = 0;
int i = 0;
float buffer = 0;

//*********************************Setup - runs Once and sets pins etc ******************************************************//
void setup()
{
    Serial.begin(9600);
    pinMode(TempProbeNegative , OUTPUT);  //seting ground pin as output for tmp probe
    digitalWrite(TempProbeNegative , LOW); //Seting it to ground so it can sink current
    pinMode(TempProbePossitive , OUTPUT); //ditto but for positive
    digitalWrite(TempProbePossitive , HIGH);
    pinMode(ECPin, INPUT);
    pinMode(ECPower, OUTPUT); //Setting pin for sourcing current
    pinMode(ECGround, OUTPUT); //setting pin for sinking current
    digitalWrite(ECGround, LOW); //We can leave the ground connected permanantly

    delay(100);// gives sensor time to settle
    sensors.begin();
    delay(100);
    //** Adding Digital Pin Resistance to [25 ohm] to the static Resistor *********//
    // Consule Read-Me for Why, or just accept it as true
    R1 = (R1 + Ra);

    Serial.println("ElCheapo Arduino EC-PPM measurments Calibration");
    Serial.println("By: Michael Ratcliffe  Mike@MichaelRatcliffe.com");
    Serial.println("Free software: you can redistribute it and/or modify it under GNU ");
    Serial.println("");
    Serial.println("Make sure Probe and Temp Sensor are in Solution and solution is well mixed");
    Serial.println("");
    Serial.println("Starting Calibration: Estimated Time 60 Seconds:");
};
//******************************************* End of Setup
//************************************* Main Loop - Runs Forever ***************************************************************//
//Moved Heavy Work To subroutines so you can call them from main loop without cluttering the main loop
void loop()
{
    i = 1;
    buffer = 0;
    sensors.requestTemperatures();// Send the command to get temperatures
    TemperatureStart = sensors.getTempCByIndex(0); //Stores Value in Variable

    //************Estimates Resistance of Liquid ****************//
    while(i <= 10) {
        digitalWrite(ECPower, HIGH);
        raw = analogRead(ECPin);
        raw = analogRead(ECPin); // This is not a mistake, First reading will be low
        digitalWrite(ECPower, LOW);
        buffer = buffer + raw;
        i++;
        delay(5000);
    };

    raw = (buffer / 10);

    sensors.requestTemperatures();// Send the command to get temperatures

    TemperatureFinish = sensors.getTempCByIndex(0); //Stores Value in Variable

    //*************Compensating For Temperaure********************//
    EC = CalibrationEC * (1 + (TemperatureCoef * (TemperatureFinish - 25.0))) ;

    //***************** Calculates R relating to Calibration fluid **************************//
    Vdrop = (((Vin) * (raw)) / 1024.0);

    Rc = (Vdrop * R1) / (Vin - Vdrop);

    Rc = Rc - Ra;

    K = 1000 / (Rc * EC);

    Serial.print("Calibration Fluid EC: ");

    Serial.print(CalibrationEC);

    Serial.print(" S  ");  //add units here

    Serial.print("Cell Constant K");

    Serial.print(K);

    if(TemperatureStart == TemperatureFinish) {
        Serial.println("  Results are Trustworthy");
        Serial.println("  Safe To Use Above Cell Constant in Main EC code");

    } else {
        Serial.println("  Error -Wait For Temperature To settle");
        Serial.print("Temp start=");
        Serial.print(TemperatureStart);
        Serial.print(" Temp end=");
        Serial.println(TemperatureFinish);
    }
}
//*************************** End Of Main Loop *******************************************************************//

EDIT:
Make sure to use a factory sealed male plug. If water get inside the plug, the voltage reading will be inaccurate.

Just be sure that some plonker doesn't plug it into the mains... ;)

re-using mains connectors is a bad idea; human factors.

That should be possible  ... connect +5V to one end, an analog input pin on the other, don't forget a resistor which is high enough not to get more current than allowed. Than measure on the analog input pin the conductivity (value) and act on it.
Afaik the max amperage for an analog pin is 20 mA if I remember correctly. Thus a resistor of V = I * R <=> 5 = 0.02 * R <=> R = 5 / 0.02 = 250 ohm should be ok. This will only occur if the conductivity is 100%. If you get a very low conductivity than you will get very low numbers when reading the analog pin. When you get too less values, you have to lower the resistor value, but you risk of burning a pin when too much current gets across.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Is there a sensor to measure a distance between 2 point as in range [0-2 meter]?
I'm looking for a way of detecting if 2 pieces of hardware are within 2 meters of eachother or not. The idea is to build a prototype to lock computers automatically. I just need a recommendation on the sensor if it exists. Geofencing, bluetooth etc are not reliable enough.

Just point a ultrasonic sensor towards the chair in front of the PC. Or add a force sensor to the chair.

i would try an ultrasonic emitter for the wrist, like those "mosquito repelling" things, along with a sensitive mic on the other end. Audio fades very reliably at distance; twice as far is 25% as loud, and the dead-simple "buzzer" can be very low power compared to more complicated emitters.

You can use a lot of different methods with advantages/disadvantages:

Use an IR LED/receiver and calculate the distance of travelling of the lights. Disadvantage: you need a very precise timing mechanism (light is fast), also take latency into account for non-light parts, and hardware needs to be in visible range and pointing to each other with LEDs)
Use an ultrasonic sensor like SR-HC04. Disadvantage: devices must point to each other in a small precise angle.
Using an RF method and sending/receiving e.g. via nRF24L01+ 2.4 GHz trasnceivers, to check the difference in time between sending and receiving when very close or a few meters apart. However, there might be aspects that might distort the result (other receivers/transmitters, what kind of material is in between, nRF antenna placement/direction etc). Using lowest speed (most reliable), highest power.

I was thinking more of a bracelet like design, which will not work with both of these sensors. What are they using in these ankle bracelets for criminals? ;)

"What are they using in these ankle bracelets for criminals?" GPS

I doubt they will use GPS, since you don't have GPS in house and you can cover/circumvent GPS signals easily. So my bet is a signal that is sent and received and a time difference (travel) time is performed calculating distance.

no need to monitor a position of the bracelet in the house

It seems you are partly right, GPS + other mechanisms (sending to fixed location): https://en.wikipedia.org/wiki/Ankle_monitor   ... however, a device at a fixed location does not really help answering the question itself.

Yes to specify: I try to solve the "user forgets to lock the computer" problem with a hardware prototype. For fun.

I would do some tests starting with nRF24L01+ 2.4 GHz (if you have them) and check if you notice a difference in sending time and receiving time when very close or a few meters apart. However, there might be aspects that might distort the result (other receivers/transmitters, what kind of material is in between, nRF antenna placement/direction etc). Using lowest speed (most reliable), highest power.