text:
Extend battery life with a power-controlling microcontroller?
This article describes a method to extend the battery life: use a low-power controller to switch on the Arduino only when needed. The author states that this method uses considerably less power than using Arduino's sleep mode.
Are there downsides to this approach? Which variant should I build?(The TPS61240 variant seems to use something from Circuits@Home that's not available anymore.) I'd appreciate schematics or links to detailed instructions.
Background: I'm building a sensor device that's in an environment with no mains power supply. The sensor should wake up eg. hourly, read eg. a temperature sensor, possibly send an SMS and then go back to sleep.

seems a bit overkill to use a microcontroller for that task.

Switching off power to the board only makes sense if you're using a full Arduino. Once you strip the Arduino down to the bare MCU and decoupling capacitors (or start with a basic breakout board instead), disabling unused peripherals and sleeping the CPU has much more of an effect since you no longer need to supply power to an external monitor chip.
Naturally this may involve creating your own board for the MCU. Fortunately Atmel has the basics of that covered.

Thanks for the answer. Some reasons why I thought that using an external power controller would be more simple: 1) I could use off-the-shelf Arduino board and a GSM shield. The GSM shields need momentarily a lot of current (2A), and I didn't research yet whether it would be easy to completely switch off the GSM shield from Arduino. 2) I'm not sure whether the GSM shields are compatible with OSCCAL and clock_div_4 optimizations. 3) I couldn't easily find what the sleep consumption would be with a stripped down Arduino. Could you help me with these points?

A PMOSFET can handle powering down the GSM module completely if required. Clock prescaling can be set to 1 while communicating with the module, and tuning OSCCAL is completely optional. The datasheet for the MCU talks about current usage in the appropriate "Electrical Characteristics" and "Typical Characteristics" section.

There's a good chance the GSM module already has power conserving modes of its own, though perhaps those aren't readily exposed by whatever interface is used.


text:
Resistance in Switch (negative vs positive logic)

I tried in my Arduino the negative logic to get a digital input from a switch (with 10 KΩ resistance). If I want to use the positive logic what kind of resitance I have to use? For me seems that 10KOhm it to big and probably a smaller resistor should be used. How do we compute the value of the resistor? The schemes of Negative and Positive Logic from Valvano's notes/ebook - University of Texas gives 10 kΩ in both cases. Is it correct?

From a pure electronics viewpoint, there is no real difference between both circuits, the difference will be handled by your code running on the MCU, as a close switch will either be HIGH or LOW depending on the logic you used to wire your switch.
The resistor must be present for 2 reasons:

to avoid producing a shortcut between +5V and GND when the switch is closed, without it the shortcut would probably damage your power supply circuitry (if both pins are directly taken from Arduino, that would mean damaging Arduino supply circuits)
to make the voltage pin attached to the pin the "winner" of both voltage pins when the switch is closed, ie that pin will provide the level to Arduino input pin

The value of the resistor should  be:

high enough to limit the current between +5V and GND when the switch is closed, preventing damage and limiting overall power consumption of your circuit
not too high to allow providing a voltage level to the input pin

Using 10k means that, applying Ohm's law, when closing the switch, a 0.5mA current would flow from +5V to GND, which is generally acceptable in terms of consumption and cwill not damage your power supply.
Note that the input pin is "high impedance" which means it has no voltage level if not connected to anything, and it does not supply or sink any current (or more accurqtely a negligible current only).
Finally, it is good to know that Arduino MCU offers the INPUT_PULLUP mode for digital pins, where an internal resistor pulls up the pin input to 5V.  This enables you to directly connect your switch between the pin and GND. So you just have to code:
pinMode(XXX, INPUT_PULLUP);

instead of:
pinMode(XXX, INPUT);

For information, according to ATmega328P datasheet (the MCU of Arduino UNO), those internal pullup resistors have a value between 20k and 50k.

thanks a lot . As I understood the INPUT_PULLUP is a ~50kΩ embedded resistance (in ATmega328P chip) that protects the digital input. For example if you connect directly the +4 Volt to a digital input the chip is already protected.. right?
So the 10 kΩ resistance is just a protection of the shortcut between +5V and GND.
Here stackexange - electronics Q says that digitalWrite(13, HIGH); Turns internal pull-up on and digitalWrite(13, LOW);  Turns internal pull-up off.

Maybe this way of turning internal pull-up on/off works but this is not the recommended way; the preferred (and official) way is just pinMode(13, INPUT_PULLUP);

INPUT_PULLUP requires 1.0.1 of the IDE.  The documentation states that prior to that release the digitalWrite HIGH/LOW mechansim was used.

Who's still using pre-1.0.1 of Arduino IDE? For those people, maybe it is time to upgrade.

source: Stack Exchange

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

sort: votes


text:
Temperature sensors TMP36 and LM35 have temperature diff. (offset) in the same circuit
I am trying to use the two temperature sensors TMP36 (from Sparkfun Inventor's kit) and KEYES LM35.
In read TMP36 Sensor and I convert the result to Celsius using the following code:
// TMP36 input sensor -> degrees Celsius calculation
TM36reading = analogRead(TM36sensor);
TM36voltage = (TM36reading/1024.0)*5.0;
//converting from 10mv per degree with 500 mV offset
//             (TMP36 voltage - 500mV) times 100)
TM36degreesC = (TM36voltage - 0.5) * 100;

In read LM35 Sensor and I convert the result to Celsius using the following code:
// LM35 input sensor -> degrees Celsius calculation
LM35reading=analogRead(LM35sensor);    // reads the LM35 output
LM35voltage = (LM35reading/1024.0)*5.0;
LM35degreesC=LM35voltage*100.0;

I have connected also a LCD display to monitor visually the values of these two sensors. Here is my full code. I use also a serial log. Here is a sample from this serial log (as you can see there is a difference/offset between 0.5 to 0.9 Celsius).
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.89, LM35: 16.11 diff -> 0.78
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.87, LM35: 16.60 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 17.09 diff -> 0.20
TM36: 17.38, LM35: 17.09 diff -> 0.29
mean difference between sensors: 0.48
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.41, LM35: 17.58 diff -> 1.17
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 17.09 diff -> 0.20
mean difference between sensors: 0.71
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 17.09 diff -> 0.29
TM36: 16.89, LM35: 16.11 diff -> 0.78
mean difference between sensors: 0.93

I power the Arduino from the computer using the USB cable. When the computer is ON we have the offset that I already demonstrated above. When the computer is turned off (after computer shutdown), immediately the sensor of TMP36 falls around 1 Celsius.. And then both sensors have similar temperature.

Why there is this temperature difference between TMP36 and LM35 sensors? How can we "fine tune" these sensors to monitor the real temperature?

Not sure if this applies (I'm a total newbie to Arduino), but this link (https://learn.adafruit.com/tmp36-temperature-sensor) has a section at the bottom called "Problems you may encounter with multiple sensors".  Might be something to review and see if it applies to your case.

The sensors have different accuracy, according to their datasheets.
The TMP36 has ±2°C typical accuracy, while the the LM35 has 0.5°C typical accuracy (over 25°C).
Read the datasheet carefully and pay attention to the characteristics, more specifically to the accuracy error graphs for each sensor. At your measured temperature (~17°C), you should expect the following error (the red line is not super accurate, but should give a general clue):
LM35:

TMP36:

In addition, as Michal stated, you might have noise in your circuit, and you are not connecting the TMP36 as per the datasheet suggests (note the capacitor between +V and Ground):

Thanks for the detailed charts.. I will try to use the 100nF Capacitor next days (I have to buy one first).

That's good, and might help a bit, as long as you understand that you will still see differences between the two sensors because of different characteristics.

There are many things, first different sensors have different accuracy or they may not have been calibrated from the factory. In addition both are analog and analog reading is susceptible to noise. My guess is there is a high frequency noise on power line coming from the computer interfering with your readings. Try putting a small (100nF) capacitor between AREF and GND pin. You can always just take median of the measured values as the actual temperature.

I read here that Arduino Mega already has a capacitor 100nF connected between AREF and GND. I will try to buy next days a 100nF and try to see if the noise is filtered in that way. Thanks.

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


text:
Super slow serial (UART) communication on Arduino
I am using this device for my Arduino that connects to the OBD-II port of my car to get various information such as speed, rpm, etc. I am using this for a digital Nixie tube speedometer using the smart Nixie tube from a Kickstarter project.
I pass the information to the Nixie tubes through serial and get information from the OBD-II through serial as well. I am getting speed updates about every 20 seconds and that is incredibly slow when the device can supposedly update up to 100 times per second.
I originally was using an Arduino Uno and using software serial for the tubes, but I figured the slowdown was due to interupts interfering with the hardware serial, so I switched to the Arduino Mega 2560 to use a second hardware serial pin to hopefully fix the problem, yet the same issue is occurring.
Here is my code... There must be something I'm doing wrong. Serial2 is for the Nixie tubes.
#import <Arduino.h>

#include <OBD.h>

int ones = 0;
int tens = 0;

int kphValue = 0;
int mphValue = 0;

int rpmValue = 0;

String onesString;
String tensString;
String payloadString;
String rpmString;
COBD obd;

void setup(){
    Serial2.begin(9600);
    obd.begin();

    //Initiate OBD-II connection until success
    while (!obd.init()){
        Serial2.print("$0,Y,Y,255,255,000,000$0,Y,Y,255,255,000,000!");
        delay(1000);
        Serial2.print("$0,Y,Y,000,000,000,000$0,Y,Y,000,000,000,000!");
        delay(1000);
    }
}

void loop(){
    onesString = String(ones);
    tensString = String(tens);
    payloadString;
    rpmString;

    if(obd.read(PID_RPM, rpmValue)){
        if (rpmValue < 3000){
            rpmString =",N,N,255,000,255,000";
        }
        else if (rpmValue >= 5000){
            rpmString = ",N,N,255,255,000,000";
        }
        else if (rpmValue >= 3000){
            rpmString = ",N,N,255,255,030,000";
        }
    }

    if (obd.read(PID_SPEED, kphValue)){
        kphToMPH();
        payloadString = "$" + onesString + rpmString + "$" + tensString + "rpmString" + "!";
        Serial2.print(payloadString);
    }
}

void splitDigits(int input_number)
{
    ones = (input_number%10);
    tens = ((input_number/10)%10);
}

void kphToMPH()
{
    mphValue = kphValue * 0.621371;
    splitDigits(mphValue);
}

EDIT:
I am using the following library: https://github.com/stanleyhuangyc/ArduinoOBD

The call to Serial2.available() looks suspicious, what happens if you remove it? That calls checks for incoming data, not that it's OK to send data.

I will edit that out.  I added that to see if it would help because without it I'm still getting slow responses.

The read is a relatively high baud rate.

the statement payloadString; doesn't do anything useful

Thank you.  I was changing things around and probably forgot to fix that.

Do the example sketches that come with the library also perform slowly? If so the slowdown might just be the ECU not sending data very fast.

Would having matching baud rates for each device help as well?
So my nixie tubes would have the same baud rate as the OBDII adapter

Which ODB library are you using? http://sourceforge.net/projects/obdcon/files/ ? https://github.com/stanleyhuangyc/ArduinoOBD ? Something else?

Project was scrapped but for the possibility of helping someone else I was using the github project.  I'll edit the question to reflect the library I was using and the device.

I think the problem is not so much in the update speed, but in the fact that you loose accuracy in your calculation. The following lines are the culprit:
int kphValue = 0;  // [-32768:32767]
int mphValue = 0;
mphValue = kphValue * 0.621371;

Make sure the calculation will be entirely in integers to prevent calculation errors:
uint16_t kphValue = 0;  // [0:65535]
uint16_t mphValue = 0;
mphValue = ( kphValue * 621 ) / 1000;

This limits kphValue to just over 100, if you want to go higher than that there are two option:

multiply by 62 and divide by 100;
use longer integers int32_t [-2147483648:2147483647], which comes with enough room for multiplying by 621371 and dividing by 1000000, but will perform slower and with a larger memory footprint. Do you really need that accuracy?

Not sure if the first part is correct, while I normally wouldn't write it that way I'd expect kphValue would be converted to a double for the calculation phase. Just gave it a quick try on a PC C++ compiler and result was 621 for an input of 1000.

@Blup1980 where do you see floating point numbers in my answer?

True @Blup1980, I didn't think of that one.

try this:
#import <Arduino.h>
#include <OBD.h>

int kphValue = 0;
int rpmValue = 0;

COBD obd;

//array of character arrays, see http://arduino.cc/en/Reference/string
const char* rpmStrings[] = {    ",N,N,255,000,255,000",
                                ",N,N,255,255,030,000",
                                ",N,N,255,255,000,000" };

void setup(){
    Serial2.begin(9600);
    obd.begin();

    //Initiate OBD-II connection until success
    while ( !obd.init() ) {
        Serial2.print("$0,Y,Y,255,255,000,000$0,Y,Y,255,255,000,000!");
        delay(1000);
        Serial2.print("$0,Y,Y,000,000,000,000$0,Y,Y,000,000,000,000!");
        delay(1000);
    }
}

void loop() {
    if ( obd.read(PID_RPM, rpmValue) && obd.read(PID_SPEED, kphValue) )
    {
        int rpmStringIndex = determineRpmIndex(rpmValue);
        int mphValue = kphToMPH(kphValue);

        //payloadString = "$" + onesString + rpmString + "$" + tensString + "rpmString" + "!";
        //using Arduino String objects is generally not a good idea due to memory constraints
        //it's probably ok, but I'd rather use character arrays and/or print a bit at a time rather than trying to assemble a giant string
        Serial2.print("$");
        Serial2.print(mphValue % 10); //ones
        Serial2.print(rpmStrings[rpmStringIndex]);
        Serial2.print("$");
        Serial2.print(mphValue / 10); //tens - integer division, don't need modulo

        //do you really want to append the string "rpmString!" or did you want the contents of the variabe rmpString+"!" ?
        //I'm pretty sure you meant the latter
        Serial2.print(rpmStrings[rpmStringIndex]);
        Serial2.print("!");
    }
    else
    {
        //obd read error
        //add debugging output here to see if obd failed to respond correctly/on time
    }
}

int kphToMph( int kphValue ) {
    //return a value rather than updating a global variable
    return ( int ) ( kphValue * 0.621371 );
}

int determineRpmIndex( int rpmValue ) {
    if ( rpmValue >= 5000 )
        return 2;

    if ( rpmValue >= 3000 )
        return 1;

    return 0;
}

Looks good and learned a lot... I will upload when I get a chance and let you know!

I was found solution with
Serial.setTimeout(100);
Like this (https://www.arduino.cc/en/Serial/SetTimeout) setTimeout was 1000ms default.
the check serial port per 1000ms.
I referenced this https://stackoverflow.com/a/28892086/929740


text:
Problems using HC-SR04 with LED displays
I'm having problems using an HC-SR04 ultrasonic sensor in conjunction with an LED display module. The sensor appears to work fine when outputting values to the serial monitor, measuring distances up to the rated maximum of around 3m. However when I connect the display module the maximum distance displayed drops to about 50 or 60cm.
I've tried both a TM1637 four-digit seven-segment display module using the TM1637Display library and a Max7219 eight-digit seven-segment display using the LedControl library. Using the NewPing library's ping_cm() function for distance measurement instead of the pulseIn() function makes no difference.
I'm tending to think it's either something in the LED module libraries that interferes with the measurement of pulses, or possibly noise and ripple on the power supply.
I tried twisting the longer power and data wires together. I've also added a 0.1uF ceramic capacitor across the power connections to the ultrasonic sensor and a 0.1uF ceramic and 2.2uF electrolytic capacitor across the power rails at the point of connection to the display module. This appeared to improve the reliability of the Max display, which previously showed a garbled display from time to time, but didn't make any difference to the range problem.
I've tried powering the Arduino with a 9V wall adapter and well as the USB supply from my PC. This makes no difference. As far as I can trust my multimeter, the supply voltage to the sensor is adequate; between 5.02V and 4.95V depending on the distance the sensor is measuring (the voltage reduces slightly when sensing longer distance). Unfortunately I don't have access to an oscilloscope so I can't see what's happening at a higher frequency. I had hoped the electrolytic capacitor would help smooth out voltage fluctuations.

My current work-around is to disable the display while the sensor measures distance. With the LedControl library, I can do this immediately before reading the pulse duration. With the the TM1637Display library I found I had to clear the display before triggering the sensor. In both cases, the display will then show the correct distance but flickers in proportion to the measurement distance (the longer the distance the longer pulseIn() has to wait for the echo).
#include <TM1637Display.h>

// Module connection pins (Digital Pins)
#define CLK 7
#define DIO 6
#define ECHO 5
#define TRIG 4

TM1637Display display(CLK, DIO);

void setup(){
  pinMode(TRIG, OUTPUT);
  pinMode (ECHO, INPUT);
  display.setBrightness(7, true);
}

void loop(){
  long duration; // duration in us
  long distance; // distance in cm

  display.clear();
  // This is the workaround described above; without this line
  // the sensor cannot measure any more than about 50 or 60cm.
  // With this line, the sensor measures up to about 3m but
  // obviously the display flickers every time around the loop.

  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  duration = pulseIn(ECHO, HIGH, 20000);
  // a 20ms (20000us) timeout corresponds to the maximum sensor range (3.4m approx)

  // Since the speed of sound is approx 340m/s, i.e. roughly 29 us/cm
  // we can divide duration (us) by 29 and again by 2 (pulse travels
  // out and back) to obtain a distance from sensor in cm:
  distance = duration / 29 / 2;

  display.showNumberDec(distance, false); // true shows leading zeros
  delay(250);
}

Any suggestions?

try commenting out display.clear()

Please check the voltage drop across HC-SR04, anything below 4.5v would provide inaccurate readings.

@jsotola: the display.clear() is the only way I can actually get a decent reading (code commented to clarify). @arcube: I've measured the voltage to be between about 4.9V and 5.0V (paragraph on voltage measurement added).

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


text:
avrdude: stk500_getsync(): not in sync: resp=0x00
I have arduino pro mini 5V, 16M ATMega328 and CP2102 USB to TTL. I've wired them like this:

When I try to upload a sketch to the arduino board I'm getting the following error:
avrdude: stk500_getsync(): not in sync: resp=0x00

The board type and the serial port are correct. The sketch also compiles successfully and I've installed the CP2102 drivers. I've noticed that even if I unplug all wires from the arduino board(and just leave the cp2102 connected to the PC), I'm getting the same error again. I'm using Windows 7.
Anyone else encountered the same issue?

@nidhin Yes, it appears http://i.imgur.com/JHaDWbt.png

@nidhin
I tried to press the reset button at the same time as I clicked the upload button. Also I tried to wire the rst pin on the cp2102 to both rst pins on arduino, none worked.

possible duplicate of Some dude named avr won't let me upload my program, aka "avrdude: stk500_getsync(): not in sync: resp=0x00"

You should check that your baudrate matches the bootloader on the board (there is one, right? is that a genuine board or a clone?).  Also, disconnect the arduino and wire the CP2102's TXD and RXD pins together.  Open the arduino serial monitor and type characters; you should either see one copy of what you type with the pins jumpered and none with them open, or else two copies with the pins jumpered and only one with them open.

I had the same error message come up when I had shorted the digital inputs. oops!

It's hard to tell from your pictures, but are all the header pins soldered to the boards? If not, they need to be: there's no chance that the proper electrical connections will be made reliably if they're just inserted loosely into the holes.

Good spot, I did not see that on the picture at first, but it seems you are right, it looks like pin headers have just been inserted into the holes without any soldering.

This error means that the program responsible for uploading (avrdude) can not communicate with your arduino.
Did you reset the board just before programming? The reset pin of the arduino seems unconnected in your picture; so the board wouldn't be executing the bootloader when the serial cables expects it to.
Try either to reset the board manually just before programming, or connect the rst pin.

I tried to press the reset button at the same time as I clicked the upload button. Also I tried to wire the rst pin on the cp2102 to both rst pins on arduino, none worked.

Not simultaneously -- you must first do the hardware reset, then try the upload.

Sometimes it works better with a capacitor in series with the reset pin. I'd start around 0.1µF and try a few different values (it depends on the value of the reset pullup)

@NicolasD Is there a way I can do it without capacitor? I think the arduino is not even connecting to the cp2102, but I don't know how to check. I also tried reseting the board(with the button on it) few seconds before uploading, still getting same error.

As @DaveTweed said, you can reset the board, say, half a second before clicking the "upload" button in arduino IDE. The capacitor is just for autmating this.

BTW, Did you use that arduino board already?

I know someone with a similar problem. But his problem is solved with a 1k resistor on both Tx and Rx in series and a 10uF capacitor which is required for arduino devices using the ATmega328 between the reset pin and ground. You could also try a PULLUP resistor on the reset. Which will mean a 10k resistor between the reset and +5V

I solved this problem by connecting DTR signal from USB-converter to the pin which says GRN on the board (the one aside TXD). It was not obvious to find, but seen on ebay some arduino-dedicated-usb-programmer which seemed to be connected this way - so I took the chance. I do not get this error anymore and uploading works every time!!!
Cheers!

As some of the other answers have said, you may not have soldered on the header pins. You can't just push them into place and hope for the best. See my Pro Mini:

My soldering is reasonably neat, however you can see the solder come through to the other side.
Also see:

Some dude named avr won't let me upload my program, aka “avrdude: stk500_getsync(): not in sync: resp=0x00”
Have I bricked my Arduino Uno? .

A lot of the issues in those threads apply to any Arduino.

To solve my sync issue I added a connection from USB serial adapter RST to ProMini DTR pin. I'm using Linux Mint 18 OS with Arduino IDE 1.8.5 -
My other Arduino clones (UNO_r3 and Nano) uses the CH340G chip so I knew I had working drivers. Sorry for the picture quality, my old camera and I don't know how to balance LED light bulbs. The pins from USB to ProMini are: (U)GND-(P)GND; (U)3V3-(P)no connection; (U)5V-(P)VCC; (U)TX-(P)TX; (U)RX-(P)RX; (U)RST-(P)DTR.  Hope this helps. 73 AB1OP_Ralph

I had the exact same problem. I tried installing the IDE on another laptop and uploaded the program from that laptop. Problem solved. Then I came back to my laptop, uninstalled the IDE and re-installed it. It works.
However, I wasn't satisfied because I can't find the source of the problem... so I tried running everything again the same exact way.. I found the problem but am not sure if that can be the actual cause of it.
In my project, I needed to carry out serial communication between Arduino and MATLAB (GUI). In order to see/verify the output(type) of MATLAB (GUI) serial data, I used HYPERTERMINAL and also VIRTUAL SERIAL PORT EMULATOR. I noticed that every time hyperterminal is running or VSPE is running while my serial monitor is on, it screws up the uploading feature of the program. I'm not sure if it's because of the VSPE or HYPERTERMINAL, but reinstalling the IDE worked for me. :-)

I spent hours looking for a solution to  the same error message. Everything was correct - Board chosen, COM port, everything.
I switched my TX and RX pins, and connected the tx and rx to each other, instead of them being switched (which I saw from a tutorial).
Then I pressed the manual reset, held it down, and uploaded, then released while it read Uploading. It worked.
Hope this helps.

This has happpened to me as well. I had a bluetooth/TTL unit wired to RX/TX, which are the same ports used by the usb connection to the computer (where transfer of the program happens), and all I had to do was disconnect RX to the BT unit when transferring the program.

{linux}
The solution for me was to set the correct USB port.
I had been previously working with my Uno on USB0.
I could not upload to my nano as I had it connected on USB1
In menu: Serial Port -> /dev/ttyUSB1

Its logical to change a port when you change a board.

This problem is caused by using the wrong USB cable. I have three cables, two of which work find, and one of which has this issue. The cables with the ferrite bead around them will work. The one cable that I have which works has a braided shield surrounding the conductors, and it is about 2 feet long. I have a 3 foot cable with no bead and no shield that exhibits this issue.

This is a possibility but it's a bit of a leap to assert that it is the cause.  Typically, as the USB interface is a lot more "delicate" than the serial downstream of it, in a bad cabling situation the USB serial device would fail to enumerate rather than enumerate and stay present but fail to proxy serial data.

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


text:
Arduino Uno and ESP01: can't issue AT commands [Solved]
I would like to connect an Arduino Uno and an ESP 01 module. I use the Arduino IDE and I tried to test communication via serial monitor. I get the "ready" message from the ESP 01, but I am not able to issue AT commands from the serial monitor. It only displays random characters on the console.
It seems that no newline character is issued, because if I try to insert commands, they are inserted next to previous characters. I use "Both NL & CR" and 115200 baud settings in Arduino IDE. I tried 9600 baud too, but then the text is unreadable.
I used the following pins on my ESP-01:
Vcc -> 3,3V
Gnd -> Gnd
Rx  -> Tx(pin 0) of my Arduino, used voltage divider to make it 3.3V.
Tx  -> Rx(pin 1) of Arduino
CH_PD -> 3.3V

Please see serial monitor screenshot:

EDIT: PROBLEM RESOLVED:
My Arduino is connected to my PC via USB, so I changed pins for communication with the ESP by SoftwareSerial to pins 10 and 11. Now it works. Thank you.

Just to have an answer instead of just an edit/addition to the question:

EDIT: PROBLEM RESOLVED:
My Arduino is connected to my PC via USB, so I changed pins for communication with the ESP by SoftwareSerial to pins 10 and 11. Now it works. Thank you.

Ok... sure... your Uno's Atmega384 was talking with pins 0 and 1 to the USB adaper chip (Atmega16u2 on Uno R3) and at the same time to the ESP-01.
Read the fine schematic: Arduino Uno R3

It could be the case, that the Arduino power supply is insufficient.
"[...] note that the Arduino 3.3V regulated output (50 mA max) can't drive the current requested by the ESP (Up to 200 mA). Some tutorials on the Internet use the Arduino 3.3V to power the ESP, but it didn't worked for me. I'm using an external power supply (An old 5V Android charger)."Source
Possible, that the power consumption was within range when the readable text was printed and too high when all the unreadable stuff was sent.

Tried to use power supply with 3,3V / up to 1A and now and received only random characters instead of "ready"message :(

Also, I inserted power source directly to Vcc pin of ESP, didnt uset any kind of diode/stabilizator etc, this could problem maybe?

Also, my voltage divider is: 3300 Ohm and 6600 Ohm, not sure if this is ok :x


text:
5V 10A 4 channel relay to 2 lights15W light in series in 220V AC supply
I am trying to setup my first relay module with live environment. I have attached the relay module image below.

Which I am using to control 4 devices in my switch board as follows:

Fan (working fine),
6w celling LED panel (2 connected in series) (Working fine)
15w celling LED panel (2 connected in series) (Sometimes work sometimes don't)
Spotlights 3 lights in series and some LED strips connected to it (Sometimes works sometimes don't.).

I have cut one wire which is connected to main normal mechanical switch WHICH IS NOT A HOT WIRE its just the another wire connected to the button.
But I am not sure why its not working? Do I need to connect neutral to the another end of the relay. As I have only 2 wires connected to the relay for each of the switches. Here is a screenshot of specifications 15watt LED panel which is connected to my house, if this can help to understand better.

If I connect Neutral on the first pin of relay and when I close the relay switch, do the current will go into the neutral wire as well?
If I keep my 3w spotlights ON or more then 3-4 hours and try to close the relay on connected to it. The relay LED light for that connected relay goes OFF but the light don't. Seems like the mechanical relay is not getting enough power to move the mechanical relay off.
I want to know why this is happening? And how can I solve this issue? Attaching a neutral (earth) wire will help to reduce this? But if connect neutral to first (off side of relay) pin, then will get the current?
Any suggestions will be helpful. Also I added 3.3v from NodeMCU to VCC (instead of jumper) pin. But that is also not helpful.

NodeMCU don't have 5V pin. I have only 3.3v pins. do I have to connect to any buck converter? @Juraj

How are you powering the nodemcu? The relay needs 5V minimum (72mA current per relay, by the way, so that's 288mA you'll need just for the relays) I mean, the clue is in the name ... they are 5V relays

@JaromandaX I am powering it with mobile charge which is 5v

But as much as I understand nodemcu step down the voltage to each upto esp8266 as esp8266 need 3v.

the Vin pin will be 5V

This "question" is vague and confused - I would STRONGLY ADVISE that you you do not attempt to connect to mains power - there is a danger of electrocution. No electrician would even consider connecting neutral to a relay (or any kind of switch).

2 connected in series; I hope you mean parallel here. You can't really put mains devices in series.

so my revised comment based on schematics in MatsK's answer. remove the VCC/JD-VCC jumper and wire JD-VCC to 5 V (Vin) pin of NodeMcu. it will power the coils with 5 V from USB and work with 3.3 V io pin wired to InX

@Gerben yes the two lights turn ON and OFF together.

@Milliways yes I thought so too. As I am not from electronics background. So I am not much aware to these things. Thats why I am not taking any risk and asking for help here. :)

@JaromandaX I thought VIN pin is used for voltage input, not for output. I may be wrong. I will clarify it once again to brush up the basic concepts.

about Vin on NodeMcu https://arduino.stackexchange.com/questions/51873/nodemcu-vin-pin-as-5v-output

@Juraj Amazing help! It helped to understand the basic concept.

You need to connect Vin from NodeMCU (Raw 5V from USB) to Vcc on the relay board.
And as stated in the comments, the relay need 5V for operating reliable.
In has the same problem, two LEDs and a resistor. To enhance it would be to replace the indicator LED (DS1-4) with a wire.
2 x LEDS á ~1.8V and a resistor á ~1.4V = 5 Volt.
1 x LED á ~1.8V and a resistor á ~1.4V = 3.2 Volt.

but if the JD-VCC is not connected with VCC and JD-VCC is 5 V and VCC is 3.3 V then it will work wit 3.3 V io pin without modification? I am a programmer and not good in electronics, but it is how I read this circuit.

One of the purpose with JD-VCC is to be able to have a optical isolation between "In" and the relay circuit and another is that you can have one PSU that feed the relays.

So do you think any step up (3.3v to 5v) buck converter can solve the problem?

Yes as long as it can supply ~300mA . The relay spec say that a 5V relay consume ~70mA . Ref datasheet https://www.mycomkits.com/reference/Songle_SRD(T73)_Relay.pdf

@user3201500, you can take 5 V from Vin https://arduino.stackexchange.com/questions/51873/nodemcu-vin-pin-as-5v-output

@MatsK I hope this will help me. I am not trying this right away. As I have to open my switch board screws. But I am sure this will be a great help. And most probably this will solve the problem too.

@MatsK, why do you recommend to remove the indicator LED?

If you remove or shorten the LED then you can drive the in with a 1.8 volt lower voltage, 5V - 1.8 volt = 3.2 volt.

but if VCC is 3.3 V and signal level is 3.3 V it would work as it is?

Please read the answer.

again. with this relay board the coils can get 5 V over JD-VCC. now we talk about the left part of the schema. if VCC is 3.3 V and logic level HIGH of In is 3.3 V. will it acrivate the optocoupler as it is? I think yes and there is no need to bridge the indicator LED


text:
Why are my if statements acting like the condition is always true?
Here is my code. My issue is is that the keys are getting "pressed" even though there is nothing jumping any of the pins on the Arduino.
// UNO-HIDKeyboard-Library - Version: Latest
// This program has been created by pcs3rd.
// Please do not change this line.
#include <HIDKeyboard.h>
HIDKeyboard keyboard;   // Initiate keyboard
// Pin deffanitions and variables...
int key0 = 2;   // Button 0 (Unused but optional)
int key1 = 3;   // Button 1
int key2 = 4;   // Button 2
int key3 = 5;   // Button 3
int key4 = 6;   // Button 4
int key5 = 7;   // Button 5
int key6 = 8;   // Button 6
int key7 = 9;   // Button 7
int key8 = 10;  // Button 8
int led0 = 13;  // Indicator light.
int state0 = 0; // Button 0
int state1 = 0; // Button 1
int state2 = 0; // Button 2
int state3 = 0; // Button 3
int state4 = 0; // Button 4
int state5 = 0; // Button 5
int state6 = 0; // Button 6
int state7 = 0; // Button 7
int state8 = 0; // Button 8

void setup() {
   keyboard.begin();    // Start keyboard emulation
   Serial.begin(9600);  // Start Serial Output
   delay(300);          // Wait to be recognized be PC.
   pinMode(key1, INPUT_PULLUP); // set pin mode
   pinMode(key2, INPUT_PULLUP); // set pin mode
   pinMode(key3, INPUT_PULLUP); // set pin mode
   pinMode(key4, INPUT_PULLUP); // set pin mode
   pinMode(key5, INPUT_PULLUP); // set pin mode
   pinMode(key6, INPUT_PULLUP); // set pin mode
   pinMode(key7, INPUT_PULLUP); // set pin mode
   pinMode(key8, INPUT_PULLUP); // set pin mode
   pinMode(led0, OUTPUT);       // set pin mode
   Serial.println("Startup Completed!");
}

void loop() {
   // write state info to vars
   state0 = digitalRead(key0); // Button 0
   state1 = digitalRead(key1); // Button 1
   state2 = digitalRead(key2); // Button 2
   state3 = digitalRead(key3); // Button 3
   state4 = digitalRead(key4); // Button 4
   state5 = digitalRead(key5); // Button 5
   state6 = digitalRead(key6); // Button 6
   state7 = digitalRead(key7); // Button 7
   state8 = digitalRead(key8); // Button 8
   if (state0 == HIGH) {       // Button 0
     digitalWrite(led0, HIGH);
     // keyboard.pressSpecialKey(0x68); (You can enter a scancode instead of 0x68,)
     Serial.println("state0");
     delay(30);
   }
   if (state1 == HIGH) { // Button 1
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x68);
     Serial.println("state1");
     delay(30);
   }
   if (state2 == HIGH) { // Button 2
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x69);
     Serial.println("state2");
     delay(30);
   }
   if (state3 == HIGH) { // Button 3
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6A);
     Serial.println("state3");
     delay(30);
   }
   if (state4 == HIGH) { // Button 4
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6B);
     Serial.println("state4");
     delay(30);
   }
   if (state5 == HIGH) { // Button 5
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6C);
     Serial.println("state5");
     delay(30);
   }
   if (state6 == HIGH) { // Button 6
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6D);
     Serial.println("state6");
     delay(30);
   }
   if (state7 == HIGH) { // Button 7
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6E);
     Serial.println("state7");
     delay(30);
   }
   if (state8 == HIGH) { // Button 8
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x0F);
     Serial.println("state8");
     delay(30);
   }
   digitalWrite(led0, LOW);
   Serial.println("scan");
   delay(30);
}

Yet, even though I have 'if' statements, the code still gets executed, as shown in my monitor:
Startup Completed!
state0
hstate1
istate2
jstate3
kstate4
lstate5
mstate6
nstate7
state8
scan
state0
hstate1
istate2
jstate3
kstate4
lstate5
mstate6
nstate7
state8
scan

Are there any hints to what could be going on? I reformatted the code for readability, but it is pretty much the same as before. Also, I am not using pin 0 or one. I am using 13 for onboard LED.

Change state1 == HIGH etc. to state1 == 1.  Does that solve it?

@MichaelT ,as I just discovered through serial output, no it doesn't change anything. But I did discover that The code gets stuck at the first statement when I set to chech against HIGH but it racks through all of the statements if i set it LOW

how did you wire the 'keys'? to 5 V pin?  do you have pull-down resistors? did you really connect some button to pin1? and HID on Uno?

Welcome to Arduino:SE. You might find this post on our Meta site helpful: How to ask a good question for Arduino Stack Exchange.

The uno is capable of hid, just not at the same time as everything else, take a look at lufa. and I don't have any keys wired, therefore, none of the code in the statements should get executed @Juraj .Also, the question isn't about the code, its about why the code in the if statement is gettingexecuted even though the gpio pin(s) aren't ber\ing jumped to .

after you edited the question, you still have it wrong: with input_pullup pins are HIGH, if not connected to ground

Microcontroller pins tend to read LOW when left floating (but not always!). However, pin 1 is used to communicate with the USB-UART converter, and I believe it is set HIGH in the idle state. So assuming you are not pressing any buttons, keys 2-8 will be in the LOW state by default, but key 1 will be HIGH. Hence when defaultCase = HIGH;, the first if is triggered. When defaultCase = LOW; all if's but the first one fire up. Solution — don't use digital pin 1 (edit: avoid pin 0 and maybe 13 as well).
Edit: The answer above refers to the original code without the pull-up resistors enabled.

So i tried shifting all my pins to 2-9 and its still racking though all of the commands

@pcs3rd: you've tried it with the new version of the code? If so please please take note of Juraj's recent comment. You now have pull-ups enabled, and all the pins should be reading HIGH unless you start pressing buttons (assuming the buttons are connected to ground). Your ifs should be checking ==LOW in order to work correctly.

Oh. thats probably the issue then


text:
Pressure transducer returns 2.4v at 0 psi when working with a 0.5v to 4.5v pressure transducer
I have this pressure transducer:
https://www.amazon.co.uk/dp/B07YZL6TYD?psc=1&ref=ppx_yo2ov_dt_b_product_details
The transducer has a range of 0.5v to 4.5v which translates to 0 psi to 100 psi.
When I hook the transducer up to a Arduino boards analog pin, whose range is between 0 to 1024, it returns about 520 at 0 psi.
When I measure with a meter, it reads 2.4v which i think should not measure that much.
What am I doing wrong?

If you could follow up and answer any questions posed in the comments or answers by editing your question with updated or improved data we would all appreciate it.

Is the pressure sensor measuring relative pressure or absolute pressure?
Assuming the pressure sensor is measuring absolute pressure:

1 atmosphere is about 14 pounds per square inch (PSI).
Altitude and weather change that so it is unreliable / not-constant.
But for many uses it is close enough.
(14/100 PSI * (4.5V - 0.4V)) + 0.4V = 0.546V + 0.4V = 0.946V

The expected voltage given the parameters in the question, assuming this is an absolute pressure sensor and that it has a linear response, should be near 1 Volt.  But it is over double that.  Consider checking the supply voltage to the sensor.  Also consider disconnecting the output of the sensor from the Arduino board and repeating the voltage measurement. Finally, make sure the above assumptions are accurate.

I would expect your pressure transducer has an initial offset voltage, typically 0.5V, it states Output: 0.5 - 4.5 V / 0 - 5 V. I would also expect the output to be about 4.5V at full pressure but this is only a SWAG as there is no data sheet available. It might have been a good price but was it worth all of the time it is taking you to determine if it is OK? Are the meter readings correct, I cannot determine that unless I know what type of output the transducer has. Is it actually analog, does it need a pull up resistor, output loading requirement, ???
If you cannot get the information from the vendor I think the only way you will really know is to connect several up and test them. There are several types of pressure transducers in this package, they are absolute (atmospheric pressure) and Gauge (PSIG) (Pounds Per Square Inch). The nice looking advertisement on your link does not give this or much other needed information such as what media is it compatible with other then a few.


text:
I can't upload codes to my ESP8266
,this is the error I encounter when i try to upload my code
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK  "your-password"
#endif

const char* ssid     = STASSID;
const char* password = STAPSK;

const char* host = "192.168.1.1";
const uint16_t port = 3000;

ESP8266WiFiMulti WiFiMulti;

void setup() {
  Serial.begin(115200);

  // We start by connecting to a WiFi network
  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP(ssid, password);

  Serial.println();
  Serial.println();
  Serial.print("Wait for WiFi... ");

  while (WiFiMulti.run() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  delay(500);
}

void loop() {
  Serial.print("connecting to ");
  Serial.print(host);
  Serial.print(':');
  Serial.println(port);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;

  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    Serial.println("wait 5 sec...");
    delay(5000);
    return;
  }

  // This will send the request to the server
  client.println("hello from ESP8266");

  //read back one line from server
  Serial.println("receiving from remote server");
  String line = client.readStringUntil('\r');
  Serial.println(line);

  Serial.println("closing connection");
  client.stop();

  Serial.println("wait 5 sec...");
  delay(5000);
}

Need a bit more information, what ESP8266 module are you using? Does it have a Reset swtich that needs to be held to program? Like discussed at this link... https://tttapa.github.io/ESP8266/Chap06%20-%20Uploading.html#:~:text=press%20and%20hold%20the%20reset,will%20boot%20in%20program%20mode

why are you posting a picture of text? ... you pasted the code, paste the error message also ... if you can't upload then the code is irrelevant and only clutters up the post

Which version of arduino IDE do you use? Try to update

Try updating the Serial Driver in your system or try using lesser baud rate, i.e. 9600 instead of 115200.

You should be able to program an ESP8266 at 500Kbit/s or faster. If it only programs at 9600, something's not right.


text:
find out the pin numbers for the Arduino IDE for a certain board - the esp 32
I followed the tutorial I found here https://techtutorialsx.com/2019/03/29/esp32-arduino-controlling-a-dc-motor/
On the very interesting topic controlling a DC motor with the esp32 and Arduino I have some questions:
The first one: Where in the world did the guy find out the pin numbers for the Arduino IDE for this board? I have no idea how to find them!?

Taking in consideration that the digital IO pins of the ESP32 can only
  source a maximum current of 40 mA [1], we cannot directly use them to
  control a DC motor.
Instead, we are going to use a ULN2803A integrated circuit to actually
  provide the current to the motor, while the ESP32 will simply control
  if the motor is running or stopped.
The connection diagram to control a DC motor from the ESP32 using an
  ULN2803A can be seen below at figure 1. for controlling a DC motor
  with the ESP32, using a ULN2803A integrated circuit
The controlling of the DC motor with the ESP32 and a ULN2803A IC. In
  short, the ULN2803A will act as a switch, which will turn on / off the
  connection of the motor to GND, depending on the state of the input
  pin labeled as In 1. So, when the GPIO of the ESP32 is at a digital
  high value (VCC), the ULN2803A will connect the motor to GND, and thus
  the motor will be on. When the GPIO is at a digital low value (GND),
  then the motor will be disconnected from GND, and thus it will be off.
  Furthermore, the ULN2803A can be controlled by 3.3 V inputs and
  provide higher voltages, allowing us to control a 5 V DC motor with
  the ESP32.
The code
The code for this tutorial will be very simple, since we basically
  only need to control the status (high or low) of a digital pin of the
  ESP32.
So, we will start by declaring as a global variable the number of the
  pin that will be connected to the DC motor.
In my case I’ll be using GPIO 13. Note that for the Beetle ESP32
  board, which is the one I’m using, this maps to the pin labeled as D7.
int motorPin = 13;

After that, we need to initialize the pin as output, in the Arduino
  setup function. To do that, we simply need to call the pinMode
  function.
This function receives as first argument the number of the pin and as
  second argument a constant indicating the operating mode. So, we will
  pass the as first argument the value of the pin stored in our
  previously declared global variable and as second argument the
  constant OUTPUT.
void setup() {

  pinMode(motorPin, OUTPUT);

}

We will write the rest of our code in the Arduino main loop. We will
  first turn on the motor, wait some seconds, turn it off, wait some
  more seconds and then repeat.
So, to turn the motor on, we simply need to set the value of the ESP32
  digital pin to high, which will make the motor run at full speed. We
  can set the digital level of a pin with a call to the digitalWrite
  function.
This function receives as first argument the number of the pin and as
  second argument a constant indicating the digital level to which the
  pin should be set.

An Arduino boards package with configuration for your board has constants for pins which correspond to labels on the PCB. The constants are defined in pins_arduino.h file, which is applied only if you choose the corresponding board in Tools menu. In code you should use this constants as values for your constants, like for example const uint8_t LED1_PIN = D2;.
If the boards package doesn't have the board and you use generic settings, the you can study the schematics of the board to see which PCB pin goes to which MCU pin. Usually the logical pin numbers are labeled in schematics additionally to physical pin numbers of the chip.
Note: The linked pins_arduino.h is for FireBeetle ESP32. The Beetle ESP32 is not defined in ESP32 boards package yet.
The schematics is on the Wiki page.


text:
Arduino Port randomly changes whenever I punch correct RFID tag
I was working on an Electronic Door Lock/Unlock system using Arduino Uno and RFID Reader/Tags on Ubuntu 18.04.02 lts.
Now the problem is that whenever I punch-in the correct RFID tag to the RFID reader, the Serial Monitor stops working and I notice that the "Port" value under (tools>Port) has also changed or even got un-selected.
Like, before my Port = /dev/ttyACM0
then whenever I punch in the correct tag, Port value either becomes None or gets changed to (= /dev/ttyACM1)
Also, after every 2nd or 3rd upload, I get the error message as /dev/ttyACM0: Permission Denied
My code is as follows:
#include <Servo.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
#define ledPin1 A0
#define ledPin2 A1
#define Buzz A2
Servo servo;
int pos = 0;
MFRC522 rc522(SS_PIN, RST_PIN);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  SPI.begin();
  rc522.PCD_Init();     // Initialize card reader
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  servo.attach(3);
  servo.write(0);
  Serial.println("Scan the Card:");
}

void loop() {
  // put your main code here, to run repeatedly:

  // check if any card is present and also scan only one card if multiple are present
  if(!rc522.PICC_IsNewCardPresent() || !rc522.PICC_ReadCardSerial())  return;

  // check if the type of the card is what we need and not any other card.
  MFRC522::PICC_Type type = rc522.PICC_GetType(rc522.uid.sak);
  if(type!= MFRC522::PICC_TYPE_MIFARE_MINI &&
     type!= MFRC522::PICC_TYPE_MIFARE_1K &&
     type!= MFRC522::PICC_TYPE_MIFARE_4K) return;
  String strID = "";
  for(byte i=0; i<4; i++) strID += (rc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(rc522.uid.uidByte[i], HEX) + (i != 3 ? ":" : "");

  // put ID in capitals
  strID.toUpperCase();
  Serial.print("Card: ");
  Serial.println(strID);

  // Do the verification
  if(strID.indexOf("92:AA:CD:73") >=0){
    Serial.println("Access Granted");
    digitalWrite(A0, HIGH);
    tone(Buzz, 3000, 500);
    for (pos = 0; pos <= 60; pos += 1) {  // goes from 0 degrees to 60 degrees
    // in steps of 1 degree
    servo.write(pos);                // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 10ms for the servo to reach the position
  }
  delay(500);
  for (pos = 60; pos >= 0; pos -= 1) {  // goes from 60 degrees to 0 degrees
    servo.write(pos);                   // tell servo to go to position in variable 'pos'
    delay(10);                          // waits 10ms for the servo to reach the position
  }
    digitalWrite(A0, LOW);
    delay(500);
  }
  else{
    Serial.println("Access Denied");
    digitalWrite(A1, HIGH);
    tone(Buzz, 300, 200);
    delay(250);
    tone(Buzz, 300, 200);
    delay(250);
    tone(Buzz, 300, 200);
    digitalWrite(A1, LOW);
    delay(400);
  }
}

Please Help!
Thanks in Advance.

Sounds like your code is crashing.

Same code was working in Windows, but showing peculiar output in ubuntu.
Also, can you help me out with why every second time I need to grant permission to ttyACM0/ttyACM1?

on Windows you didn't notice the reset, because the port didn't change?

Comment out all the code related to what happens when you tap the right tag. Then add it back in a few lines at a time until it fails.


text:
how to connect 100 Leds and Blink them on Arduino
I am planning to connect 100 LEDs to an arduino in a parallel circuit.
The current limit exceed beyond the Arduino UNO board.
In want to blink all 100 LEDs at same time.  So how can I provide power source to 100 LEDs so they can blink with arduino programming.
Thanks in advance
Edit: As per discussion, MOSFET is required but which value MOSFET is required. There are many P- and N-channel MOSFETs available.

Arduino problem is only how to blink, not what to blink.

A relay, a mosfet, a (motor) driver, a transistor, and so on. Have you soldered 100 leds parallel? That was a bad idea, they will not have the same brightness, since they require a certain current, not a voltage. What kind of leds are they?

I little bit understand that Mosfet work as a switch of blinking function. What mosfet is better for lit 100 leds. i didn't connect 100 leds yet, but i will make circuit according to connectivity with arduino.

For 100 LEDs in parallel you will also need 100 resistors, and a transistor (MOSFET) that can handle the total current for all the LEDs.
For instance, at 20mA drive current you would be dealing with 2A - you'd need a (minimum) 2A power supply and a MOSFET that can handle 2A.
Or you can think a little differently.
If you use a higher voltage power supply you can group your LEDs together into chains.  For example with a 12V power supply you could (depending on the voltage of the LEDs) have up to 4 in a chain (red LEDs, 2V forward voltage, 2x4=8. White LEDs, 3V forward voltage, 3x4=12).  Each chain then has a single resistor, and you're working with a quarter of the current (500mA) - just 25 chains of 20mA but at a higher voltage.  So you can use a smaller MOSFET and you have only 25 resistors.
Another thing you could consider is to then further group those chains together. Maybe 5 groups of 5 chains, each with their own MOSFET. Then you switch just one group on at a time, but cycle through them very rapidly.  Each group only then uses 100mA (5 chains at 20mA = 100mA), and you can use a really small MOSFET, and your power supply needs only be able to provide a couple of hundred mA (give it some headroom) and can be smaller and cheaper.
The only down-side of that method is you can get flicker which may be noticeable if the LEDs are moving. It also means your Arduino is doing more work to light all the LEDs.

Thanks for valuable reply. I also have 10 RGB Common Anode. in this project i want to make different animations,effects. I am studying about mutiplexing. Is it necessary to use TLC5940NT IC for multiplexing?

No, you don't need the TLC5940NT. That doesn't multiplex, anyway, it's a shift register.  For simple multiplexing of 10 LEDs you want 10 P-channel FETs and 3 resistors. Or you can use 5 P-fets and 6 N-fets and 6 resistors, depending on how you want to arrange your multiplexing. If you only want to use low currents then you could probably get away without the fets - as long as the total curret through an IO pin at any moment in time doesn't exceed 25mA (or 40mA for brief periods).

ok could you please tell me the correct values for both p-channel FETS and 3 resistors and 5 p-fets and 6 n-fets, 6 resistors............................I little bit understand that Mosfet work as a switch of blinking function. What mosfet is better for lit 100 leds. i didn't connect 100 leds yet, but i will make circuit according to connectivity with arduino..........If you can share some tutorials, i will be very thankful to you.

A MOSFET is just a switch (in this situation), yes.  You need to make sure it can handle the peak current for your arrangement, and that the threshold voltage (VGS) is below about 4V - ideally below 2V (-4 and -2 for P FETs).  P FETs switch the anodes, and N FETs switch the cathodes. Multiplexing is just rapid switching on and off of LEDs so fast you can't see it.

thanks for reply. last thing could you provide p channel mosfet name (like IRFxxxxx)  for multiplexing RGB leds. i dont have enough knowledge about electronic components.

Please help only P-channel MOSFET value is required.

I do not know any suitable for hobbyists. All the ones I use are SMD components.  Use the parametric search of your favourite supplier to find one with enough current capacity, the right kind of threshold voltage, and a package suitable to your needs.


text:
RF receiver becomes weakened after motor turns on
I recently bought a simple SMAKN 315MHz RF receiver and transmitter, and I got everything working so that the transmitter transmits the value of a joystick, and the receiver receives that and uses it to set the analogWrite() of a motor on a PWM pin.
However, the moment the motor turns on, the receiver just weakens tremendously. At that point it only gets a message when I stick the receiver right against the transmitter. I’m powering the arduino and motor with a 3.7v LiPo battery btw.
Any help? I’ve tried with a 9V alkaline and a 9V adapter and nothing significantly changed.

What kind of motor? How is it wired?

@Majenko Just a simple brushed motor, it doesn’t even matter if the motor is on the transistor controlling the speed or just plugged into voltage and ground lines with a resistor, the receiver immediately will stop working

That behaviour is to be expected. Motors are very noisy and cause massive amounts of interference in radio signals.
The best thing you can do is to try and suppress that interference. For this you will need three 0.1µF (100nF) ceramic capacitors.
One capacitor is connected between the terminals of the motor to reduce noise transferred down the wires (wires make good antennae). The other two connect between each of the terminals and the metal body of the motor.
The metal body of the motor then becomes a shield to trap the noise.


text:
i2c wire length
I have some problems with i2c. I can not use long wires on SDA and SCK bus.
This seems to be the consequence of the capacity between the SDA and SCK wires and not between SDA/SCK and GND.
I figured this out by placing capacitors in a breadboard with a Arduino UNO and some MCP23017's (with 2k2 pull-up resistors).
100pF capacitor between SDA and SCK: No problem.
150pF: The communication stops.
1nF from SDA to GND and/or 1nF from SCK to GND: No problem.
A two wire cable is approx 50pF per meter, so 2 meters seems the limit.
With an ATtiny85 (8MHz clock, 100k i2c speed) as master it is even worse:
With 2k2 pull-up a capacity of 68pF is killing.
By reducing the pull-up resisters to 470E I was able to go up to 200pF  (hurray: 4 meters of wire).
Someone any idea how to increase the distance by tuning the SDA/SCK timing?

I2C is not designed to be used over long wires. What makes you think you can?

A P82B96 Dual bidirectional bus buffer can help you "go the extra mile". See table on page 14, https://www.nxp.com/docs/en/data-sheet/P82B96.pdf

@MikaelPatel add your comment as a answer.

As @majenko wrote, the I2C bus was not designed to go over wires or into a cable. It is ment for components on the same pcb board.
As @mikaelpatel wrote there are bus drives which convert the I2C signal into some kind of RS-485 signal for twisted pair cables.
The crosstalk between SDA and SCL should be avoided at all times. Don't put SDA and SCL into wires that are next to each other. When using twisted pair cable (for example Cat5), then use SDA in a different pair than SCL.
The worst situation is when SDA and SCL are next to each other in a flat ribbon cable.
The capacitance caused by the cable from SDA to GND and from SCL to GND can be compensated some by a lower value of the pullup resistors and by lowering the clock speed.
The maximum current is specified as 3 mA. That means with 5V, the lowest value for the pullup resistor is 1k6.
A little more can be achieved with a current driver of 3 mA instead of the pullup resistors. This is not often done, but it creates a better signal.
The Arduino Wire library for the Arduino Uno can be set to 50 kHz with Wire.setClock. I don't know the lowest value, but there is a limit without warning. I don't know the lowest clock speed for an Attiny microcontroller. A software I2C bus implementation can often go much lower.
Note that some sensors have a minimum clock speed.
The rule of thumb is that 50 cm is the maximum for the I2C wires. However, some say that they are able to use the normal I2C bus over 6 meters cable. My opinion is that the I2C should always work, since it is not very fault tolerant, and the Arduino Wire library for the Arduino Uno is not fault tolerant at all. Therefor, don't go near the limits.
The MultiSpeedI2CScanner (probably only working for Atmega chips) helped me a lot to learn about the I2C limits in different situations.

With 2 shielded cables, separate for SDA, SCL no problem to go several meters.
I just connected 2 I2C devices on common shielded cables 6m long SDA, SCL
3.3V and GND on non-shielded cables
Successfully tried also computer mice shielded cables, it's about 1.5m working no problem
Pull up resistors approx. 4k7

Can you tell us what kind of shielded cable you used?


text:
Controlling the Serial Monitor for 10 seconds
I am an amateur with Arduino and coding and I am learning in my lab class. My project consists of using a photoresistor to measure the brightness of a white LED. I have the following circuit built.

I am having problems with the code because I need the serial monitor to print every 1/10 of a second for 10 seconds. My professor started talking about the micros() function but never showed an example. I have an idea as to how I can utilize this function to control how long the Serial Monitor prints for but I have been unsuccessful. I know that setting a delay is good enough for reading every 1/10 of a second but how can I make the serial monitor print values for only 10 seconds?
I believe it should be a total of 100 readings.
This is my current code:
unsigned long start, finished, elapsed, total;
int analogInPin = A0;
int LEDreading;           // analog reading
int LEDpin = 9;           // LED on pin 9

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

void loop() {
  analogWrite(LEDpin,255);  // LED brightness
  start = millis();
  LEDreading = analogRead(analogInPin);
  Serial.println(LEDreading);
  delay(100);
  finished = millis();
  elapsed = finished - start;
  total = elapsed*100;

  if (total >= 10000){
    Serial.end();
}

You could count to 100...

If you can blink without delay(), then you can print without delay().

Using micros() is very much like boiling an egg.
When you want your egg to be cooked just right you know that it needs to be in the boiling water for a certain amount of time. There's three ways you can achieve that:

Use an egg timer to alert you when the time has passed,
Sit and stare at the boiling pot counting the seconds as they slowly tick by (booooooring..... ...zzzZZZzzz...)
Remember what time you put the egg in the water and glance at the clock every so often to see how much time has passed.

Using millis() is like option 3. It tells you how many milliseconds have passed since the board was turned on (or since the last millis() rollover at roughly 49 days). So when you put the egg in the water you record the current time. Then you periodically compare the recorded time to the current time (a simple subtraction will suffice) to see if enough time has passed. When it has you remove the egg and chow down.
So to put that more in a coding context - when you start some operation, or want to measure a period of time from a point, you just save the time in a variable:
start = millis();

(start must be uint32_t, aka unsigned long). To find if enough time has passed you just subtract that saved time from the current time and it gives you the elapsed time, which you can compare to your required elapsed time:
if (millis() - start >= 100) {
}

1/10 of a second is 100ms, so if you hit a difference of 100ms (or more) then your time has arrived and you can do something.
If you want it to do it again after that then just set the "start" time to the current time again.
For instance, for your requirements:
void loop() {
    // Record the start time - the static means it
    // only happens once the first time loop() is run and
    // it remembers the value between iterations
    static uint32_t start = millis();

    // Somewhere to store the number of values we
    // have given - again, static so it remembers across
    // iterations of loop()
    static uint8_t count = 0;

    if (count < 100) { // No more than 100 counts
        if (millis() - start >= 100) { // Tick
            start = millis(); // Do it again in 100ms time

            // Add whatever you need for your readings here

            count++; // Add one to the count
        }
    }
}

Using delay(100) will cause the sketch to wait at that line for 100 milliseconds.  That is not (quite) the same as DOING something every 100 milliseconds.  The difference is that other things take time too, so the time will be 100 milliseconds plus how ever long everything else takes.
The solution used by @Majenko still has that problem in a small way, because a new millis() value is used to set the new value of start.  In most situations, it will work fine, but it is possible that the either or both of the millis() results were more than 100 after the previous value of start.  That would happen if code that replaces the comment took more than 100ms some time.  The fix for that is very simple.  Just change start = millis() to start += 100.  That will attempt to speed up the following loop, if it was getting behind.
As a side note, it would be good to change the 100 millisecond references to a defined name.  Either a #define or a const.  Since the millis() function returns an "unsigned long" value, I would use the same data type for a related const value.  That just means that the compiler will not have to (invisibly) convert between different types when doing the math operations.
#define REPORT_CYCLE 100
const unsigned long REPORT_CYCLE = 100; // milliseconds between measurement and reporting cycles

If you are a beginner, you may not have seen static variables yet.  If you know about them, fine, but if not, they can be replaced by global scope variables.
The @Majenko code uses a fixed count of 100 iterations to do the measurement and reporting.  That works fine as long as neither the for 10 seconds or every 1/10 second changes.  If either of those change, the count limit would also need to be recalculated and changed.  Instead, I would use another defined name for how long to do measurement and reporting cycles, and let the compiler handle how many times that actually is.
Doing an analogWrite() sets the value (brightness here), which will stay constant until changed again.  Since your program only sets a single value, it only needs to be done once.  Move that statement to setup().
There is no need to do Serial.end() when the reporting is done.  That disables serial communication, but is unneeded, if no more Serial.println() commands are executed anyway.
To avoid calling millis() multiple times in the same 'pass' (in each if test), I like to call it once, and save the result.
Taking the @Majenko code, plus your starting sample, and described changes gets
// Intervals in milliseconds
#define REPORT_CYCLE 100
#define REPORT_INTERVAL 10000
unsigned long nextStart, endTime;
int analogInPin = A0;
int LEDreading;           // analog reading
int LEDpin = 9;           // LED on pin 9

void setup() {
  Serial.begin(9600);
  analogWrite(LEDpin,255);  // LED brightness
  nextStart = millis(); // Time for "right now"
  endTime = nextStart + REPORT_INTERVAL;
}

void loop() {
  unsigned long now = millis();
  if (now < endTime) { // still need to do more reporting
    if (now >= nextStart) { // time to get and report another reading
      nextStart += REPORT_CYCLE; // When the next reading should be done

      LEDreading = analogRead(analogInPin);
      Serial.println(LEDreading);
    }
  }
  // do other things, both while still reporting, and after reporting is done
}


text:
Is it possible to connect nodemcu to mobile internet and how?
Guys i have done project home automation over Android in which i have use NodeMCU and relay to control switching of lights but this is a offline project.
Now I want to connect it with internet please tell me if I can connect NodeMCU to mobile WiFi.
I don't have router at home  please tell me if it is possible and how?

please explain "mobile WiFi", I suspect you are referring to whats aka mobile internet, 3G/4G, LTE and so on.

Yes i want to connect nodemcu to mobile internet

NodeMcu is made specially for wireless communication. You can connect it to wifi and hospot. You just need to pull in some library and pass you data to connect.

If you have a mobile wifi router, the nodemcu can connect to it just as it would connect to a fixed router.
If you want to connect the nodemcu to the internet without a mobile wifi router, you can use a gsm/gprs/3G/4G module, for example the SIM800L. (Provided the location has cell coverage.)

SIM800 is 2G = low bandwidth

I don't think switching lights will need a lot of bandwidth though.

I agree, it shouldn't.

I have a wifi library.This is how I connect the NodeMCU with that library.
#include <ESP8266WiFi.h>

#define WIFI_SSID "name_of_your_hotspot"
#define WIFI_PASSWORD "password_of_hotspot"

void setup() {
   Serial.begin(9600);
   WiFi.begin( WIFI_SSID,  WIFI_PASSWORD) ;

    Serial.print("connecting");

    while (WiFi.status() != WL_CONNECTED ) {
        Serial.print(".");
        delay(500);
    }

     Serial.println();
     Serial.print("connected");
     Serial.println(WiFi.localIP);
}

void loop () {
    // Your code
}

I used this tested and working code. Comment if any issue.
Make sure you import the library.
Hope this fixed your issue.
EDIT : 4th Jan 2018
I know this topic is old and maybe the OP solved this problem but I saw many people struggling with this same situation how to connect nodeMCU to an internet connection.
So, I created a medium post with detailed information on how to Connect ESP8266 module to the internet? You can read the story here (I am not paid or sponsored by this post I made this story to help the newbies)
If you still have any problem comment down below or add a response in my medium story.

Can u provide link for wifi library

The library is built in. Check in the list of library. Sketch > Include Library  > ESP8266WiFi

@Mayur did that work?


text:
Serial port - ESP8288 (TCP/IP) - WiFi - "Virtual serial port on my linux/windows PC" [Solved]
Is there an way to transport a serial port via TCP/IP to a PC.
The goal is to have a ESP8266 dongle that I connect to a router, switch or other device with a serial port for configuring.
I have found RFC 2217 that is suitable for the goal. Is there a arduino implementation ? Or any other way to get to the goal?

You mean besides the example that comes with the ESP8266 boards package that does just what you want?

Now I have to take a look at the examples.
A FB friend pointed me to https://github.com/jeelabs/esp-link/ that looks like it will do the work as well. Thx

There's one called (I think) WiFiSerial. I took that and built on it to add RFC2217 support a while back. Never got round to testing it since I don't have an RFC2217 client, but I have used it for programming boards remotely.

Majenko, could you share the code?

If I can find it, sure.

Here you go - make of it what you will.  If you fancy pushing any changes and fixes back as a PR in Github that'd be great. https://github.com/MajenkoProjects/WiFiSerialDTR


text:
How to find if AC Appliance is on or off using ACS712 current Sensor
I am trying to get the status of appliance using current sensor. My Circuit looks like below image. I don't want to measure current. I just want to know whether appliance is on or off.

I am getting following readings when power turned on and off, I don't see any difference, I am not able to figure out whether the bulb is on or off.

Please help me to know the status of appliance/bulb.
PS. Please find my code below:
/*
Measuring AC Current Using ACS712
www.circuits4you.com
*/
const int sensorIn = A0;
int mVperAmp = 185; // Use 100 for 20A Module and 66 for 30A Module

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

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

void loop(){

 Voltage = getVPP();
 VRMS = (Voltage/2.0) *0.707;  //root 2 is 0.707
 AmpsRMS = (VRMS * 1000)/mVperAmp;
 Serial.print(AmpsRMS);
 Serial.println(" Amps RMS");
}

float getVPP()
{
  float result;
  int readValue;             // value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;       // store min value here

   uint32_t start_time = millis();
   while((millis()-start_time) < 1000)  // sample for 1 Sec
   {
       readValue = analogRead(sensorIn);
       // see if you have a new maxValue
       if (readValue > maxValue)
       {
            /*record the maximum sensor value*/
           maxValue = readValue;
       }
       if (readValue < minValue)
       {
           /*record the minimum sensor value*/
           minValue = readValue;
       }
   }

   // Subtract min from max
   result = ((maxValue - minValue) * 5.0)/1024.0;

   return result;
 }

Show your code.

Hi @EnricBlanco thanks for prompt response,Please find the code above.

Is your ACS712 module made to be used with the mains voltage ? Most are not. The ACS712 modules are sensitive for magnetic fields from transformers and wires. They are also noisy. If you, for example, have a 5A ACS712 module and want to measure 0.1A, the measurement could be lost in the noise. The sketch collects the minimum and maximum peak, therefor the sketch collects also the noise peaks. A current transformer does not need direct contact and is a lot safer.

another issue is that AC has no current at the zero-cross, so you need some sort of timing to get RMS

The code looks like it would produce rather larger values than you are seeing, if it gets correct inputs from the sensor.  For that reason, you probably should carefully check your wiring.  Also, with a DVM, measure the sensor output voltage with the light on and with it off, to verify sensor operation.  If you measure ok sensor voltages but don't get good readings, your analog input pin may have a problem; you could try other analog input pins.
Note, when debugging an issue like this, it does not make sense to run a few numbers through five levels of processing before printing anything out.  You should at least add serial prints in getVPP(), and just before returning the result, print out result, maxValue, and minValue.
Note, fix the erroneous comment “//root 2 is 0.707”; the square root of 2 is about 1.414213562, while 1/√2 = (√2)/2 is about 0.707106781.

230v/100W = 0,44A so it should be a clear difference between off current and on current.


text:
I have just done this same code but not getting exact time as per Indian timezone...What thing should I add to get exact time?
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/

static const int RXPin = 10, TXPin = 11;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup() {
  Serial.begin(115200);
  ss.begin(GPSBaud);
  Serial.println(F("DeviceExample.ino"));
  Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
}

void loop() {
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();
  if (millis() > 5000 && gps.charsProcessed() < 10) {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
}

void displayInfo() {
  Serial.print(F("Location: "));
  if (gps.location.isValid()) {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  } else {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid()) {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  } else {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid()) {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  } else {
    Serial.print(F("INVALID"));
  }
  Serial.println();
}

Is this what you are looking for:
https://forum.arduino.cc/index.php?topic=473294.msg3237680#msg3237680

Use NeoGPS instead of TinyGPS, it has time and date functions for timezone offsets.
Ref:
https://forum.arduino.cc/index.php?topic=473294.msg3237680#msg3237680

This is a link-only answer, please provide the relevant parts in the answer here.

@Avamander changed the answer as requested.

Thank you, at least it won't be flagged as "link-only" now.


text:
Arduino master/slave communication using RS485
I am using Arduino Uno as a Master Device and 3 Arduino Unos as slave devices.
I am sending data from each slave to master after every 3 seconds continuously, and is going to execute further logic accordingly.
I have been using a lot of libraries to test this scenario.
There are libraries which are using SoftwareSerial and HardwareSerial too, but these libraries are not working for me when i have multiple slaves and one master (It is only working with one master and one slave).
Please suggest me a better library which would be useful in my scenario.
Wiring Diagram:

addressing the slaves is on you. or use ModbusRTU

@Juraj : any particular library?

You need to implement one of automation protocols or write your own. https://en.wikipedia.org/wiki/List_of_automation_protocols

have you got any answer to solve this case? I am working to build system like this, but it is still not doing well :(

@Adwin not yet. what about you.. please let me know if u get anything.

First of all, your connection is just wrong, you should make the RS-485 bus as a straight line, with a 120 ohm resistor at the beginning and another one at the end. Each slave should tap into that line as close as possible to that line, look for datasheets and you will understand what I am talking about.
Second, you can use Modbus as a pretty good and easy to use communication protocol.

hey thanks for the reply on such old post.
which datasheet i shall exactly look into??

Max485 is a classic, probably has it, if not, look for Application Notes on RS-485, TI has good material on this.

And the post is not old, just half a year, I have seen a lot worse than that. Don't forget to accept if it answers.

RS485 module has resistor 120 Ohm inside


text:
Flickering LED when servo moves
I just got to play around with Arduino lately so I'm really new on this stuff and sorry for the grammar error.
I got a work where I need to turn the LED on all the time, my plan is to add a slow fade in and fade out later but the problem occurs when I add the servo.
Everytime servo starts moving slowly or fast the LED kinda flickering/dim like it lost power and come back to normal after the servo stops moving.
Here's the scheme I used and the code, I only change some delay to 5ms and so to test it out but no matter what the led is keep flickering.
Im using nano v.3 clone if its matter.

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 100;    // variable to store the servo position
int ledpin3 = 3;

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pinMode(ledpin3, OUTPUT);
}

void loop() {
  digitalWrite(ledpin3, HIGH);
  delay(1000);

  for (pos = 99; pos <= 150; pos += 1) { // goes from 0 degrees to 180 degrees
                                         // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable ‘pos’
    delay(15);                       // waits 15ms for the servo to reach the position
  }

  for (pos = 150; pos >= 30; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable ‘pos’
    delay(15);                       // waits 15ms for the servo to reach the position
  }

  for (pos = 30; pos <= 99; pos += 1) { // goes from 0 degrees to 180 degrees
                                        // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable ‘pos’
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Try moving your LED digitalWrite in the setup as you are just turning it on.

Do you have a resistor on your LED?

Does the LED flicker with same sketch and the servo disconnected? If not I think power is the issue.

if it's only a cosmetic problem, add a resistor in series with the LED and a capacitor across the LED leads.

If you are powering the arduino via usb try not to do that or plug it in to an usb 3.0 (and higher) port. The reason for this is that the servo draws a lot of power and the standard usb 2.0 with 0.5A can't handle the load and you got an voltage drop. And in that period of time the led goes off. usb 3.0 (and higher) can handle up to 1.5A so this souldn't be an error.

Thanks for your reply coder,tried to put it on my 3.0 usb ready powerbank and also directly at wall with no luck,the led still go wild,do i need to power the servo from another source? I tried to really minimize the component since i barely got any space left

It would be better if you powered the servo from its own power source such as batteries during development / testing.  Later, if a larger power supply can be located, you might try using the same power source for both the Arduino and servos.  Remember that the servo ground needs to be connected to the Arduino ground as well as the independent power source ground.

This not only depends on the USB power source, but also in the diode, through which the current flows on the Arduino. If you draw too much current through it, you will fry the diode. You have to connect the servos power besides the Arduino,  not through it.


text:
UltraSonic Sensor with an ESP-01 Standalone
I'm trying to build a cheap device to measure water level in a tank using HC-SR04 sensor and ESP-01 which send the data to MQTT topic. I used the same code with ESP-E12 which works just fine. As I'm trying to drive the cost down with ESP-01, I faced a problem with I/O pins. I searched the web and found some contradicting info about which pins could be used in this case.
So here is the schematic of my setup:

Coming to the ESP-01, I used a USB adapter to program it and the code uploaded successfully. Here I'm just showing the Ultrasonic sensor part which I believe I have issues with.
#define echoPin 2 // Echo Pin
#define trigPin 0 // Trigger Pin

long duration, distance; // Duration used to calculate distance

void setup(){
  Serial.begin (115200);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration/58.2;
  Serial.println(distance);
  delay(200);
}

I read somewhere in the internet that GPIO2 can't be used and must be replaced with Rx = GPIO3. However, I tried that and it didn't work too.
So the question here, am I really using the right pins or is it really possible to do that with esp-01?

I think logic requires 5V, but there is a hack to make it work with 3.3 v : https://www.instructables.com/Modify-Ultrasonic-Sensors-for-3-Volts-Logic-prepar/

you use the right pins. but this pins must be pulled up at boot. if the sensor pulls them LOW, then the esp8266 will not boot. same appiies for ESP-12

You need a Logic Level Converter Module
Because esp8266 01 support 3v and ultrasonic sensor support 5v

And ESP8266 IO pin is 5v tolerant ! https://www.facebook.com/groups/1499045113679103/permalink/1731855033731442

This question is old, but myself had the same problem, so I will answer it.
The problem here seems to be that you have the GPIO0 and GPIO2 connected to the SR04 module when it is powered (this is how should be expected), but the GPIO0 and GPIO2 (also GPIO15, just for mention it), are used by ESP8266 to change the boot mode, with nothing connected to these pins, the ESP will load the program written in the flash, but if these pins change the levels while the ESP is powering up, it could enter in the Flash mode and your code will not execute. If you turn on the ESP-01 first and connect the wires to the SR04 just after, the code works, I know because I had the same problem and have the circuit in my front right now. But this is just for testing, you should not have to do that, the solution for me was to use the GPIO3.
You can use the pin RX as GPIO3 as you mentioned, but you can't use it at the same time that you are using the Serial, because Serial will use the RX and TX pins. If you write a Webserver to display the distance measured, for example, and remove the lines that use the serial, it will work. I used the GPIO3 and GPIO2 with the same code, just disabling serial and changing the pin numbers and worked.

There are 2 things here.
Ultrasonic sensor works on 5V while ESP on 3.3V. So your sensor is sending 5V signal to ESP. It might fry your board but I believe it has a safety cut off of everything above 3.3V and that's the reason your application is not working.
Cheap solution would be adding voltage divider to your Echo pin:
https://randomnerdtutorials.com/how-to-level-shift-5v-to-3-3v/
but then you will face the issue mentioned by Juraj above.
You may then overpass that issue manually or look for more sophisticated (expensive) solution.

ESP is 5v tolerant. https://www.facebook.com/groups/1499045113679103/permalink/1731855033731442

full size ESP is but ESP-01 is not

What? The CHIP is 5v tolerant!


text:
Arduino Communication with Xbee
I'm trying to establish a wireless connection between two Arduino's(M0) using xbee s2c, one Arduino as the sender and other as the receiver. But I am not able to receive the message what the Arduino is sending.
The two radio modules are configured as:
Sender
pan id- 1234
CE- enable
DH- 13A200
DL- 40F8D876
AP- Transparent mode

Receiver
pan id- 1234
CE- Disable
JV- Enable
DH- 13A200
DL- 40F8D874
AP- Transparent mode

SENDER CODE
void setup() {
  // Begin the Serial at 9600 Baud
  Serial1.begin(9600);
  SerialUSB.begin(9600);
}

void loop() {
  SerialUSB.print(int(Serial1.write("1")));
  delay(1000);
}

RECEIVER CODE
void setup() {
  // Begin the Serial at 9600 Baud
  Serial1.begin(9600);
  SerialUSB.begin(9600);
}

void loop() {
  if (Serial1.available()){
  SerialUSB.print(int(Serial1.read()));
  delay(1000);
}}


text:
How to combine two different sensor sketches to one complete sketch?
How to combine two different sensor sketches to one complete sketch for a complete circuit that attaches to one Arduino Uno?
Sharp Dust Sensor
int measurePin = A0; // Connect dust sensor to Arduino A0 pin
int ledPower = D8;   // Connect 3 led driver pins of dust sensor to Arduino D2

int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);
}

void loop(){
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);

  voMeasured = analogRead(measurePin); // read the dust value

  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);

  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024.0);
  dustDensity = 0.17 * calcVoltage - 0.1;

  Serial.print("Raw Signal Value (0-1023): ");
  Serial.print(voMeasured);

  Serial.print(" - Voltage: ");
  Serial.print(calcVoltage);

  Serial.print(" - Dust Density: ");
  Serial.println(dustDensity); // unit: mg/m3

  delay(1000);
}

MQ-135 Sensor
int airquality = A2;
void setup()
{
  Serial.begin(9600);

}
void loop()
{

  int sensorValue = analogRead(A2);
  Serial.print("Air Quality = ");
  Serial.print(sensorValue);

  Serial.print("*PPM");
  Serial.println();
  delay(1000);

}

it is unclear what you are asking .... combine 2 sensors has multiple meanings  .......... please ask a detailed question

I will leave a simplified answer and I would recommend to read https://www.makeuseof.com/tag/getting-started-with-arduino-a-beginners-guide/ or similar to get a understanding of how to code.
An Arduino sketch has a structure.

Initialising values
A void setup() this code only run once the MCU is started
A void loop() and this code runs continuously.

So to merge two sketches you need to combine the code that is in the same sections and of course avoid duplicate code and ensure that you have unique variable names
Sharp Dust Sensor
int measurePin = A0; // Connect dust sensor to Arduino A0 pin
int ledPower = D8;   // Connect 3 led driver pins of dust sensor to Arduino D2

void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);
}

MQ-135 Sensor
int airquality = A2;
void setup()
{
  Serial.begin(9600);
}

Combined code
int measurePin = A0; // Connect dust sensor to Arduino A0 pin
int ledPower = D8;   // Connect 3 led driver pins of dust sensor to Arduino D2
int airquality = A2;

void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);
}

There is no way of "automatically" combine two sketches into one. That's because resources of Arduino are very limited. For example UNO it has only 4 timers. If both of the sketches want to use same resource they will not work properly.
If you want to combine two sketches into one you have to write a new sketch that combines mechanisms of both sketches. It's not easy, because delay and delayMicroseconds are going to give you problems, but you should be able to do that using micros() and millis() plus some modular math.


text:
Error when compiling code NODE MCU ESP8266-12E module in Arduino ide
Here is my sketch:

#include<ESP8266WiFi.h>

char* ssid = "xxxxxxxx";
char* pass = "xxxxxxx";

void setup() {
 WiFi.begin(ssid,pass);
 Serial.begin(9600);
 while(WiFi.status()!=WL_CONNECTED)
 {
  Serial.print(".");
  delay(500);
  }
  Serial.println("");
  Serial.print("IP Address: ");
  Serial.print(WiFi.localIP());
}

Here is the error:
Traceback (most recent call last):   File "C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py", line 25, in <module>
    esptool.main(fakeargs)   File "C:/Users/ASUS/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 2653, in main
    esp.connect(args.before)   File "C:/Users/ASUS/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 460, in connect
    last_error = self._connect_attempt(mode=mode, esp32r0_delay=False)   File "C:/Users/ASUS/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 440, in _connect_attempt
    self.sync()   File "C:/Users/ASUS/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 379, in sync
    timeout=SYNC_TIMEOUT)   File "C:/Users/ASUS/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 322, in command
    self.write(pkt)   File "C:/Users/ASUS/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 285, in write
    self._port.write(buf)   File "C:/Users/ASUS/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/pyserial\serial\serialwin32.py", line 323, in write
    raise writeTimeoutError serial.serialutil.SerialTimeoutException: Write timeout the selected serial port
serial.serialutil.SerialTimeoutException: Write timeout  does not
exist or your board is not connected

does the code "verify"?

This looks more like an error while uploading than on compilation to me. Have you selected the correct board settings?

The section
void loop() {
}

Is missing in the code, add it and recompile and.....