text:
Reading data from airspeed v3 eagle tree
I am trying to get values from this sensor Airspeed v3 from eagle tree but it seems my I2C is not working properly.
I bought a module in third party mode and followed these instructions from the manufacturer website.
I went to rcgroups forum and discovered the right values for the bits mentioned in the documentation about WRITE and READ.
I started the development of a code but I cannot get the values from the sensor. It is supposed to send me a 2 byte-formatted value indicating the airspeed measured. But surprisingly when I call this method Wire.requestFrom(AIRSPEED_ADDRESS, 2) it returns 0, so someway the communication is not working. I have used I2C before for ADXL345 sensor and it works perfectly.
The results from these lines
Serial.println(data[0]);
Serial.println(data[1]);

are just -1 indicating that no data is available to display.
Does anybody know how to get this working? Am I missing something?
This is my code right now.
#include <Wire.h>

#define AIRSPEED_ADDRESS  0xEA
#define WRITE_BIT         0x00
#define READ_BIT          0x01

void setup() {
  // join I2C bus (I2Cdev library doesn't do this automatically)
  Wire.begin();
  Serial.begin(9600);
  Serial.println("Program started");
}

void loop() {
  byte data[2] = {0};
  int i = 0;
  int16_t velocidade = 0;

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  if (!Wire.write(WRITE_BIT)) {
    Serial.println("error sending write_bit");
  }
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  if (!Wire.write(0x07)) {
    Serial.println("error sending 0x07");
  }
  Wire.endTransmission(false);

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  if (!Wire.write(READ_BIT)) {
    Serial.println("error sending read_bit");
  }
  else {
    //Serial.println("ok sending read_bit");
  }
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Serial.print("bytes read from slave: ");
  Serial.println(  Wire.requestFrom(AIRSPEED_ADDRESS, 2) );
  data[0] = Wire.read();
  data[1] = Wire.read();
  Wire.endTransmission();

  velocidade = data[1] | (data[0] << 8);
  Serial.println(data[0]);
  Serial.println(data[1]);
  Serial.println(" ");

}

This is really helpful. Thank you very much!

That's interesting but after using a different library the code worked out.
It has to follow exactly what the datasheet says in order to get things done.
The following source code makes it and get the airspeed from the sensor:
#define SENSOR_ADDRESS 0xEA
#include <Wire.h>
#include <I2cMaster.h>
TwiMaster AIRSPEED_SENSOR(true);

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

long airspeed_update(void) {
  static struct {
    union { int16_t val; uint8_t raw[2];
    } airspeed16;
  } airspeedv3;

  long airsp;

  if(AIRSPEED_SENSOR.start(SENSOR_ADDRESS | I2C_WRITE)) {
    delay(10);
    AIRSPEED_SENSOR.write(0x07);
    delay(10);
    AIRSPEED_SENSOR.stop();
  }

  if(AIRSPEED_SENSOR.restart(SENSOR_ADDRESS | I2C_READ)) {
    delay(10);
    airspeedv3.airspeed16.raw[0]=AIRSPEED_SENSOR.read(false);
    delay(10);
    airspeedv3.airspeed16.raw[1]=AIRSPEED_SENSOR.read(true);
    delay(10);
    AIRSPEED_SENSOR.stop();
  }

  airsp=airspeedv3.airspeed16.val;
  return airsp;
}

void loop() {
  int airspeed = airspeed_update(); Serial.println(airspeed);
  delay(50);
}

Get this library from here.

I found the I2C address on my Eagletree Airspeed V3 sensor to be 0x75 NOT 0xEA.
the following code adapted from first sample above works on my Nano:
/*
 * note that timming is critical - see delay (5)
 * and bps set to 115200
 * works ok, but clean up 5-19-2019 jaf
 */

#include <Wire.h>

#define AIRSPEED_ADDRESS  0x75
#define WRITE_BIT         0x00
#define READ_BIT          0x01

void setup() {
  Wire.begin();
  Serial.begin(115200);
  Serial.println("Program started");
}

void loop() {
  byte data[2] = {0};
  int i = 0;

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Wire.write(WRITE_BIT);
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Wire.write(0x07);
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Wire.write(READ_BIT);
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Wire.requestFrom(AIRSPEED_ADDRESS, 2);
  data[0] = Wire.read();
  Wire.endTransmission();

  Serial.println(data[0]);
  delay(5);
}

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


text:
How to write RFID data using the RFID-RC522 chip
I have got this library+code example from a friend, to read RFID numbers using the RFID-RC522 chip:
RFID.ino
#include <RFID.h>
#include <SPI.h>

/**
* RFID pins
* MOSI: Pin 11 / ICSP-4
* MISO: Pin 12 / ICSP-1
* SCK: Pin 13 / ISCP-3
* SS: Pin 10
* RST: Pin 9
*/

RFID rfid(10, 9);
unsigned char prevNum[] = {0,0,0,0,0};

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  rfid.init();
}

void loop() {
    if (rfid.isCard()){
        if (rfid.readCardSerial() && (
            rfid.serNum[0] != prevNum[0]
         or rfid.serNum[1] != prevNum[1]
         or rfid.serNum[2] != prevNum[2]
         or rfid.serNum[3] != prevNum[3]
         or rfid.serNum[4] != prevNum[4]
        )){
          Serial.println(rfid.serNum[0]);
          Serial.println(rfid.serNum[1]);
          Serial.println(rfid.serNum[2]);
          Serial.println(rfid.serNum[3]);
          Serial.println(rfid.serNum[4]);

          prevNum[0] = rfid.serNum[0];
          prevNum[1] = rfid.serNum[1];
          prevNum[2] = rfid.serNum[2];
          prevNum[3] = rfid.serNum[3];
          prevNum[4] = rfid.serNum[4];
        }
    }
}

RFID.h
/* RFID.h - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.
 * Based on code Dr.Leong   ( WWW.B2CQSHOP.COM )
 * Created by Miguel Balboa (circuitito.com), Jan, 2012.
 */
#ifndef RFID_h
#define RFID_h

#include <Arduino.h>
#include <SPI.h>

/******************************************************************************
 * Definitions
 ******************************************************************************/
#define MAX_LEN 16   // Largo m�ximo de la matriz

//MF522 comando palabra
#define PCD_IDLE              0x00               // NO action; Y cancelar el comando
#define PCD_AUTHENT           0x0E               // autenticaci�n de clave
#define PCD_RECEIVE           0x08               // recepci�n de datos
#define PCD_TRANSMIT          0x04               // Enviar datos
#define PCD_TRANSCEIVE        0x0C               // Enviar y recibir datos
#define PCD_RESETPHASE        0x0F               // reajustar
#define PCD_CALCCRC           0x03               // CRC calcular

//Mifare_One  Tarjeta Mifare_One comando palabra
#define PICC_REQIDL           0x26               // �rea de la antena no est� tratando de entrar en el estado de reposo
#define PICC_REQALL           0x52               // Todas las cartas para encontrar el �rea de la antena
#define PICC_ANTICOLL         0x93               // anti-colisi�n
#define PICC_SElECTTAG        0x93               // elecci�n de tarjeta
#define PICC_AUTHENT1A        0x60               // verificaci�n key A
#define PICC_AUTHENT1B        0x61               // verificaci�n Key B
#define PICC_READ             0x30               // leer bloque
#define PICC_WRITE            0xA0               // Escribir en el bloque
#define PICC_DECREMENT        0xC0               // cargo
#define PICC_INCREMENT        0xC1               // recargar
#define PICC_RESTORE          0xC2               // Transferencia de datos de bloque de buffer
#define PICC_TRANSFER         0xB0               // Guardar los datos en el b�fer
#define PICC_HALT             0x50               // inactividad

//MF522 C�digo de error de comunicaci�n cuando regres�
#define MI_OK                 0
#define MI_NOTAGERR           1
#define MI_ERR                2

//------------------ MFRC522 registro---------------
//Page 0:Command and Status
#define     Reserved00            0x00
#define     CommandReg            0x01
#define     CommIEnReg            0x02
#define     DivlEnReg             0x03
#define     CommIrqReg            0x04
#define     DivIrqReg             0x05
#define     ErrorReg              0x06
#define     Status1Reg            0x07
#define     Status2Reg            0x08
#define     FIFODataReg           0x09
#define     FIFOLevelReg          0x0A
#define     WaterLevelReg         0x0B
#define     ControlReg            0x0C
#define     BitFramingReg         0x0D
#define     CollReg               0x0E
#define     Reserved01            0x0F
//Page 1:Command
#define     Reserved10            0x10
#define     ModeReg               0x11
#define     TxModeReg             0x12
#define     RxModeReg             0x13
#define     TxControlReg          0x14
#define     TxAutoReg             0x15
#define     TxSelReg              0x16
#define     RxSelReg              0x17
#define     RxThresholdReg        0x18
#define     DemodReg              0x19
#define     Reserved11            0x1A
#define     Reserved12            0x1B
#define     MifareReg             0x1C
#define     Reserved13            0x1D
#define     Reserved14            0x1E
#define     SerialSpeedReg        0x1F
//Page 2:CFG
#define     Reserved20            0x20
#define     CRCResultRegM         0x21
#define     CRCResultRegL         0x22
#define     Reserved21            0x23
#define     ModWidthReg           0x24
#define     Reserved22            0x25
#define     RFCfgReg              0x26
#define     GsNReg                0x27
#define     CWGsPReg              0x28
#define     ModGsPReg             0x29
#define     TModeReg              0x2A
#define     TPrescalerReg         0x2B
#define     TReloadRegH           0x2C
#define     TReloadRegL           0x2D
#define     TCounterValueRegH     0x2E
#define     TCounterValueRegL     0x2F
//Page 3:TestRegister
#define     Reserved30            0x30
#define     TestSel1Reg           0x31
#define     TestSel2Reg           0x32
#define     TestPinEnReg          0x33
#define     TestPinValueReg       0x34
#define     TestBusReg            0x35
#define     AutoTestReg           0x36
#define     VersionReg            0x37
#define     AnalogTestReg         0x38
#define     TestDAC1Reg           0x39
#define     TestDAC2Reg           0x3A
#define     TestADCReg            0x3B
#define     Reserved31            0x3C
#define     Reserved32            0x3D
#define     Reserved33            0x3E
#define     Reserved34                0x3F
//-----------------------------------------------

class RFID
{
  public:
    RFID(int chipSelectPin, int NRSTPD);

    bool isCard();
    bool readCardSerial();

    void init();
    void reset();
    void writeMFRC522(unsigned char addr, unsigned char val);
    void antennaOn(void);
    unsigned char readMFRC522(unsigned char addr);
    void setBitMask(unsigned char reg, unsigned char mask);
    void clearBitMask(unsigned char reg, unsigned char mask);
    void calculateCRC(unsigned char *pIndata, unsigned char len, unsigned char *pOutData);
    unsigned char MFRC522Request(unsigned char reqMode, unsigned char *TagType);
    unsigned char MFRC522ToCard(unsigned char command, unsigned char *sendData, unsigned char sendLen, unsigned char *backData, unsigned int *backLen);
    unsigned char anticoll(unsigned char *serNum);
    unsigned char auth(unsigned char authMode, unsigned char BlockAddr, unsigned char *Sectorkey, unsigned char *serNum);
    unsigned char read(unsigned char blockAddr, unsigned char *recvData);
    unsigned char write(unsigned char blockAddr, unsigned char *writeData);
    void halt();

    unsigned char serNum[5];       // Constante para guardar el numero de serie leido.
    unsigned char AserNum[5];      // Constante para guardar el numero d serie de la secion actual.

  private:
    int _chipSelectPin;
    int _NRSTPD;

};

#endif

Using the code I have now I can read RFID data, and read them via the Serial monitor.
Now, if I want to write RFID numbers to a card, can I do this with this library, or what other library should I use that is capable of writing?

The library you refer to is called RFID by Miguel Balboa.
It is equipped with several examples showing you how to read and write data. Check them out.
If you are looking for some more background information on what happens when you write data on a tag, check out the first video of of the MakeCourse of the University of South Florida.
At 21:30 it explains how to write data.

source: Stack Exchange

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

sort: votes


text:
connecting GSM 900A module to arduino
I am trying to connect my arduino uno to GSM 900A with the help of this tutorial https://elementztechblog.wordpress.com/2014/10/10/interfacing-sim900a-gsm-modem-with-arduino/
but the calling is not being carried out.
The serial output is as following:
Calling through GSM Modem
Called
ÿÿÿÿ

and the code is
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()

{

  Serial.begin(9600);
  Serial.println("Calling through GSM Modem");

  mySerial.begin(9600);
  delay(2000);
  mySerial.println("ATD99abc19965;");
  mySerial.println("ATH");
  Serial.println("Called ");
}

void loop()
{

  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
}

You're really missing multiple parts here...
Check out this tutorial: http://tronixstuff.com/2014/01/08/tutorial-arduino-and-sim900-gsm-modules/

First of all, did you power up the SIM900A using its PWRKEY pin?
And can you send and receive AT commands?

How do you know that you have a valid GSM connection?
Did you try AT+CREG? and AT+CPIN?

Do you understand the AT commands you send?

You send ATD (with abc in the number?) and after that you immediately send ATH. Thus you would hang up directly after calling, and probably wouldn't even get to the actual calling part.

#include <SoftwareSerial.h>

SoftwareSerial sim900Serial(10, 11); // RX, TX

void setup()
{
   Serial.begin(9600);
   Serial.println("Calling through GSM Modem");
   sim900Serial.begin(9600);
   delay(2000);
   sim900Serial.println("ATD99abc19965;");
   delay(10000);
   sim900Serial.println("ATH");
   Serial.println("Call ended ");
}

void loop() {
   if (mySerial.available()){
      Serial.write(mySerial.read());
   }
}

Also, your code isn't very well formatted. Compare the code above with yours.

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


text:
WebCam Face detection and tracking tutorial with Arduino Uno R3 and OpenCV 3.0 RC1 in Ubuntu 14.04
I try to make this Arduino Open CV tutorial for webcams. OpenCV 3.0 RC1 is compiled and installed. I also use Code::Blocks 13.12 as IDE. I am a newbie what comes to OpenCV and I do not know too much about Arduino either but here I am learning. Arduino IDE is 1.7.2. The tutorial is made for Windows 7 and software for this OS but I bet it is possible to repeat this in Ubuntu Linux 14.04 also.
So the tutorial is here:
http://duino4projects.com/face-detection-and-tracking-with-arduino-and-opencv/
When I try to compile and run the techbitarFaceDetection.cpp
the Code::Block IDE gives me following error:

fatal error: Tserial.h: No such file or directory

So please tell me what to do next and how to fix this error.

Forget Tserial.h lib. To solve your problem (for serial communication) I sugest you to use "read/write from/to a file" programming method. The serial ports may be written to just like you are writing in a file. In the facedetect.cpp (OpenCV's example), in the detectAndDraw() function (I'm using OpenCV 3.0) add: unsigned char MSB[1] = {0}; //
    unsigned char LSB[1] = {0}; //
    char serialPortFilename[]="/dev/ttyACM0";
    FILE *serPort = fopen(serialPortFilename, "w"); //
than add:
LSB[0]=r->x & 0xff;//
    MSB[0]=(r->x >>8) & 0xff;//

    fwrite((const void*)MSB,sizeof(unsigned char),sizeof(MSB),serPort);//
fwrite((const void*)LSB,sizeof(unsigned char),sizeof(LSB),serPort);//

LSB[0]=r->y & 0xff;//
    MSB[0]=(r->y >>8) & 0xff;//

    fwrite((const void*)MSB,sizeof(unsigned char),sizeof(MSB),serPort);//
    fwrite((const void*)LSB,sizeof(unsigned char),sizeof(LSB),serPort);//

into the if (0.75 < aspect_ratio && aspect_ratio < 1.3) statement.
Finally don't forget to close the file
fclose(serPort);

Hope this will work for you!

TSerial.h is part of the Serial C++ Library that is used by the project that you are trying to build (see the section "Software Required" on the tutorial page you linked).
Make sure you have that library installed correctly.


text:
Programmed 5 Volt output to power a relay
I need to put out 5 volts from an Arduino UNO digital pin. I've read that the pins can do approx. 5 volts, but I need to know if it will actually reach 5. I'm also powering a few other devices from the Arduino.
Are the digital pins capable of emitting 5 volts consistently? Are there any better alternatives?
Thanks.

A 2n7002 MOSFET - 15 cents in 1's at Digikey wilol allow you to drive 50-100 mA wit =h no other parts (maybe a catch diode oj the coil). A BC337 transistor will drive hundreds on mA of load (needs one resistor). NEVER drive a relay directly from a processor pin - even if you can. Too much to go wrong - uC dies ....

Your concern for the output capability of the pin should be its current sourcing or sinking capability, not its voltage. Arduino pins typically have a limit of 40ma per pin and a total maximum of 200ma. This is for the Atmega328p (you didn't say which Arduino you're using. You'll need to drive motors or relays or anything else with a substantial current requirement with a driver circuit powered independently of the Arduino itself. That can be with a shield made for the purpose or a circuit you design and build into your project. Motors and relays in particular need snubber diodes to protect the driving circuits from inductive "kickback" or spikes generated in their coils.

Note that the 40mA is the absolute maximum and isn't guaranteed.  For sustained reliable usage you shouldn't exceed 25mA.  Also the 200mA is the total for all IO pins combined.


text:
Arduino Keyboard - print() works but println() does not
I am recently seeing strange behavior in my Arduino Yun.
Just using the microcontroller, I enter the following:
#include <stdlib.h>
#include <string.h> // For string operations.
#include "Keyboard.h"
#include "Mouse.h"

void setup() {
  Keyboard.begin();
  Keyboard.println("Hello world.");
  Keyboard.print("Hello world.");
}

Rather than getting two lines as expected, I get Hello world.Hello world..
It is a very strange error because println (docs) is so 'core' to Keyboard function. I've never had this issue before and I've been playing with it for months. I am running IDE 1.6.11.
A possibly relevant detail
I had this working on my Yun months ago without the #include "Keyboard.h" and #include "Mouse.h". I opened the IDE again just recently and, upon compiling, it failed saying I needed to add those lines. So I did, and it now println doesn't work.

There are semi colons missing at the end of the print statement, is that just a typo?

How are you receiving this?   It may well be that the keyboard emulation is in fact sending a return or newline, and your receiving program isn't interpreting that in the way that you like.  That "." in your received output could be a control character, try to get a hexdump or better yet, look at raw scancodes rather than character interpretations.  Also look at the documentation (or failing that sourcecode) and see if the println() method is documented to do anything useful for this class.

@ChrisStratton You can see the periods in the output in my input, and the periods don't have any effect on this bug. If I leave them out, we still get no newline/carriage return.

@ChrisStratton I've added a link to the println docs in the question.

Again, state how you are capturing the output

@ChrisStratton The output is keyboard commands outputted to the computer the device is attached to (like a standard Arduino keyboard). I'm using OS X TextEdit. When it works (as it has before), you get Hello world. and the cursor moves to the next line. Now that it isn't, the cursor sits at the end of the statement.

I've never had this issue before and I've been playing with it for months. - on the Yun? It's been working for months and now it isn't?

Please test: Keyboard.print("Hello world.\n");

Also try on another PC. It is possibly a configuration issue on OS/X. When it works ... you get Hello world. and the cursor moves to the next line. - the library hasn't changed, right? So maybe the testing environment changed.

@NickGammon That works. println still doesn't.

@NickGammon Yes, on the Yun. I had it working but now it isn't - I honestly don't know why. There is one thing that may be relevant - I'm going to include it in my question now.

Please test: Keyboard.print("Hello world.\n");

...

That works. println still doesn't.

I'm going to guess here that println is doing something odd in the Yun libraries. I note that the Keyboard.cpp file in my release has this in it:
#define SHIFT 0x80
const uint8_t _asciimap[128] =
{
    0x00,             // NUL
    0x00,             // SOH
    0x00,             // STX
    0x00,             // ETX
    0x00,             // EOT
    0x00,             // ENQ
    0x00,             // ACK
    0x00,             // BEL
    0x2a,           // BS   Backspace
    0x2b,           // TAB  Tab
    0x28,           // LF   Enter
    0x00,             // VT
    0x00,             // FF
    0x00,             // CR    <---------- note!

Notice that linefeed has a code mapped (0x28) but carriage return (CR) does not (unless you call 0x00 a mapping).
I think you'll find that when you hit Enter on a keyboard it is sending a CR (after all, it used to be labelled the "return" key) and not a LF.
However I thought that the Print class outputted both:
size_t Print::println(void)
{
  return write("\r\n");
}

Maybe yours doesn't. I'm not certain which exact println will be pulled in for a Yun. The fact that it used to work, and now doesn't, suggests a change there somewhere.


text:
Atmega328P-PU: Programmer is not responding
Few days ago, I built my own custom Arduino on the breadboard. It is built according to tutorial on http://www.crash-bang.com/resource/breadboard-arduino/. The Atmega328P-PU is already burned with the Arduino bootloader with simple blink sketch.
For the programmer, I decided to use the Arduino USB2Serial. Again, it is connected as shown on crash-bang site. Problem is I get this error when uploading a different sketch:
avrdude -Cavrdude.conf -v -patmega328p -carduino -PCOM3 -b115200 -D -Uflash:w:build244630154737317489.tmp/sketch_may23a.cpp.hex:i

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
     Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
     Copyright (c) 2007-2009 Joerg Wunsch

     System wide configuration file is "avrdude.conf"

     Using Port                    : COM3
     Using Programmer              : arduino
     Overriding Baud Rate          : 115200
     AVR Part                      : ATmega328P
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PC2
     RESET disposition             : dedicated
     RETRY pulse                   : SCK
     serial program mode           : yes
     parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     ByteDelay                     : 0
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                              Block Poll               Page                       Polled
       Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
       flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
       lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

     Programmer Type : Arduino
     Description     : Arduino
     Hardware Version: 3
     Firmware Version: 4.4
     Vtarget         : 0.3 V
     Varef           : 0.3 V
     Oscillator      : 28.800 kHz
     SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: reading input file "build244630154737317489.tmp/sketch_may23a.cpp.hex"
avrdude: writing flash (450 bytes):

Writing | avrdude: stk500_recv(): programmer is not responding

Most of the time I do not even get to this point and just end up with something like:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xf5

What I have done so far:

I already tried to reset Arduino just before uploading the sketch.
According to the avrdude, bootloader is fine.
Reinstalled drivers, Arduino IDE
Changed the USB cable and connected it to another USB slot
Burned new bootloader using ArduinoISP

Thank you for help.

Is there a reason why you don't want to stick with ISP?

This would require to buy another programer, would not it? I hope someone could know the solution to get current programmer to work...

"Step 3 says to connect +ve rail –> AVCC (pin 20) and +ve rail –> AREF (pin 21). You can leave those pins not connected. "
+ve rail should not be connected to Aref. The +ve rail will connect via the internal operation of the ADC mux.
AVCC and both Gnds should be connected per the datasheet:
5.2.7. AVCC
AVCC is the supply voltage pin for the A/D Converter, PC[3:0], and PE[3:2]. It should be externally connected to VCC, even if the ADC is not used.
28.2.
AVCC must not differ more than ±0.3V from VCC.... Optionally, AVCC or an internal 1.1V reference voltage may be connected to the AREF pin by writing
to the REFSn bits in the ADMUX Register. The internal voltage reference must be decoupled by an external capacitor at the AREF pin to improve noise immunity.
If you connect Aref to the +ve rail externally, and then select the internal reference, things can go bad.
FTDT thru 0.1uF cap to Reset, with 10K pullup, and reverse biased diode to VCC, works for me in plenty of designs.  Not sure why it does not work in all cases. The diode dissipates any spike on the Reset line to keep the chip from thinking high voltage programming mode is being started.


text:
Unable to send serial data to XBee connected to Arduino Uno without a shield
So here are some pictures of the setup I have with an LED, 330 Ohm resistor, Arduino UNO, 2 XBee S1s, and many wires,
https://i.sstatic.net/QT1KF.jpg
For specifics, here is the wiring,

XBee Pin 1 (VCC) is connected to Arduino Uno Pin 3.3V
XBee Pin 2 is connected to Arduino Uno Pin 1 (TX)
XBee Pin 3 is connected to Arduino Uno Pin 0 (RX)
XBee Pin GND is connected to the minus column on the breadboard.
Arduino Uno Digital Pin 9 is connected to a 330 ohm resistor which is connected to an LED that is connected to the minus column on the breadboard
Arduino Uno Pin GND is connected to the minus column on the breadboard
And lastly I have another XBee connected to my laptop through a USB dongle

I'm trying to send data in the form of bits through my computer using a program called XCTU to turn the LED on and off. Here is the code for the Arduino,
int led = 9;
int bufferSize = 100;
byte readBuffer[100];
byte lastByte = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  digitalWrite(led, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  int toRead = Serial.available();
  if(toRead > 0){
    while(toRead > bufferSize){
      Serial.readBytes(readBuffer, bufferSize);
      toRead = toRead - bufferSize;
    }

    Serial.readBytes(readBuffer, toRead);
    lastByte = readBuffer[toRead - 1]; //reads last big in serial input

    if(lastByte == '1'){
      digitalWrite(led, HIGH);
    }
    else if(lastByte == '0'){
      digitalWrite(led, LOW);
    }
  }
  delay(250);
}

However, when I send a '0' through XCTU, the LED doesn't turn off. What could be causing this? Note that I did not use a shield to connect the XBee to the Arduino Uno, I soldered the pins to the appropriate spots because I thought it was possible after watching this video,
https://www.youtube.com/watch?v=wtal7SWZek0
Also, I will be cross-posting this on arduino forums to get as much input on this as possible. I will update both topics frequently to attribute answerers for their input (https://forum.arduino.cc/index.php?topic=435027.msg2998240#msg2998240)

There's a whole lot missing here.  I'd be helpful to know what you've tried to debug it.  For instance, do you know that the xbees are talking to each other, etc.  I would start by uploading a program to the uno that prints a string and then open the serial port on your computer and make sure you're seeing that string.  That will confirm they are talking to each other and that you haven't reversed rx and tx.

@mwwalk I've tried what you suggested and I was unable to see the string. I tried reversing rx and tx many times but i haven't been quite successful. I know that both XBees are active because I was able to use the dongle to connect both of them to the computer (one at a time).

So after experimenting with the SoftwareSerial library, it seemed that all the wiring was done correctly but the original code was replaced with,
#include "SoftwareSerial.h"

SoftwareSerial XBee(1, 0); //TX is 1, RX is 0 on the Arduino Uno
int LED = 9;

void setup()
{
  // Baud rate MUST match XBee settings (as set in XCTU)
  XBee.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop()
{
  if (XBee.available())
  {
    byte c = XBee.read();
    if (c == '1')
    {
      digitalWrite(LED, HIGH);

    }
    else if (c == '0')
    {
      digitalWrite(LED, LOW);
    }
  }
  delay(150);
}

and I am now able to turn an LED on or off with data sent from XCTU.
Note: I forgot to include this in my question but some configuration details were that the XBees I was working with were "XBee 1mW Wire Antenna - Series 1 (802.15.4)". Settings for each XBee configured in XCTU include,
Baud Rate: 9600
Data Bits: 8
Stop Bits: 1
no Parity nor flow control
Channel and Pan ID were identical across both XBees
For the XBee connected to the laptop,
DH = 0, DL = 2, MY = 1, and CE = Coordinator[1]
For the XBee connected to the Arduino Uno,
DH = 0, DL = 1, MY = 2, and CE = End Device[0]
*Credit to user PaulS on the arduino forum for helping me out.


text:
I'm able to send messages from SIM800a module and receive "+CMGS: 177 Ok" but I'm not able to receive it in the number entered in the code
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
char msg;
char call;

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println("GSM SIM900A BEGIN");
  Serial.println("Enter character for control option:");
  Serial.println("h : to disconnect a call");
  Serial.println("i : to receive a call");
  Serial.println("s : to send message");
  Serial.println("r : to receive message");
  Serial.println("c : to make a call");
  Serial.println("e : to redial");
  Serial.println();
  delay(100);
}

void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
      SendMessage();
      break;
    case 'c':
      MakeCall();
      break;
    case 'h':
      HangupCall();
      break;
    case 'e':
      RedialCall();
      break;
    case 'i':
      ReceiveCall();
      break;
    case 'r':
      ReceiveMessage();
      break;

  }
 if (mySerial.available()>0)
 Serial.write(mySerial.read());
}

void SendMessage()
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+917018483787\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println("sim900a sms");// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

void ReceiveMessage()
{
  mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
  delay(1000);
  if (mySerial.available()>0)
  {
    msg=mySerial.read();
    Serial.print(msg);
  }
}

void MakeCall()
{
  mySerial.println("ATD+917018483787;"); // ATDxxxxxxxxxx; -- watch out here for semicolon at the end!!
  Serial.println("Calling  "); // print response over serial port
  delay(1000);
}

void HangupCall()
{
  mySerial.println("ATH");
  Serial.println("Hangup Call");
  delay(1000);
}

void ReceiveCall()
{
  mySerial.println("ATA");
  delay(1000);
  {
    call=mySerial.read();
    Serial.print(call);
  }
}

void RedialCall()
{
  mySerial.println("ATDL");
  Serial.println("Redialing");
  delay(1000);
}

please format your code ... it is not readable the way you presented it

what is the exact problem that you are seeing ... you did not ask a question, so it is unclear what you want to know

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


text:
Can i combine an ultrasonic sensor and gps together?
I need to operate 2 different sensors by Arduino UNO: GPS module and Ultrasonic sensor. I have managed to run each one of them separately and I don't know how to manipulate the code;
GPS MODULE
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 4, TXPin = 3;
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(9600);
  ss.begin(GPSBaud);
}

void loop()
{
  // This sketch displays information
  // every time a new sentence is correctly encoded.
  while (ss.available() > 0)
  {
    gps.encode(ss.read());
    if (gps.location.isUpdated())
    {
      Serial.print("Latitude= ");
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= ");
      Serial.println(gps.location.lng(), 6);
    }
  }
}

ULTRASONIC SENSOR
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;

// defines variables
long duration;
int distance;
void setup()
{
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
}

void loop()
{
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

  // Calculating the distance
  distance= duration*0.034/2;

  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
}

That's easy. I have no possibility to try it. But if your code has been working, this will also. (Just copy/paste.) I had to change the while loop into a if block, because I was not sure, if the while blocks for a longer time. It could have been that the GPS sends and sends and sends ... That would block the ultrasonic sensor.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

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

const int trigPin = 9;
const int echoPin = 10;

long duration;
int distance;

void setup()
{
  Serial.begin(9600);
  ss.begin(GPSBaud);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop()
{
  // This sketch displays information
  // every time a new sentence is correctly encoded.
  if (ss.available() > 0)
  {
    gps.encode(ss.read());
    if (gps.location.isUpdated())
    {
      Serial.print("Latitude= ");
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= ");
      Serial.println(gps.location.lng(), 6);
    }
  }

  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

  // Calculating the distance
  distance= duration*0.034/2;

  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
}

Thank you for your respond and help sir. But i do have some problems in the output. The gps coordinate does not show

@AfiqAzmii I'd showed you how to combine the two sketches. That's what you have been asking for. I can't tell you, why this doesn't work, because I don't know anything about the setup. I can not see any pictures of your project and the wiring and I have no link to the documentation of both sensors.  I even don't know which one you use. You did also not tell me, if the distance sensor works correctly.  As this is a complete new question, it would be better to add a new question or update the old one. If you add all the information I asked for, someone or me have a better chance to help you.

A I've seen you had already asked a new question. I'look into it.


text:
Can't get OC1B (pin 10) to output
I'm trying to get this program to use channel B for the output waveform using the phase correct PWM mode and using OCR1A as the top. With a 50% duty ratio I'm attempting to  get a 10 Hz freq. I'm able to adjust the OC1A (Pin 9) if I set TCCR1A to 0x43; but nothing comes from pin 10. Code:
include "avr/io.h"

void setup()
{
 DDRB = 0x6; //set pins 9 and 10 as output

 /*set operation Toggle mode; WGM13:0 = 1011 phase correct PWM
CS12:0 = 101 prescaler = 1024*/
 TCCR1A = 0x23;
 TCCR1B = 0x15;

 OCR1A = 0x187; //391 for 50% duty cycle
 TCNT1 = 0; //clear counter and update OCR1A
}
void loop()
{ }

It's much more readable to configure registers using bit operations like TCCR1A |= (1<<COM1A1);. Pin 10 refers to the arduino's pin 10?

Haven't looked into the spec but maybe you want to try setting OCR1AL = 0x87 and OCR1AH = 0x01 separately.

You are using Timer/Counter 1 in Fast PWM Mode with TOP set to OCR1A:
OCR1Aonly describes the number to what it counts up so, 0…391 in your case.
You have to define the duty cycle with OCR1B. 50% would be 195.


text:
Arduino Uno - Can' get LCD Display work crrectly
I make an automatic light that's triggered from a Visitor Counter. I use an LCD to show the actual counter state. The LCD does not anly show the actual count but also the numbers before. For Example:
If the counter is actual 2, it blinks between 1 and 2.
This behavior does not occur in the original project where the correct number is shown.
Please, can I know why, and how to fix it? Thank you!

This is the code:
//Visitors Counter and Automatic Room Light
//Viral Science  www.youtube.com/c/viralscience

#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);

#define in 14
#define out 19
#define relay 2

int count=0;

void IN()
{
    count++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}

void OUT()
{
  count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}

void setup()
{
  lcd.begin(16,2);
  lcd.print("Visitor Counter");
  delay(2000);
  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(relay, OUTPUT);
  lcd.clear();
  lcd.print("Person In Room:");
  lcd.setCursor(0,1);
  lcd.print(count);
}

void loop()
{

  if(digitalRead(in))
  IN();
  if(digitalRead(out))
  OUT();

  if(count<=0)
  {
    lcd.clear();
    digitalWrite(relay, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Light Is Off");
    delay(200);
  }

  else
    digitalWrite(relay, HIGH);

}

What is the actual program? What is the difference between the actual and your program? What is the code anyway?  And do you mean by blinking it shows alternately 1 and 2?  To fix it, probably you have to change the code, or the circuit, but high likely the code. But this 'answer' is as vague as your question I'm afraid.

Yes sir @Michel Keijzers it keep blinking and shows alternately 1 and 2 . I will try compile a new coding and see what happen . Thank you sir !

Please add the code ( that is not working ) to the question. You asked why the code does not work and how to fix it. To answer we must know it. Simply, writing new code seems not to be the best strategy. Perhaps it works, but then you don't know why the first code did not. Or it does not work; what will you do then? Please do not report that your second code does also nor work, without showing it here. We can not guess what you have programmed so far.

I suggested to change the text and the title of the question as I edited it. If I understood it correctly, please accept die update. It hopefully make the question more understandable.  (Although my English is bad.) I have not access to your code, so it remains to you to add it to make the question a lot more understandable.

No, please do not add the code to a comment. Just edit your question and add it at the end of your question. Then mark the code completely and press the {} button of the online editor. You'll get well formatted code. You have not enough space in a comment. And the code should be part of the question.

The code you added is the original code from https://www.viralsciencecreativity.com/post/arduino-visitors-counter-automatic-light from which you said it would work. If you want us to find the error you made, we need to see your code, that might be wrong. So please add the code you have changed, and that does NOT work. And the code from the video only works if you have separate doors. One to go in and one to go out. If you pass the two sensors in one door you get an in and an out event. If I didn't missed anything. ;-)

If you want to say that it works in the video but not for you, than it is perhaps because the author did a trick. He uses a plank to disable both sensors at the same time. Then he moves the plank to only activate one sensor. It depends on which sensor is released , whether the counter was increased or decreased. He simulates the two doors I mentioned. And he had to doo this within one second. Or the counter remains increasing or decreasing.

For what ever reason IN() and OUT() get called at the same time. I see no obvious mistakes in the code, do I assume it has something to do with your setup. But your approach won't work anyway, because IN(( and OUT() will get called as lang as a person enters/leaves. What you need is to detect signal edges rather than levels (or does your sensor detect s.o.passing by and generate such a signal?)

So what i can do to eliminated the blinking effect on the lcd based on the infrared sensors detection?


text:
Grid based maze - robot stops at every square
I need a little bit of help.
I'm working on a school project where a robot with 3 ultrasonic sensors needs to go through grid based maze (5x5) and then draw its map.
But I got stuck. I'm trying to let the robot stop close to the center of a square, let it ping the position of obstacles, write out the positions and then let it choose the next direction where to go.
I tried it with the ollowing code, but without any success.
(main part is in loop function)
#include <AFMotor.h>
#include <elapsedMillis.h>
#include <NewPing.h>
#include <MPU6050_tockn.h>
#include <Wire.h>

#define SONAR_NUM 3
#define TRIGGER_PIN 45
#define ECHO_PIN 44
#define L_TRIG_PIN 36
#define L_ECHO_PIN 37
#define R_TRIG_PIN 30
#define R_ECHO_PIN 31
#define MAX_DISTANCE 200
#define eps 5.0
#define PING_INTERVAL 250

unsigned long pingTimer[SONAR_NUM];
unsigned int cm[SONAR_NUM];
uint8_t currentSensor = 0;

MPU6050 mpu6050(Wire);
AF_DCMotor motorL(3);
AF_DCMotor motorR(4);

NewPing sonar[SONAR_NUM] = {
  NewPing( R_TRIG_PIN, R_ECHO_PIN, MAX_DISTANCE ),
  NewPing( L_TRIG_PIN, L_ECHO_PIN, MAX_DISTANCE ),
  NewPing( TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE  )
};

long timer = 0;
bool WallRight, WallLeft, WallFront,WallBack,
     Turned180, TurnedLeft, TurnedRight;
int Distance = 0, modulo;
// Direction 1: front, 2: right, 3: back, 4: left
int Direction = 2;
int x = 0;
int y = 0;
int dx = 1;
int dy = 0;
float Angle, NewAngle;
long TimerFront = 0;
long StopTimer = 0;

struct Array {
  bool Left;
  bool Right;
  bool Front;
  bool Back;
  int StrucDirection;
};

Array Map[5][5];

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

  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);

  motorL.setSpeed(85);
  motorR.setSpeed(80);

  pingTimer[0] = millis() + 75;
  for ( uint8_t i = 1; i < SONAR_NUM; i++ )
  {
    // Set the starting time for each sensor.
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
  }

  Map[0][0].Left = true;
  Map[0][0].Right = true;
  Map[0][0].Front = false;
  Map[0][0].Back = true;
  Map[0][0].StrucDirection = 2;
}

void loop()
{
  // Loop through all the sensors.
  for (uint8_t i = 0; i < SONAR_NUM; i++)
  {
    // Is it this sensor's time to ping?
    if (millis() >= pingTimer[i])
    {
      // Set next time this sensor will be pinged.
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;

      // Make sure previous timer is canceled before
      // starting a new ping (insurance).
      sonar[currentSensor].timer_stop();

      // Sensor being accessed.
      currentSensor = i;
      // Make distance zero in case there's no ping echo for this sensor.
      cm[currentSensor] = 0;
      // Do the ping (processing continues,
      // interrupt will call echoCheck to look for echo).
      sonar[currentSensor].ping_timer(echoCheck);
    }
  }

  if ( ( modulo >= 7 ) && ( modulo <= 9 ) ||
       ( cm[2] < 7 && cm[2] > 0 ) )
  {
    if( millis() - StopTimer >= 1000 )
    {
      motorL.run(RELEASE);
      motorR.run(RELEASE);
      //Serial.println(dx);
      //Serial.println(dy);
      if( x + dx < 5 && x + dx >= 0 && y + dy < 5 && y + dy >= 0 )
      {
        x = x + dx;
        y = y + dy;
      }

      Obstacles();
    }
    DecideWhereNext();
    modulo = 0;
  }
}

void TurnLeft()
{
  for (uint8_t i = 0; i < SONAR_NUM; i++)
    pingTimer[i] = -1;

  mpu6050.update();
  motorL.setSpeed(150);
  motorR.setSpeed(145);
  Angle = mpu6050.getAngleZ();
  NewAngle = Angle + 86.0;
  //Serial.println(Angle);
  //Serial.println(NewAngle);

  while(abs(Angle - NewAngle) > eps)
  {
    if( millis() - timer > 50 )
    {
        mpu6050.update();
        Angle = mpu6050.getAngleZ();
        //Serial.println(Angle);
        timer = millis();
    }
    motorR.run(FORWARD);
    motorL.run(BACKWARD);

  }

  motorL.run(RELEASE);
  motorR.run(RELEASE);
  TurnedLeft = true;

  if(dy == 1)
  {
    dx=-1;
    dy=0;
    Direction = 4;
  }
  else if ( dy == -1 )
  {
    dx=1;
    dy=0;
    Direction = 2;
  }
  else if( dx == 1 )
  {
    dx=0;
    dy=1;
    Direction = 1;
  }
  else
  {
    dx=0;
    dy=-1;
    Direction = 3;
   }

   pingTimer[0] = millis();
   for (uint8_t i = 1; i < SONAR_NUM; i++)
     pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
}

void TurnRight()
{
  for (uint8_t i = 0; i < SONAR_NUM; i++)
    pingTimer[i] = -1;

  mpu6050.update();
  motorL.setSpeed(165);
  motorR.setSpeed(170);
  Angle = mpu6050.getAngleZ();
  NewAngle = Angle - 84.0;
  //Serial.println(Angle);
  //Serial.println(NewAngle);

  while( abs( Angle - NewAngle ) > eps )
  {
    if( millis() - timer > 50 )
    {
      mpu6050.update();
      Angle = mpu6050.getAngleZ();
      //Serial.println(Angle);
      timer = millis();
    }
    motorR.run(BACKWARD);
    motorL.run(FORWARD);
  }

  motorL.run(RELEASE);
  motorR.run(RELEASE);

  if( dy == 1 )
  {
    dx = 1;
    dy = 0;
    Direction = 2;
  }
  else if( dy == -1 )
  {
    dx = -1;
    dy = 0;
    Direction = 4;
  }
  else if( dx == -1 )
  {
    dx = 0;
    dy = 1;
    Direction = 1;
  }
  else
  {
    dx = 0;
    dy = -1;
    Direction = 3;
  }

  pingTimer[0] = millis();

  for (uint8_t i = 1; i < SONAR_NUM; i++)
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;

}

void Turn180()
{
  for (uint8_t i = 0; i < SONAR_NUM; i++)
    pingTimer[i] = -1;
  mpu6050.update();
  motorR.setSpeed(158);
  motorL.setSpeed(174);
  Angle = mpu6050.getAngleZ();
  NewAngle = Angle + 173.0;
  //Serial.println(Angle);
  //Serial.println(NewAngle);

  while(abs(Angle - NewAngle) > eps)
  {
    if( millis() - timer > 50 )
    {
        mpu6050.update();
        Angle = mpu6050.getAngleZ();
        //Serial.println(Angle);
        timer = millis();
    }

    motorR.run(FORWARD);
    motorL.run(BACKWARD);

  }

  motorL.run(RELEASE);
  motorR.run(RELEASE);

  if (dy == 1)
  {
    dx = 0;
    dy = -1;
    Direction = 3;
  }
  else if (dy == -1)
  {
    dx = 0;
    dy = 1;
    Direction = 1;
  }
  else if (dx == 1)
  {
    dx = -1;
    dy = 0;
    Direction = 4;
  }
  else if (dx == -1)
  {
    dx = 1;
    dy = 0;
    Direction = 2;
  }

  pingTimer[0] = millis();

  for (uint8_t i = 1; i < SONAR_NUM; i++)
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
}

void Forward()
{
  motorL.setSpeed(92);
  motorR.setSpeed(85);

  motorL.run(FORWARD);
  motorR.run(FORWARD);
}

void Obstacles()
{
  if (WallLeft)
  {
    Map[x][y].Left = true;
  }
  else
  {
    Map[x][y].Left = false;
  }

  if (WallRight)
  {
    Map[x][y].Right = true;
  }
  else
  {
    Map[x][y].Right = false;
  }

  if (WallFront)
  {
    Map[x][y].Front = true;
    Map[x][y].Back = false;
  }
  else
  {
    Map[x][y].Front = false;
    Map[x][y].Back = false;
  }

  Map[x][y].StrucDirection = Direction;

  Serial.print(" x:");
  Serial.print(x);
  Serial.print(" y:");
  Serial.print(y);
  Serial.print(" ");
  Serial.print(Map[x][y].Left);
  Serial.print(" ");
  Serial.print(Map[x][y].Right);
  Serial.print(" ");
  Serial.print(Map[x][y].Front);
  Serial.print(" ");
  Serial.print(Map[x][y].Back);
  Serial.print(" ");
  Serial.print(Map[x][y].StrucDirection);
  Serial.print(" ");
}

void echoCheck()
{
  if ( sonar[currentSensor].check_timer() )
  {
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;

    pingResult( currentSensor );
  }
}

void pingResult( uint8_t sensor )
{
  modulo = cm[2] % 30;
  //Serial.print("Pravy: ");
  //Serial.println(cm[1]);
  //Serial.print("Predni: ");
  //Serial.println(cm[2]);

  if (cm[0] > 13)
  {
    WallLeft = false;
    //Serial.println("Vlevo neni prekazka");
  }
  else if (cm[0] <= 13)
  {
    WallLeft = true;
    //Serial.println("Vlevo je prekazka");
  }

  if(cm[1] > 13)
  {
    WallRight = false;
    //Serial.println(cm[1]);
    //Serial.println("Vpravo neni prekazka");
  }
  else if (cm[1] <= 13){
    WallRight = true;
    //Serial.println(cm[1]);
    //Serial.println("Vpravo je prekazka");
  }

  if(cm[2] > 13)
  {
    WallFront = false;
    WallBack = false;
  }
  else if (cm[2] <= 13)
  {
    WallFront = true;
  }

}

void DecideWhereNext()
{

  if(!Map[x][y].Front && Map[x][y].Right )
  {
    Serial.println("Forward");
    Forward();

  }
  else if(!Map[x][y].Front && !Map[x][y].Left && Map[x][y].Right)
  {
    Serial.println("Forward");
    Forward();
  }
  else if(!Map[x][y].Front && !Map[x][y].Right)
  {
    Serial.println("Right");
    TurnRight();
    Forward();

  }
  else if(Map[x][y].Front && Map[x][y].Right && !Map[x][y].Left)
  {
    TurnLeft();
    Serial.println("Left");
    Forward();
  }
  else if (Map[x][y].Front && Map[x][y].Right && !Map[x][y].Left)
  {
    Turn180();
    Serial.println("Turning 180");
    Forward();
  }

}

I'm using the NewPing library also and I tried to stop the pings of the sensors while the robot is turning with the following code:
for (uint8_t i = 0; i < SONAR_NUM; i++)
  pingTimer[i] = -1;

and start pings again with:
pingTimer[0] = millis();
for (uint8_t i = 1; i < SONAR_NUM; i++)
  pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;

as it was documented here.
I did not manage to start the pings again, so if anyone would be so kind and helped me, I would be very grateful.

what does this mean? I tried to stop the sensors ............. this is a very poor description of the observed behavior without any success .... please describe what actually happens

please add information to your question ... please do not use comments


text:
How to Set Sensor Data Parameters?
Good day! How to set sensor Data parameters?
Like the data only set for example it starts with minimum value of 3 and ends with maximum value of 6 and it will turn on led 1 and if minimum value of 1 and maximum value of 2 turn on led 2 just like that?
My actual code for that:
float basa = scale.get_units();
if( basa >= 4 )
{
  digitalWrite(led1, HIGH);
}
else if( basa >= 2 )
{
  digitalWrite(led2, HIGH);
}

This code shows that if ever it reaches value of 4 the value of 2 will react also so my question is how set sensor data value like it will only react Value1 - Value2 like that.
thank you

2 will not react

I don't understand, what your problem is. Please describe it more

Do you really see, that both LEDs get turned on, when basa >= 4? The logic of your if statements seems to be correct. If basa >= 4, the first condition will execute and LED1 will be turned on. The second condition will not execute, because it is in an else statement, where the if statement already evaluated true. Do you reset the LEDs somewhere else in your code? If not, you might see, that the values from your scale simply go up and pass both intervals. If only the first measurement is in the interval between 2 and 4, and the second is over 4, the code will light up both LEDs

For example:
float basa = scale.get_units();

digitalWrite(led1, LOW);
digitalWrite(led2, LOW);

if( basa >= 2 && basa < 4 )
{
  digitalWrite(led2, HIGH);
}

if( basa >= 4 )
{
  digitalWrite(led1, HIGH);
}

EDIT: as suggested by @chrisl (see comments)
If understand you problem correctly, you try to light up 2 LEDs according to the value you read from a scale. IMHO you want to assign three intervals (ranges) like so:
(-INF, 2) : none of the LEDs is switched on
[2, 4)    : only LED 2 is switched on
[4, +INF) : only LED 1 is switched on

[x or x] means the x belongs to the interval.
(x or x) means the x does not belong to the interval.
+INF and -INF are the positive or negative infinity.

My code does the following:
I use the observation, that the intervals do not intersect and the union of the intervals are the complete real number space. (Although your scale has a more narrow range: (0-?kg). The program can handle a wider range compared to the the scale, so it is not a problem.)
If the first condition (-INF, 2) is true, none of the others would be and we can be sure that the LEDs I switched off with the digitalWrite(ledX, LOW);
 statements will stay off. If the value is in the range of [2, 4) I switch on LED2 and can be sure that the other LED stays off because the condition basa >= 4 can not be true. And if the value is in the range of  [4, +INF) I switch on LED1 and can be sure that LED 2 has not been switched on because the condition basa >= 2 && basa < 4 can not be true.

I would say this does exactly the same as the OPs code, except for the digitalWrite(ledX, LOW) calls. Please explain more how this solves the OPs problem (whatever that problem actually is)

@chrisl OP wants when value is 2 turn on an LED and when it's 4 another. but in OP code when it's 4, 2 condition also applies. so Peter approach is correct. if it's bigger than 2 and less than 4 is what OP exactly wants.

@chrisl You're right, I should have explained the solution, but it was late last evening ;-). I'll edit the answer and add my understanding of the problem also. Btw, my code differs not only in the digitalWrite(ledX, LOW) statements. I removed the else and so I decoupled the two cases and I used a range [2,4) for the first case. The < 2 case is implicitly handled by the digitalWrite(ledX, LOW) statements.

@ElectronSurf No, in the OPs code, when basa >= 4 only the first condition applies and thus only led1 is turned on. The second condition is not executed in that case, because it is in an else statement. The code only comes to that condition, when basa < 4. Peter Paul Kiefer added the case for basa < 2 and decoupled the if statements (which could be seen as an improvement).

@chrisl "if ever it reaches value of 4 the value of 2 will react" what I said was based on OP explanation.

@PeterPaulKiefer, you missed the 'else' in OP's snippet?

@Juraj I did not missed the else; I removed it. For me it was one of the means to achieve what I thought the OP had asked for. Have I interpreted the OPs question right? Only the OP can told us. But I fear he stopped the collaboration ;-).

thanks pal appreciated it


text:
Thermal Printer - Qrcode
I am trying to print QRcode (not bitmap) on my thermal printer with Arduino and ESP32.
I am using the same QRcode library and Adafruit Thermal printer library of this post.
How to scale a bitmap (uint8_t array) in Arduino?
Is it possible to convert the pixel coordinates + color to a bitmap or print the pixel(x,y, color)?
Thanks for all

I need some code to print a QRcode. I am using this code to my oled display.
static uint8_t buffer[QR_VERSION_BUFFER_SIZE(7)] = { 0 };

QRCode qrcode = { 0 };
const int8_t error = qrcode_initText(&qrcode, buffer, 7, 0, "1245");
ASSERT_DEBUG_MODE(0 == error);

const uint8_t y0 = 10;
const uint8_t x0 = 10;

for (uint8_t y = 0; y < qrcode.size; y++)
{
    for (uint8_t x = 0; x < qrcode.size; x++)
    {
        uint8_t pixel = 0;
        if(qrcode_getModule(&qrcode, x, y) )
        {
            /*Put black pixel*/
            pixel = 0;
        }
        else
        {
            /*White pixel*/
            pixel = 1;
        }

        HI_GFX_Draw_Pixel(x0 + x, y0 + y, pixel);

    }

}

Honestly I don't understand what you mean. Please explain more and include your code. Explain, what exactly in that code is the problem

Read the README of that library in the API section. Where it uses Serial.print use whatever pixel drawing function you have.

Add the code that I am using to print the QRcode on the screen. I don't know a function for print a pixel.


text:
Arduino ds3231to TM1638 problems,alarm clock project
Good morning,
I am coding an alarm clock on arduino by using a DS3231 and a TM1638.
The code works and the time updates in the serial monitor,although the time doesn't update on the tm1638.
I'll attach the code here:
#include <DS3231.h>
#include <TM1638.h>
#include <Streaming.h>
#include <SPI.h>
#include <Wire.h>
#include <InvertedTM1638.h>
#include <TM1638.h>
#include <TM1638QYF.h>
#include <TM1640.h>
#include <TM16XX.h>
#include <TM16XXFonts.h>
byte buttons;
#define TM1638_STB D5
#define TM1638_CLK D6
#define TM1638_DIO D7

TM1638 module(TM1638_DIO, TM1638_CLK, TM1638_STB);
// DS3231 uses I2C - device ID 0x68
// on Wemos mini pins SDA -> D1 and SCL -> D2
DS3231 rtc;
int hours;
int minutes;
int seconds;
bool h12;
bool PM;
int data;
RifTime t;
char buffer[24];

void setup()
{
  // set up the 7-segment display
  module.clearDisplay();
  module.setupDisplay(true, 2);
  Wire.begin();
  Serial.begin(115200);

  Serial.println(F("\nDS3231 Hi Precision Real Time Clock"));

  // Fill these variables with the date and time.
  int seconds, minutes, hours, dayofweek, dayofmonth, month, year;

  // Example for april 15, 2013, 10:08, monday is 2nd day of Week.
  // Set your own time and date in these variables.
  // dayofweek = 4; // Day of week, any day can be first, counts 1...7
  hours = 14;
  minutes = 30;
  seconds = 0;
  year = 2019;
  month = 8; // month 1...12
  dayofmonth = 28; // Day of month, 1...31

  data=( hours * 10000 + minutes * 100 + seconds * 1 );

  rtc.setClock(year,month,dayofmonth,hours,minutes,seconds);
}

void loop()
{
  rtc.getTime(t);
  Serial << rtc.toString(buffer) << endl;

  delay(1000); // do nothing

  module.setDisplayToDecNumber(data,4,false);

  if(seconds==60)
  {
    seconds=00;
    minutes++;
  }
  if(minutes==60)
  {
    minutes=0;
    hours++;
  }

  if(hours==24)
  {
    data=00000000;
  }

  if((data)==143000)
  {
    module.setLEDs(0x0001);
  }
  else
  {
    module.setLEDs(0x0000);
  }

}

You set the variable data only in the setup function.
You also do not print out data to Serial but the output of rtc.toString(buffer).
If data is not updated in the loop method, the display constantly shows the time you initially set in the setup method.


text:
RS485 communication problem
I'm trying to achieve RS485 communication between Arduino Mega and Arduino UNO as specified in following link:
https://www.engineersgarage.com/arduino/rs485-communication-between-arduino-mega-and-arduino-pro-mini
But now my problem is The master i.e. Arduino Mega doesn't print anything on Serial Monitor.
Please help me out to solve this issue, trying from week still no success.

Sir Peter Paul Kiefer,
Im attaching my circuit setup

Master Code/Mega code
void setup()
{
  //Using Serial1 Port
  Serial1.begin(9600);
  Serial.begin(9600);

  //DE/RE Controling pin of RS-485
  pinMode(8, OUTPUT);
}

void loop()
{
  char getdata='m';

  //DE/RE=HIGH Transmit Enabled M1
  digitalWrite(8,HIGH);

  //Write '9' and Fetch Data From Pro Mini
  Serial1.print('9');

  //DE/RE=LOW Receive Enabled M1
  digitalWrite(8,LOW);
  delay(1000);

  //If Serial Data is available
  if(Serial1.available())
  {
    while( Serial1.available() && getdata!='d' )
    {
      getdata=Serial1.read();
      Serial.print(getdata);
    }

    Serial.println("");
  }
}

Slave code
void setup()
{
  //Serial1.begin(9600);//Uncomment for Arduino Lenardo
  Serial.begin(9600);
  //while(!Serial1);//Uncomment for Arduino Lenardo

  //Led Connected
  pinMode(13, OUTPUT);

  //DE/RE Controling pin of RS-485
  pinMode(8, OUTPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
  char getdata='c';

  //Led OFF
  digitalWrite(13,LOW);
  //DE/RE=LOW Receive Enabled
  digitalWrite(8,LOW);

  if(Serial.available())
  {
    getdata=Serial.read();
  }

  if(getdata=='9')
  {
     //DE/RE=HIGH Transmit Enabled
     digitalWrite(8,HIGH);

     Serial.print("AcruxTek");
     Serial.print("Isld");
  }

  delay(2000);
  //Led ON
  digitalWrite(13,HIGH);
  delay(2000);
}

I connected gnd of RS485 converter to arduino gnd and also i did common gnd between circuits but still no output. I used same code nothing changed.. except one thing the example uses arduino pro mini but i used arduino uno as slave

Sorry. The link doesn't work. And you did not specify your problem in any way. We can not help you with knowing your setup. Just showing like others have done, gives us no hint of what you have done. So how can we help?   I downvoted you, because it seems as a commercial for an diy page and of cause, I may be wrong. Edit your question, give us information about your own setup, perhaps a schematic (even hand drawn) and your code you've written so far. Then I will remove my downvote and probably I can even help you.

Oh, I've seen you have included the closing braket in the url. If I remove it the link works. I'll  draw my down vote back. But you should give us an overview of your own project, we can not find out out what's your problem if we study a working project from someone other.

Im trying to read energy meter holding register data through RS485. As given in my previous link im using RS485 to TTL converter for that purpose. I'm not success in getting data from energy meter. so i thought of trying basic example of RS485 commuication between ARduino Mega and Arduino Uno using this converter. AS I said serial monitor doesn't print anything

Yes I understood that, you have problems with connecting two Arduinos over a RS485 link using the mentioned Interfaces/adapters. But how did you do that? Please give a description of what you did. The project from the link should work, so what did you different. What about your program code. Have you a typo in it. How did you connect the parts?  I do not know because I can not have a look into it. I would really like to help you, but I can't without information. HINT: It would be better to edit your question with the new information.

If you doubt that the linked code is correct. I've tried it last evening and it worked. But you might had interpreted the schematics wrong. These are not very clear and definitely not made for beginners. That's why I asked you to show me your setup. Perhaps you would better succeed with another project, that's clearly explained. https://www.instructables.com/id/RS485-Serial-Communication-Between-Arduino-Mega-an . But i have no experience with this Visuino program. I hope it will generate C/C++ Code so you can see it. Or don't you need the code?

Please put additional information in your question, you can [edit] it! Don't write an answer, I just found it by accident. And as PeterPaulKiefer said, we need to see your source code or a note that you use the linked code unchanged. Did you connect GND between the Arduinos and the RS485 modules?

I connected gnd of RS485 converter to arduino gnd and also i did common gnd between circuits but still no output. I used same code nothing changed.. except one thing the example uses arduino pro mini but i used arduino uno as slave

I think there might be two issues in the engineering garage code. delay() function parameter in both codes is not matched. And another thing might cause problem is"Arduino Serial monitor hardware serial is already connected with another usb-serial converter ic which you are using for code uploading, so you cannot use this serial port for rs-485. So using software serial of Arduino pro-mini is a safe option. Finally you have to connect the software Serial pins with rs-485 converter. I have modified the code a little bit and attached the code herewith.
Arduino Mega code
void setup()
{
  Serial1.begin(9600);//Using Serial1 Port
  Serial.begin(9600);
  pinMode(8, OUTPUT);//DE/RE Controling pin of RS-485
}

void loop()
{
  digitalWrite(8,HIGH);//DE/RE=HIGH Transmit Enabled M1
  Serial1.print('9');//Write '9' and Fetch Data From Pro Mini

  int timeOut = 0;
  digitalWrite(8,LOW);//DE/RE=LOW Receive Enable
  while(!Serial1.available() && timeOut < 5000)
  {
    delay(1);
    timeOut++; // wait 5s to get response from slave
  }
  String response = Serial1.readString();
  Serial.println(response);
}

Arduino Pro-Mini Code
#include <SoftwareSerial.h>
#define RS485_RX 2
#define RS485_TX 3
SoftwareSerial mySerial(RS485_RX,RS485_TX);//Creating object

void setup()
{
  //Serial1.begin(9600);//Uncomment for Arduino Lenardo
  Serial.begin(9600);
  mySerial.begin(9600);
  //while(!Serial1);//Uncomment for Arduino Lenardo

  pinMode(13, OUTPUT);//Led Connected
  pinMode(8, OUTPUT);//DE/RE Controling pin of RS-485
}

void loop()
{
  digitalWrite(13,LOW);//Led OFF
  digitalWrite(8,LOW);//DE/RE=LOW Receive Enable

  while(!mySerial.available())
  {
    delay(1);
  }

  String res = mySerial.readString();
  if (res == "9")
  {
     digitalWrite(8,HIGH);//DE/RE=HIGH Transmit Enabled
     mySerial.print("AcruxTek");
     mySerial.print("Isld");
  }
  digitalWrite(13,HIGH);//Led OFF
}

Thanks for your reply sir, Ill definitely try your suggestions and let you know the results

Sir, I tried your code still there is not output coming in master i.e. mega serial monitor

It's not really clear from the picture, but it seems that, the two adapter have no common ground. i.e you have to connect the ground (GND) pin of one the adapter to the GND pin of the other one. But do not remove the connection between the GND pins and the arduino GND pins.
I also assume that the mega-adapter is powered with 3.3 V and the UNO-adapter is powered with 5 V (or 3.3V I can not see). This might cause a problem, because the MAX485 chip needs a 5V power supply.
EDIT:
Sorry by a second view a saw, the mega delivers 5 V. So possibly you only have to connect the GNDs of the adapters to solve your problem.
EDIT 2:
I guess the little yellow wire in front of of both adapters connects the DE pins of them. The DE pin of each adapter is also connected to the respective Arduino PIN 8. So it doesn't matter which Arduino is requesting to switch the adapter into the send mode. Both adapters are sending. As far as I know, the adapter only work in Half Duplex you mus define the direction of the data flow. If one adapter is in send mode the other must be in receive mode.
It might also be possible that the DE and RE PIN of each adapter is connected.
But this seams strange to me also. With that I would say you setup up one adapter in both receive and send mode and the other in none of them.
EDIT 3:
By looking into the MAX485 Spec. I saw that RE is LOW active but labeled as RE (which I understood as HIGH active), so sorry the last paragraph of my EDIT 2 is nonsense. So, perhaps it's a matter of timing or (more likely) there is still something wrong with the wiring.
EDIT 4:
In the picture I see that you connect the hardware tx and rx pins to the adapter. But Software Serial needs its own pins. Pin0 and Pin1 are connected with the PC Serial Terminal over the built in USB to Serial adapter of the arduino UNO. That's the reason why you need the software serial solution on an arduino. You need a second serial interface and UNO has only one of them which is already used for the connection to the PC (Programming and serial monitor).
In the code I don't see the initialization of the software serial port.
This is also necessary:
#include <SoftwareSerial.h>

const byte rxPin = 2;
const byte txPin = 3;

// set up a new serial object
SoftwareSerial mySerial (rxPin, txPin);

@priya I rejected your edits of my Answer because I think, it might confuse the readers. I appended the text to this comment: "As per your suggestion I connected RE pin to pin 9 of Arduino for both MEGA and UNO boards and set the logic level. But still no output. Can you suggest any test that can be done to ensure that RS485 converters are in working condition or damaged?"

I formatted you code, so I can read it better. Parts of the Code are missing there should be a line SoftwareSerial Serial1( rxPin, txPin ); Oh wait... In the picture I see that you connect the hardware tx and rx pins to the adapter. But Software Serial needs its own pins. The other are connected with the PC Serial Terminal. I'll edit my answer.

Sir I tried the code provided by Shuvangkar Shuvo which uses software serial still no success

Did you reconnect the DI and RO pins of the adapter to Pin2 and Pin3 of the UNO? In the picture you used the wrong pins (pin0 and pin1) of the UNO.

Yes Sir, I connected DI pin to pin 3 and RO pin to pin 2 of arduino UNO

No, that should be DI(TX) <-> Pin2 and RO(RX) <-> Pin3 for the arduino UNO. And  DI(TX) <-> TX1 (Pin19?) and   RO(RX) <-> RX1 (Pin18?)  for the mega.

Then I have to swap the connections of TX and RX of Uno board. But for Mega board a little confusion in connection. I have mega board which is made in China.If we look at TX1 and RX1 pins there is a difference, which is correct??

Im attaching link of both the boards                                                                           Mega (Italy Board) - https://www.elexp.com/media/catalog/product/cache/75eed2686e01eb22cb4050b2f40ddf97/0/1/01ARD000067.jpg                                                                        Mega (China Board)- http://1.bp.blogspot.com/-VsoefcyjVzI/VW7oXCHCnaI/AAAAAAAAACM/R-0kdrViX_E/s1600/Clone%2BArduino%2BMega%2B2560.JPG. Please let me now whether my board is good.  Please see there is a difference in pin no for Serial1 port

That's funny. They flipped the Pins . But I hope they only labeled it false, I don't know. If the labels are correct then the program will have a problem. The predefined HardwareSerials e.g. Serial1 on the Mega are bound to pin 18 and 19 for TX and RX and not 19 and 18 for TX and RX.I have no chinese clone and zero exprerience with them. But if you want to be sure, you can use the second port and Serial2 in your program. The pins of port 2 seams to be the same.

I interchanged Arduino Uno RX and TX pins as per above suggestions and also Im using Serial2 in Arduino Mega.. The RX LED on MEGA blinks but Serial monitor doesn't print anything.

@priya Look how I edited my answer each time I had something new. Please, if you have changed something on your setup, append also a new paragraph to your question. Add the new code and a picture of your new setup. I can not say what's wrong if I can not see what you have done. And the picture should show the scene from above, so I can really see the wiring and  the labels of the pins.

Sir, still im not succeeded in my RS485 testing. Please help me out


text:
I can't turn on the motor by Arduino IoT Cloud
I'm trying to turn ON/OFF a DC motor from Arduino Iot Cloud. I have to turn it ON/OFF physically and through the cloud, physically it works well but from the cloud it does nothing. I'm using an Arduino MKR WiFi 1010, a L298N Dual full bridge,9V DC motor and a push buttom. Mi circuit is like this
My code is this
#include "thingProperties.h"
#include <FTDebouncer.h>

#define MOTOR_PIN 2
#define BUTTON_PIN 5

FTDebouncer buttons;

void setup() {
  pinMode(MOTOR_PIN, OUTPUT);
  buttons.addPin(BUTTON_PIN, LOW);
  buttons.init();

  setDebugMessageLevel(2);
  Serial.begin(9600);
  delay(1500);
  // Defined in thingProperties.h
  initProperties();
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
}

void loop() {
  buttons.update();
  ArduinoCloud.update();
  onMotorChange();
}

void onPinActivated(int pinNr) {
  // do something according to the _pinNR that is triggered. For instance:
  Serial.println(pinNr);
  toggle = !toggle;
}

void onPinDeactivated(int pinNr) {
  // do something according to the _pinNR that is triggered. For instance:
  Serial.println(pinNr);
}
void onMotorChange() {
  digitalWrite(MOTOR_PIN, toggle || motor);
  Serial.print("The motor is ");
  if (toggle) {
    Serial.println("ON");
  }
}

I tried with a LED and it worked very well, but with the motor doesn't.
This is the code that Arduino creates when I add things to the board, the part of

thingProperties.h

// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

// x-ed id
const char THING_ID[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

const char SSID[]     = SECRET_SSID;    // Network SSID (name)
const char PASS[]     = SECRET_PASS;    // Network password (use for WPA, or
use as
key for WEP)

void onMotorChange();

bool toggle;
bool motor;

void initProperties(){

ArduinoCloud.setThingId(THING_ID);
ArduinoCloud.addProperty(toggle, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(motor, READWRITE, ON_CHANGE, onMotorChange);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Thanks for the help and suggestions. How should I connect the motor or what do I have to change in the code?

You have connected the button direct to the driver board: When you press the button, the Arduino is not involved. It recognizes the button press but its reaction doesnt matter. You can not say your button works with the Arduino program. You defined the motor output signal to pin 2 but you used pin 3 to connect it to the motor driver. You used different inputs on the driver (for the arduino signat and the button signal). It is possible that the other input is for a second motor. And finnally your program has  logic that make no sense; I doubt it compile at all. e.g. where is toggle declared?

@PeterPaulKiefer it might be declared in thingProperties.h, but that's unclear.

@PythonSchlange Yes that's possible. The OP is welcome to clearify that. Although toggle is a very generic name for a variable that is declared in a header file. And e.g. ArduinoCloud.update() could play a serious role. But I have no access to it. As far as I know the program, it makes no sense to me.

@PeterPaulKiefer I totally agree with you. Please upload the header file too.

@PeterPaulKiefer I was wrong making the diagram, just that. Toggle was declared in 'thingProperties.h', when you add your thing, the cloud generates a code

As you schematics do eventually not fit to the reallity, I can only argue with the code. First I've x-ed the ThingsId, it should not be published. ;-) There are so many things I see that's it's not easy to explain them shortly. "The code is the truth", so I wrote an answer with an commented sketch.

The following code is an example. As I don't know the Arduino Cloud Thing configuration, and I don't have access to the cloud and the Hardware, the
programm is just a guess making some commented assumptions.
There are many assuptions I made, and I can not rely on the schematics you showed me. Eventually you have to redesign the circuit/hardware setup. A L298N is a so called H-Bridge. That needs at least two control pins in1 and in2 connected to arduino outputs to define the direction of the motor. You only connected one of them to an output of the arduino. And one of them to the button and an input of the arduino. (If that part of the schematics is correct.)
If you press the button in1 gets HIGH but the in2 may also get HIGH because your program switches the motor pin to HIGH. That turns the motor off. If one pin is HIGH the other must be LOW to drive the motor. Some L298N modules also need a PWM signal at the enA pin. That sets the speed of the motor with the duty cycle of the PWA signal. Most modules have a pullup at enA and enB so per default the motors are configured for full speed.
#include "thingProperties.h"
#include <FTDebouncer.h>

#define MOTOR_PIN 2
#define BUTTON_PIN 5

FTDebouncer buttons;

void setup()
{
  pinMode(MOTOR_PIN, OUTPUT);

  // !!! PPK: Handler methods added
  buttons.addPin(BUTTON_PIN, LOW, onPinActivated, onPinDeactivated);

  buttons.init();

  setDebugMessageLevel(2);
  Serial.begin(9600);
  delay(1500);
  // Defined in thingProperties.h
  initProperties();
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
}

void loop()
{
  buttons.update();
  ArduinoCloud.update();
}

void onPinActivated(int pinNr)
{
  if ( pinNr == BUTTON_PIN )
  {
     toggle = !toggle;
     // this assumes that the toggle triggers a change for
     // the motor variable in arduino cloud. If not,
     // the motor variable will not be changed and my code does not work.
     // uncommenting the following line may help, in that case
     // motor = toggle;
  }
}

void onPinDeactivated(int pinNr)
{
  // Intentionally left empty, we only react to the rising edge.
}

void onMotorChange()
{
  digitalWrite( MOTOR_PIN, motor );
  Serial.print("The motor is ");
  if ( motor )
  {
    Serial.println("ON");
  }
  else
  {
    Serial.println("OFF");
  }
}

This line  // !!! PPK: Handler methods added
buttons.addPin(BUTTON_PIN, LOW, onPinActivated, onPinDeactivated);  (?) I can't compile with this and I can't edit "thingProperties.h". BUTTON_PIN is the pin for toggle that is a bool thing as the motor, just to turn ON/OFF (I follow an example in Arduino project hub)


text:
How to compare an incoming byte from cool terminal as modbus hex value and compare it with a predefined value in set in the program?
My Input from Cool terminal is
    05 03 00 01 00 02 94 4F
I should be able to read this input 05 03 00 01 00 02 94 4F compare with the same(05 03 00 01 00 02 94 4F). If the incoming value(05 03 00 01 00 02 94 4F) and the predefined value(05 03 00 01 00 02 94 4F) are the same it should print the hex value like

05 03 04 43 65 BA 7D 04 E8

I tried to code it but i could'nt get the value.
Here is my code in Arduino
    void setup()
    {
      Serial.begin(9600);
    }

    void loop()
    {
      static char buffer[1024];
      static size_t length = 0;

      if (Serial.available()) {
        char c = Serial.read();

        // Otherwise buffer the incoming byte.
        //else if (length < sizeof buffer - 1) {

        Serial.write(c);  // echo
        buffer[length++] = c;
      }
    }

You didn't include your code. And what does "couldn't get the value" mean?

Did you read what you copy & pasted? (edit question, select code, press ctrl-k to align). What means 'read this input compare with the same' ? And where is the predefined value in the code (or is the predefined value something else? If so, what exactly?

I have edited it would be good for you to understand now.

how are you determining the value to print? .... ar you doing some calculation?

@jsotola I am not doing any calculation. I just wanted to print the answer

the printed hex values are different from the input hex values ... that indicates data manipulation of some kind

Yes Yes yes !!!! The printed hex values are different because I am just printing them( and I am not mofifying anything).


text:
Can't upload programme on arduino uno
Arduino: 1.8.3 (Windows 7), Board: "Arduino/Genuino Uno"
Sketch uses 1094 bytes (3%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM14 -b115200 -D -Uflash:w:C:\Users\Admin\AppData\Local\Temp\arduino_build_360380/FINALROTARO.ino.hex:i

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM14
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x1f

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


text:
AT commands not working on arduino uno with A7 gsm gprs module
After all connections have been made, I tried to verify my sketch to the arduino
#include <SoftwareSerial.h>

// RX, TX
SoftwareSerial mySerial(2, 3);

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

  while (mySerial.available())
  {
    mySerial.read();
  }
}

void loop()
{
  if (Serial.available())
  {
    mySerial.write(Serial.read());
  }

  if (mySerial.available())
  {
    Serial.write(mySerial.read());
  }
}

After uploading this code to arduino, I tried to confirm.
But it was constantly displaying
¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
If I set the baud to 9600
But if I set it to 115200, I will not get anything
..
Please help me.
I will be defending my project tomorrow and I am stock here...

You start your project one day before you have to present it. That's funny ;-)) .... OK, now seriously: In order to get quick help, you should add all information you have, and provide links to the used boards and modules. Your could at least format your code example. Have you seen it, how could someone read it? I've done that for you. "But if I set it to 115200, I will not get anything .. " Which one have you set to 115200? The hardware serial, the software serial, the serial terminal in the IDE, all of them? How did you wire the board? Show a picture of your setup.

BTW: Formatting code is easy. Just highlight it and then press the {} button in the menu bar of the online editor.

Have you tried all the other common baud rates? The module might work on one of them. Do you have dicumentation about your module, that states the baudrate?