texts:
I wrote a sketch for controlling the stepper motor under the controls of the Blynk application, the sketch was compiled but there was a problem in that no control was taking place. Receipts and controls occur on virtual pins V1, V2, V3. (The problem is that nothing is controlled), please help solve the problem.

//#include <Stepper.h>
//#define BLYNK_WRITE
//#include <ESP8266WiFi.h>
//#include <BlynkSimpleEsp8266.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor
Stepper myStepper(stepsPerRevolution, 1, 2, 3, 4);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "[private]";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "S30mini";
char pass[] = "12345678";

int pinData;
int pinData1;
int pinData2;
BLYNK_WRITE(V3) //Button Widget is writing to pin V1
{
  int pinData = param.asInt();
 }
BLYNK_WRITE(V2) //Button Widget is writing to pin V1
{
  int pinData1 = param.asInt();
 }
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
  int pinData2 = param.asInt();
 }

void setup()
{
  // Debug console
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
    Blynk.run();

  // map it to a range from 0 to 100:
  int motorSpeed = map(pinData, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }

   if (pinData1 == 1){
      myStepper.step(stepsPerRevolution);
   }

   if (pinData2 == 1){
     myStepper.step(-stepsPerRevolution);
    }

}


texts: How do i improve this Code? (or how to pass a Char String into a Function to behave like a Variable)

texts:
Sorry i am a beginner and amateur when it comes to coding, can somebody help me to make the code inside the loop() less "monkey-like" by using a proper function?
I have tried a lot and at some point i am running out of ideas about how to even phrase the question on google.
My main problem when writing a function for this case is that i don't know how to pass a variable into a function which has to be written out as part of a Variable but also as part of Char Strings if that makes sense.
If you look at the code inside the loop() i actually only had to pass the number to the function, like "3" to change some Variables and Char Strings accordingly. I would be able to solve the issue with those Char Strings but i am completely clueless how to handle the Variable (rmd3, rmd4...).
"3" as in:
Variable:        rmd3,    Char String      "rmd3 = 1",   Variable Value:  rotary_mode = 3   and Char String:     "rotary_mode = 3"
This is a simplified version of my code but boils down to where i am stuck at. It refers to a rotary selector i am using which has 6 Positions (rmd1 - rmd6). However if i knew how to solve this issue i could use it in many other situations as well.

Bounce rmd3 = Bounce(45,10);    //rotary selector on pos.3
Bounce rmd4 = Bounce(44,10);    //rotary selector on pos.4
int rotary_mode = 0;            //Rotary Mode

void setup() {
  Serial.begin(11520);
  pinMode(45, INPUT_PULLUP);   //pin of pos.3
  pinMode(44, INPUT_PULLUP);   //pin of pos.4
  }

void loop() {
             rmd3.update();
             if (rmd3.fallingEdge()) {
                Serial.print("rmd3 = 1");
                rotary_mode = 3;
                Serial.print("rotary_mode = 3");
             }
             if (rmd3.risingEdge()) {
                Serial.print("rmd3 = 0");
                rotary_mode = 0;
                Serial.print("rotary_mode = 0");
             }

             rmd4.update();
             if (rmd4.fallingEdge()) {
                Serial.print("rmd4 = 1");
                rotary_mode = 4;
                Serial.print("rotary_mode = 4");
             }
             if (rmd4.risingEdge()) {
                Serial.print("rmd4 = 0");
                rotary_mode = 0;
                Serial.print("rotary_mode = 0");
             }
}´´´

Pseudocode:

´´´void loop() {
int rmd_int;            //Mode numbers as int from 1 to 6
char rmd_char = [2];    //Mode numbers as char from "1" to "6"

              rmd3.update();
              rmd_int = 3;
              rmd_char = "3";
              void selected_mode(rmd_int, rmd_char);
}

void selected_mode(int rmd_int, char rmd_char ){
             if (rmd[rmd_int].fallingEdge()) {
                Serial.print("rmd[rmd_char] = 1");
                rotary_mode = [rmd_int];
                Serial.print("rotary_mode = [rmd_char]");
             }
             if (rmd[rmd_int].risingEdge()) {
                Serial.print("rmd[rmd_char] = 0");
                rotary_mode = 0;
                Serial.print("rotary_mode = 0");
             }
}```


texts: Is it ok to declare variables inside timer interrupts?

texts:
I am building a real time audio application using the Arduino DUE. This application needs big arrays like:

uint16_t sDelayBuffer0[46000];

The Due has only 96kb of RAM available so this array just ate up most ot its memory.
The problem is i need more arrays like this...

So, i was thinking, instead of declaring all of the arrays as global variables, to declare them inside the timer interrupt functions.

The loop() handles stuff like reading the ADCs. The actual effects are coded inside timer iterrupt funciton that are replayed over and over. So the code constantly loops in loop() and the selected timer interrupt function.

But other timer interrupt fucntions use other arrays. So i was thinking to declare every array that a corresponding timer interrupt function wants inside that fucntion.

So all arrays are not declared at the same time (since when we exit the timer interrupt function we were on and head either to loop or another interrupt function, the grabage collector will destroy the array right?)

The problem with this theory, is that this is a real time audio application. So is it wise to constantly declare a big array like this? Since the timer interrupt ficntion will run very very often. Won't i have delay problems iwth the actual sound? Or variable declarations happen extremely fast inside the CPU, even for big arrays?


texts:
I have a SIM900 GPRS/GSM Shield and an Arduino Mega. Now for the past week I have been using USB as power to send and receive GPRS data with no issue. Today the SIM900 module is continually randomly turning off, not even turning of at specific stages of communication.

I thought this could be power related, so have external power (5V 5A UBEC) into the 5V pin of the Mega, which I believe should cover the voltage and current requirements of the SIM900 shield. However this has not solved the problem.

Any ideas on what could be causing the random shutdowns?

EDIT:
Is it safe for me to wire power up like this:


texts:
My son is working on a school project, He wants to measure microbiological interaction with soil and plant.
In his protocol, he has to measure the amperage of the soil. I would like to help him with some automation and Arduino.
But I can't find a module that does this work for him.
Have you got some resources or maybe a small and easy PCB to achieve this?
Firsts measurements tend to reveal that microbiological product small ampere, near the micro/nano ampere.
Edit : I think I don't explain correctly what we are trying to achieve :
The plant rejects sugar through its roots, then the bacteria eat the sugars and these bacteria release electrons in the medium, and it is this phenomenon that we want to measure.
It is the bacteria that produce the electrons because a whole test protocol has been put in place to ensure the phenomenon.
So we want to monitor this electron production and then make some and correlations analyze to see if it's benefit to the plant or not.


texts: Trying to switch a 5v fan with a LiPo and can't figure our what's wrong at full duty cycle

texts:
I have a simple project where I want to turn a 5v fan on/off and both the MCU  and fan will powered by a LiPo battery.
I'm powering the ESP and fan directly from the battery in the attached circuit. For now I've decided not to boost the power to 5v for the fan because the fan runs fine at lower voltage. Also using a BJT transistor as a low side switch.
This all seems to work fine except at full duty cycle the voltage to the fan seems to completely collapse. At just below full (like if a do analogWrite(pin 1000) it's humming along fine but when I go to 1023 the voltage drops from around 4 to closer to 2 and the fan stops. Even at lower duty cycles like 50% the fan operates nice and slow.
I put a multimeter on the leads to the fan and observe the voltage drop at full duty.
I'm very new to all this and have done a lot of reading but I haven't been able to solve this. Also this is my first fritzing drawing so I hope it makes sense.
Edit: I made some changes to the circuit and it's working as expected. I have also updated the circuit diagram below.


texts:
I am making an arduino clock/alarm. I use an LCD screen to display the time.

void loop(){
    static unsigned long timing=micros();
    if (mode == 0) {//mode 0 is when the time should show
        timing=countTime(timing);
        writeTime(minutes, hours);//display time
  }
}
  unsigned long countTime(unsigned long timing){
            if (micros() - timing >= 59946970) {
              return timing += 59946970;//more precise because Arduino timing is not perfect
              minutes++;

    }
        else{

         return timing;
        }

      }

    void writeTime(int minute, int hour) {
      lcd.setCursor(6, 1);
      if (minute >= 60) {
        minute = 0;
        hour++;
      }
      if (hour >= 24) {
        hour = 0;
      }
      if (minute < 10) {

        if (hour < 10) {
          lcd.print(String("0") + hour + ":" + "0" + minute);
        }
        else {
          lcd.print(hour + String(":") + "0" + minute);
        }
      }
      else {
        if (hour < 10) {
          lcd.print(String("0") + hour + ":" + minute);
        }
        else {
          lcd.print(hour + String(":") + minute); //possibly split if problems arise
        }

      }

  }

I used to do all this within the loop, but decided to make it separate. Why isn't this code working?


texts: read from serial monitor then store char in array then print it , please help

texts:
Build a program that will accept a name at the keyboard and then puts the name into a 1-D array. Then, use the contents
of the array to print out the name.


texts: Strange values on Serial Monitor even with matched baud rate

texts:
I am using the Adafruit Flora, connected with a Max 4466 microphone sensor. When I read values from the pin numbered 12 (which is marked as a11 for analog input on the schematic of the flora) I get random characters in the serial monitor as shown in the attached image, with my code. Trying to read other pins that are connected to nothing doesn't read any information. My baud rate in the serial monitor and the code are the same as you can see in the image.

Looking at the max 4466 explanation on the Adafruit website it says you don't need a capacitor or anything and can just directly plug the out pin on the MAX 4466 to the analog pin on an Arduino. I'm not sure if a different protocol has to be followed for a Flora instead of an Arduino. It also says to convert the information to an actual signal I need to use the FFT libraries, but I don't think this input being read is even correct.

If the FFT library is the problem here, I would need help on how to use it because there is no clear value being read in the example code. I had to set up a delay in the code otherwise the IDE would crash from all the info.Additionally, the VCC on the max is connected to 3.3V, the GND to GND, and the OUT to the #12 pin on the Flora.


texts:
I need vibration sensor for my project. I have found many sensors similar to this one. But it seems, that this sensor outputs only zeros for "non-hit" state and ones for "hit state". And I need something that can output levels of vibration, not only presence/abscense.

So is there any high-resolution vibration sensor for arduino?

Thank you!


texts: How to generate two pulses one with 60 and other 66 duty cycle at same instant in 2 pins?

texts: I have to drive two switches one at a duty cycle of 60% and the other at a duty cycle of 66% simultaneously at 50khz frequency. I am using an Arduino Uno ATmega 328.


texts: Arduino with bmp280 sensor not entering void loop

texts:
I've been working on a project in which I need to know my altitude. For this purpose I've been using the BMP280 sensor. But I have an issue.
I've been trying to test if the sensor works with the program "bmp280_sensortest.ino", already included in the library. When I open the serial monitor the message "BMP280 Sensor event test" is displayed, indicating that there is a valid sensor on board. Below that the temperature, pressure and altitude data should be displayed, but nothing happens.
I've added a simple Serial.print("hello") at the start of void loop(), but not even that is displayed. The program doesn't seem to enter void loop() and I don't know why.
Here is the code:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>

Adafruit_BMP280 bmp; // use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();

void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 Sensor event test"));

  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1) delay(10);
  }

  /* Default settings from datasheet. */
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

  bmp_temp->printSensorDetails();
}

void loop() {
  sensors_event_t temp_event, pressure_event;
  bmp_temp->getEvent(&temp_event);
  bmp_pressure->getEvent(&pressure_event);

  Serial.print("hello");
  Serial.print(F("Temperature = "));
  Serial.print(temp_event.temperature);
  Serial.println(" *C");

  Serial.print(F("Pressure = "));
  Serial.print(pressure_event.pressure);
  Serial.println(" hPa");

  Serial.println();
  delay(2000);
}

Any reply is greatly appreciated.
edit:
if I remove
!bmp.begin()
from the if statement and replace it with a 1 it enters the void loop but it displays 0°C and 0pa


texts:
I'm new to Arduino and I'm trying to use PWM to generate a tone through a buzzer. I've created a for loop, however, the for loop doesn't seem to break when the variable ms is < 1000000.

int second = 1000000; //1 second in microseconds

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

void loop() {
  //Play middle C for 1 second
  for(int ms=0; ms <= second; ms+=3830)
  {
    digitalWrite(3, HIGH);
    delayMicroseconds(1915);
    digitalWrite(3, LOW);
    delayMicroseconds(1915);
    Serial.println(ms);
  }
  Serial.write("Finished C");
}

We can see on the serial output that the value of ms exceeds 1000000 but the for loop is still going. Can anyone see where I am going wrong?


texts: Hardware/Software Serial communication abruptly stops (HC - 05 bluetooth module)

texts:
I'm trying to send the readings of 3 sensors simultaneously to my Android phone on an app I made using MIT App Inventor 2 via the HC-05 bluetooth module.

For this, I'm sending a string like "20.067, 58.234, 12 |" where the "," allows the splitting of the text and "|" acts as a delimiter to tell the app that the whole string has reached it.

The problem I'm facing is that after a while(which varies from 2 seconds to a few minutes), the readings just stop and the app stops responding (ie; touching any butons on the app does nothing). However, this is a non-issue when I'm not using Bluetooth at all and just printing to the Serial Monitor.

To find the cause, I tried the following things:

Sent text to the module via the normal Serial.print() function so that I can see it on my PC and my app at the same time. Strangely, after the readings stopped (on the serial monitor as well), as soon as I closed the Serial Monitor and opened it again, the readings were back and again stopped after a while.
I used the SoftwareSerial.h library to define a different pair of RX/TX pins to send the text to the module and the serial monitor separately. This time, when the readings stopped, restarting the serial monitor had no effect.

I'm not exactly sure how to interpret these outcomes but it leads me to believe the problem lies in the serial communication.

Additional information:

The baud rate is set to 115200
I'm sending a string every 500ms and the app clock fires every 100ms

This is a screenshot of the codeblock on MIA 2:

This is the relevant portion of the Arduino sketch. The rest of it just calculates the variables being printed

  if(millis()-looper>500){
  // Sensor 1 data
  Serial.print(" X = ");
  Serial.print(x1);
  Serial.print(" Y = ");
  Serial.print(y1);
  Serial.print(" Z = ");
  Serial.print(z1);
  Serial.print(",");

  // Sensor 2 data
  Serial.print(" X = ");
  Serial.print(x2);
  Serial.print(" Y = ");
  Serial.print(y2);
  Serial.print(" Z = ");
  Serial.print(z2);
  Serial.print(",");

  // Sensor 3 data
  Serial.print(angle);
  Serial.println("|");
  looper = millis();
  }


texts: which Arduino UNO ethernet shield supports power over ethernet?

texts:
I ordered for this ethernet shield for my UNO as shown on the amazon website listing

I was thinking to add power over ethernet module to take advantage of shield that supports adding POE module.

.

But I received the one below

Does the one I received POE? Without the use of POE module!


texts: The Arduino Oscilloscope - Error message: 'ADCSRA' was not declared in this scope

texts:
Project: The Arduino Oscilloscope - published in The MagPi No. 71 July 2018

This is my first Arduino project!
I'm porting over the sketch "Gather_A0.ino" but I'm encountering compile errors:
Error message: 'ADCSRA' was not declared in this scope.
What am I missing?

Error message:

Arduino: 1.8.12 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
D:\Arduino & Raspberry Pi\Oscilloscope\Arduino_Scope\Software\Gather_A0\sketch_apr09a\sketch_apr09a.ino: In function 'void setup()':
sketch_apr09a:15:3: error: 'ADCSRA' was not declared in this scope
   ADCSRA = (ADCSRA & 0xf8) | 0x04; // set 16 times division
   ^
D:\Arduino & Raspberry Pi\Oscilloscope\Arduino_Scope\Software\Gather_A0\sketch_apr09a\sketch_apr09a.ino: In function 'void trigger()':
sketch_apr09a:58:4: error: expected 'while' before '{' token
   }{
    ^
sketch_apr09a:58:4: error: expected '(' before '{' token
sketch_apr09a:58:4: error: expected primary-expression before '{' token
sketch_apr09a:58:4: error: expected ')' before '{' token
sketch_apr09a:58:4: error: expected ';' before '{' token
sketch_apr09a:60:1: error: expected '}' at end of input
 }
 ^
exit status 1
'ADCSRA' was not declared in this scope


texts: Does the square-wave nature of PWM dictate how much resistance you need?

texts:
I think the answer is yes, but I wanted to ask the question anyway for future common reference. And to check my understanding.

Say I want to power 10 LEDs with PWM with my Mega 2560. I have a bunch of 200 ohm resistors.

I know the Mega and most other Arduinos can safely provide a maximum of 200mA total current. 200mA / 10 is 20mA per LED maximum.

Using my 200 ohm resistors I can calculate how much voltage will supply 20 mA of current:

V = 200 ohms * 20mA
V = 4V

So I just need to make sure to analogWrite less than or equal to 4V to each of the ten LEDs and I won't cross the 200mA threshold. That's if PWM was true analog.

However, PWM is not true analog, and if I analogWrite 4V to each pin, they're going to spend most of the time at 5V and some of the time at 0V.

When every pin is at 5V the board has to supply

(5V / 200 ohms) * 10 = 250mA

Which is over the spec, so I am in danger of damaging my board. Right?

So if I want to calculate the maximum current draw of the 10 LEDS being powered simultaneously with PWM, I have to assume that they are all getting 5V regardless of what I analogWrite to them. I do not actually have control over the voltage, I only have control over the resistance.

Thus in order to be safe I need to get some new resistors with resistance:

5V / 20mA = 250 ohms

Is this all correct?


texts: Sim800L HTTP post request stop working after a while

texts:
I am desperate to get my SIM800L module (http://www.ebay.co.uk/itm/SIM800L-GPRS-GSM-Module-Board-Quadband-QUAD-BAND-Antenna-for-MCU-Arduino-/321992759287) sending POST requests for a long period of time... Sometimes it stops after 100 requests in a row, sometimes 300 so it's really weird.

Everytime I run it, it sends the request for a while (between 1 and 3 hours) and suddenly stops on these AT commands:

---> AT+HTTPINIT
<---

OK

When it works the OK is on the same line and it goes on to the next AT command.

        ---> AT+HTTPTERM
    <--- ERROR
         ---> AT+HTTPINIT
    <--- OK
    ---> AT+HTTPPARA="CID"
    <--- OK
    ---> AT+HTTPPARA="UA"
    <--- OK
    ---> AT+HTTPPARA="URL"
    <--- OK
    ---> AT+HTTPPARA="CONTENT"
    <--- OK
    ---> AT+HTTPDATA=1221,10000
    <--- DOWNLOAD
    <--- OK
    ---> AT+HTTPACTION=1
    <--- OK
Status: 201
Len: 0
    ---> AT+HTTPREAD
    <--- OK
    ---> AT+HTTPTERM
    <--- OK

I thought it was a powering problem so I connected the module to the VIN pin of my arduino mega via a buck converter but the problem is still here!

Does anybody have any idea what could be wrong? I can send you the code if needed.

Many thanks in advance
Pauline


texts: What bootloader is present by default on Arduino Uno?

texts:
Or where can i find information of default bootloaders present on each Arduino board. All I could look up was it could be one of these bootloaders on the atmega chip :-

.Atmega
.Atmega8
.bt
.caterina
.caterina-Arduino_Robot
.caterina-LilyPadUSB
.gemma
.lilypad
.optiboot
.stk500v2

This was the list present in the folder ~\Arduino\hardware\arduino\avr\bootloaders.


texts:
I've this PWM Module - 6V-90V 15A Pulse Width PWM DC Motor Speed Controller Switch which I use to control a peristaltic pump (ordinary DC motor), now I want to replace the potentiometer with an Arduino in order to create a soft-start for the pump by pressing a button.
The control is a 0-5V input from the potentiometer, and the description says "you can external drive" and "It could use of PLC controls speed of motor", unfortunately I cannot provide datasheets or schematics.

Is it possible? Or I need a digital pot?

How should I wire it? The 3 cables from the board to the pot are: ground, 0-5V and 5V


texts:
I'm trying to send data from one Arduino board to another using NRF24L01 connect to the two ends of the two Arduino boards. The Tx blinks in the transmitting end(Arduino board 1) but the receiving end(Arduino board 2) is not getting any value from it. Here is my code.

Transmitting end (Arduino board 1)

#include <SPI.h>
#include "RF24.h"

RF24 myRadio(0, 1);
byte addresses[][6] = {"0"};

struct package
{
    int id = 1;
    float longitude = 0.0;
    float latitude = 0.0;
    char text[100] = "Geographic coordinates";
};

typedef struct package Package;
Package data;

void setup()
{
    Serial.begin(115200);
    delay(1000);
    myRadio.begin();
    myRadio.setChannel(115);
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate(RF24_250KBPS);
    myRadio.openWritingPipe(addresses[0]);
    delay(1000);
}

void loop()
{
    myRadio.write(&data, sizeof(data));

    Serial.print("\nPackage:");
    Serial.print(data.id);
    Serial.print("\n");
    Serial.println(data.longitude);
    Serial.println(data.latitude);
    Serial.println(data.text);
    data.id = data.id + 1;
    data.longitude = data.longitude + 0.1;
    data.latitude = data.latitude + 0.1;
    delay(1000);
}

Receiving end (Arduino board 2)

#include <SPI.h>
#include "RF24.h"

RF24 myRadio(7, 8);
struct package
{
    int id = 0;
    float longitude = 0.0;
    float latitude = 0.0;
    char text[100] = "empty";
};

byte addresses[][6] = {"0"};

typedef struct package Package;
Package data;

void setup()
{
    Serial.begin(115200);
    delay(1000);
    myRadio.begin();
    myRadio.setChannel(115);
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate(RF24_250KBPS);
    myRadio.openReadingPipe(1, addresses[0]);
    myRadio.startListening();
    delay(1000);
}

void loop()
{

    if (myRadio.available())
    {
       while (myRadio.available())
       {
           myRadio.read(&data, sizeof(data));
       }
        Serial.print("\nPackage:");
        Serial.print(data.id);
        Serial.print("\n");
        Serial.println(data.longitude);
        Serial.println(data.latitude);
        Serial.println(data.text);
    }

}

This is how i connected the Arduino and NRF24L01

Any reason why im not getting the the data from the transmitting end?


texts:
I created a function that saves the timestamp in a text file, but it saves unreadable. Full of invalid characters, example: Ÿ@Â   O   ƒº!¥ Ÿ@Â   O   ƒº!¥ Ÿ@Â   O   ƒº!¥ Ÿ

#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include "RTClib.h"

RTC_Millis rtc;
File txt;
const char * getCurrentTimestamp()
{
    char dateBuffer[40];
    DateTime now = rtc.now();
    sprintf(dateBuffer,"%02u-%02u-%04u %02u:%02u:%02u", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
    return dateBuffer;
}

void saveLog()
{
  txt = SD.open("dados.txt", FILE_WRITE);
  txt.print(getCurrentTimestamp());
  txt.close();
}

void setup() {
  pinMode(53, OUTPUT);
  SD.begin(4);
  Serial.begin(9600);
  rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
}

void loop() {
  Serial.println(getCurrentTimestamp());
  saveLog();
  delay(1000);
}

My code is very simple, do not understand where I went wrong. if I copy the following code snippet for saveData() function and save the dateBuffer variable, everything works normally.

char dateBuffer[40];
DateTime now = rtc.now();
sprintf(dateBuffer,"%02u-%02u-%04u %02u:%02u:%02u", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());

how to save the timestamp correctly in the file through the function getCurrentTimestamp() ?


texts: "expected primary-expression before '.' token" in debug code

texts:
I'm making some code for school, and is adding debug code to it. When compiling, I get the error as written in the title. This is the code in question:

#define DEBUG 1

#ifdef DEBUG
#define Serial.println(x) DEBUG_PRINT(x)
#else
#define DEBUG_PRINT(x)
#endif

And the code in my void setup, which has Serial.begin:

#ifdef DEBUG
Serial.begin(9600);
DEBUG_PRINT("Asteroid");
#endif

What am I getting wrong? I get the feeling it's my define text, but I'm unsure.

Thank you for your time
Gaarden


texts: The error shows ir_sensor:54:1: error: expected unqualified-id before '{' token { ^ exit status 1 expected unqualified-id before '{' token

texts:
int EN1=12;
int EN2=13;
int EN3=11;
int EN4=10;
int IR=15;
int LED=14;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(EN1,OUTPUT);
pinMode(EN2,OUTPUT);
pinMode(EN3,OUTPUT);
pinMode(EN4,OUTPUT);

pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(IR,INPUT);
pinMode(LED,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(EN1,HIGH);
digitalWrite(EN2,HIGH);
digitalWrite(EN3,HIGH);
digitalWrite(EN4,HIGH);

forward();
}

void forward() {

analogWrite(2,255); // The speed value of the left motor//
analogWrite(3,0);

analogWrite(4,255); //The speed value of the right motor//
analogWrite(5,0);

analogWrite(6,255); // The speed value of the left motor//
analogWrite(7,0);

analogWrite(8,255); //The speed value of the right motor//
analogWrite(9,0);
}
{
int z = digitalRead(IR);
if (z==HIGH)
{digitalWrite(LED,HIGH);
}
if (z == LOW)
{digitalWrite(LED,LOW);
}
}


texts: Failure to upload to unoR3/Built-in WiFi

texts:
Just-purchased UNO/R3/WiFi.  Lees Electronics / Vancouver, BC, Canada.   https://leeselectronic.com/en/
In "tools' Board set as UNO WiFi.  In "tools" Port COM5 not ID'd as Arduino.  Run Bootloader.  Initially, when using COM7 (IDd as "Arduino UNO').  Upload fail.  Using COM5,  Attempt to upload results in 10 attempts:  First 2 (of 10) errors message sets below:
Using Port                    : COM5
         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=0x27
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x27

Tom Kane / Feb 10, 2021


texts: Is it possible to gather data while the Arduino is being powered with a battery, connect to comp, and then read off the values in Serial Monitor?

texts:
I want to do a project where I gather data such as sunlight hours per day, as well as temperature highs/lows. Once I have gathered 24 hours worth of data, I want to hook it up to the computer to read off the values in Serial monitor.
When I try and open the Serial monitor, it restarts the program wiping all the memory.
I tried doing something with PROGMEM, but that didn't seem to help as it is only for constants.
I want to avoid using an LCD to display data if possible.


texts: Can RX and TX be temporarily transposed on demand?

texts:
Only 2 arduinos can normally be linked via serial port because TX and RX need to be cross-linked, and connecting multiple TXs together would cause conflict.

RS485 allows multiple nodes connected in parallel on a 2 wire differential 'bus', using a TX ENABLE pin to allow one master to transmit while all other slaves listen.

I suspect it should be possible to similarly connect multiple serial RXs together to give a common listening bus, and be able to use TX ENABLE on any one node at a time to transpose its RX and TX to allow its TX to transmit to the other RXs. This might be physically done using a changeover relay swapping RX with TX, but is it possible to somehow temporarily switch the TX and RX assignments on demand by software?

I doubt the actual pin assignments can be changed in-situ, but perhaps the same results are achievable with some programming wizards sleight-of-hand trickery?


texts: Read and write on the same node (central) using an RF24 network on Arduino

texts:
I want to send and receive on the same node using the RF24Network library, but I'm unable to do so even when I use radio.StopListening().

Here is the code:

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(9,10);
RF24Network network(radio);
struct payload_t{unsigned long int code; unsigned long int message;};

void setup(void) {
  Serial.begin(9600);
  SPI.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.setAutoAck(false);
  network.begin(108, 0);
}

void loop(){
  network.update();
  RF24NetworkHeader header;
  payload_t payload;
  if(network.available()) {
    network.read(header, &payload, sizeof(payload));
    Serial.println(payload.message);
    // I WANT HERE TO SEND BACK TO THE TRANSMITTER but I'm unable to do that
    radio.stopListening();
    payload_t payload = { 2000, 15444452 };
    RF24NetworkHeader header(2);
    network.write(header, &payload, sizeof(payload));
  }
}

Second Node:

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(9,10);
RF24Network network(radio);
struct payload_t{unsigned long int code; unsigned long int message;};
firstExec = 1;

void setup(void) {
  Serial.begin(9600);
  SPI.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.setAutoAck(false);
  network.begin(108, 2);
}

void loop() {
  network.update();
  if(firstExec) {
    radio.stopListening();
    payload_t payload = { 2000, 5555555 };
    RF24NetworkHeader header(0);
    network.write(header, &payload, sizeof(payload));
    radio.startListening();
    firstExec = 0;
  }
  RF24NetworkHeader header;
  payload_t payload;
  if(network.available()) {
    network.read(header, &payload, sizeof(payload));
    Serial.println(payload.message);
  }
}


texts: I want my arduino mega to read from all 4 serial ports at the same time, running sequentially through each one

texts:
I currently have the code running through Serial1, which works exactly as I want it to:

int RFIDResetPin = 13;

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial2.begin(9600);
  pinMode(RFIDResetPin, OUTPUT);
  digitalWrite(RFIDResetPin, HIGH);
  Serial.println("Arduino is ready");
}

void loop(){

  char tagString1[13];
  int index = 0;
  boolean reading1 = false;
  ///////////////////////////////////////
  //this reads from the reader installed
  //on serial1, which is pin 19
  //////////////////////////////////////
  while (Serial1.available() > 0) {

    int readByte1 = Serial1.read(); //read next available byte

    if (readByte1 == 2) reading1 = true;
    if (readByte1 == 3) reading1 = false;

    if (reading1 && readByte1 != 2 && readByte1 != 10 && readByte1 != 13) {
      tagString1[index] = readByte1;
      index++;
    }
  }
  Serial.print("Reader 1: "); //read out any unknown tag
  Serial.println(tagString1);

  clearTag(tagString1); //Clear the char of all value
  resetReader(); //reset the RFID reader
}

void resetReader() {
  ///////////////////////////////////
  //Reset the RFID reader to read again.
  ///////////////////////////////////
  digitalWrite(RFIDResetPin, LOW);
  digitalWrite(RFIDResetPin, HIGH);
  delay(150);
}

void clearTag(char one[]) {
  ///////////////////////////////////
  //clear the char array by filling with null – ASCII 0
  //Will think same tag has been read otherwise
  ///////////////////////////////////
  for (int i = 0; i < strlen(one); i++) {
    one[i] = 0;
  }
}

However, I want to add serial0, 2, and 3 as well. there are 2 main questions I have
1) is it possible to have copy paste this section of the code:

    while (Serial1.available() > 0) {

    int readByte1 = Serial1.read(); //read next available byte

    if (readByte1 == 2) reading1 = true;
    if (readByte1 == 3) reading1 = false;

    if (reading1 && readByte1 != 2 && readByte1 != 10 && readByte1 != 13) {
      tagString1[index] = readByte1;
      index++;
    }
  }
  Serial.print("Reader 1: "); //read out any unknown tag
  Serial.println(tagString1);

  clearTag(tagString1); //Clear the char of all value
  resetReader(); //reset the RFID reader
}

while changing some of the variable names to connect the other serial ports? I saw something here, but don't know how to implement it, or if it even would work for me.

and
2) since I am routing the incoming data through serial0, Is it possible to have this code working on it as well?


texts: Arduino relay module working in a wrong way

texts:
I have an Arduino Mega and a 4-channel relay module.

This is the relay module.

When the Arduino digital output is LOW, the relay is energized.  When the Arduino output is HIGH, the relay coil is de-energized.

How can I fix this?


texts: Using an arduino to emulate keyboard inputs

texts: I have a shapeoko 2, and have been wanting to create a jogging pendant for it for a while.  Currently GRBL (the G code interpreter for arduino) doesn't support jogging the machine with a pendant.  I was wondering if it was possible to emulate arrow key inputs on the keyboard through an arduino.


texts: Recently, I bought two Si4463 chips, but I don't know how to use them. It seems complex. I'd like to know if there are any examples of an Si4463 used with an Arduino?


texts:
I have a problem understanding the following code:

PROGMEM  prog_uint16_t x={1232,3232,43343};
rawlen = pgm_read_word_near(x);
memcpy_P(uSendBuff, pfSendBuff+1, rawlen * sizeof(uint16_t));

Why do we need this? -

rawlen * sizeof(uint16_t));

Why not this? -

memcpy_P(uSendBuff, pfSendBuff+1, sizeof(rawlen));


texts: How I can use multi sensor in one code in Arduino?

texts:
How I can use multi smoke sensor in one code? I mean how can I use more than one sensor, where both sensors has the same purpose, like use smoke sensor in multi room. Similar to this code where one is used only. How I can more than one, in Arduino Uno R3,,

<per>
    int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;

void setup() {
  pinMode(redLed, OUTPUT);
 pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}

void loop() {
  int analogSensor = analogRead(smokeA0);

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  // Checks if it has reached the threshold value
  if (analogSensor > sensorThres)
  {
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW);
    tone(buzzer, 1000, 200);
  }
  else
  {
    digitalWrite(redLed, LOW);
    digitalWrite(greenLed, HIGH);
    noTone(buzzer);
  }
  delay(100);
}

How I can add more than one sensor to get same purpose. check detect 1 and detect2 and detect 3 if one of this detection LED Red ON, Thanks`


texts:
I want to read the TCD1304 linear CCD sensor with an ESP32 and I'm facing some problems. As a first "warm-up" and to get familiar with this sensor I tried to generate the sensors input signals using a timer interrupt and bitbanging, but soon I found out that the resulting signals were way to slow and I didn't get any useful readings.
The signals involved are:

SH (shift gate): determines the integration time
ICG (integration clear gate): used to transfer pixel values to the shift register
ΦM: (master clock): self-explanatory
OS: output signal

The timing of those signals seems to be quite critical (see diagram below) and need to be quite fast - supported master clock frequency ist 0.8-4MHz and an analog measurement has to be done after every 4th clock pulse (0.2-1MHz).

Right now I'm pretty lost and I believe that this task requires some progamming techniques that I'm not familiar with so far.
Basically, my question is:
What is the best way to generate those signals and how do I read the ADC at that high sampling rate/accurate in timing?
I have some ideas, but - as I said - I probably lack the required skills, so it's hard for me to decide which approach I should take:

Using a single timer and direct port manipulation:
This would be easy to implement, but my assumption is that the interrupts will fire much too frequently to handle the ISR (which would be more or less complex, even if I refactorize my current test code). Especially reading the ADC will take too much time, I guess.

using the ESP's I2S-ADC:
I have no experience with I2S. From what I understand it is good for reading the ADC with a high frequency, but it is typically used for periodic sampling. In my case I would need the readings to be aligned with the control signals and I don't know if that is possible/convenient with I2S-ADC.

using ADC-DMA:
@esben Rossel has a done great work providing a framwork for STM32s and the TCD1304 in which he uses DMA for readout. I have never used direct memory access, but I feel this is a promising approach. Unfortunately, the documentation of the ADC only covers the ADC-RTC mode while there is no information about how to use the ADC-DMA mode. If DMA is the way to go I appreciate any hints on how I can get started with DMA programming on the ESP32.

In the latter cases 2) and 3) I would still need to generate the driving pulses in a "CPU-friendly" manner, probably hardware PWM (?), while the analog reading has to be triggered at every fourth clock pulse.
Would I use one timer for each signal and if yes, how would I ensure that the signals have the correct phase offset? Also, how can I trigger the analog measurement after every 4th clock pulse?


texts: Unable to turn off SRAM 23LC1024 connected to Arduino

texts:
I'm trying to reset SRAM 23LC1024 (Turn it off and turn it on again) connected to my Arduino Mega 2560. I need to do that because I want to profile the SRAM in an attempt to implement PUF. Currently, I'm able to read and write to SRAM.

I try to cut off the ground connected to SRAM, disable the SPI, but the memory in SRAM is not back to random value (initial value of SRAM if you reset it correctly). To disconnect or connect the ground with SRAM, I used MOSFET. Before cut off the ground, I write 1's to all memory. But, after wait for seconds (or minutes), the value still the same.

Now, the only way to reset the SRAM that I know is by resetting the Arduino itself. Can someone help me?

Below is my code

#include <SPI.h>

//SRAM opcodes

#define RDSR        5
#define WRSR        1
#define READ        3
#define WRITE       2

byte cs_pin = 10; //cs_pin location of the two SRAMS

//uint32_t maxram = 131072; //number of bytes in 23LC1024 SRAM
uint32_t maxpage = 4096;  //number of pages in 23LC1024 SRAM
//uint32_t maxpage = 1024;  //number of pages in 23K256 SRAM

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-*/
//Page transfer Functions
//here we can read and write 32 bytes at each address

void Spi23LC1024Read32(uint32_t address, uint8_t cs_pin, uint8_t* buff)
{
  uint32_t i;
  uint8_t read_page;

  digitalWrite(cs_pin, LOW);
  SPI.transfer(READ);
  SPI.transfer((uint8_t)(address >> 16));
  SPI.transfer((uint8_t)(address >> 8));
  SPI.transfer((uint8_t)address);

  for (i = 0; i < 32; i++)
  {
      read_page = SPI.transfer(0x00);
      buff[i] = read_page;
  }
  digitalWrite(cs_pin, HIGH);
}

void Spi23LC1024Write32(uint32_t address, uint8_t buffer170, uint8_t cs_pin)
{
    uint32_t i;

    digitalWrite(cs_pin, LOW);
    SPI.transfer(WRITE);
    SPI.transfer((uint8_t)(address >> 16));
    SPI.transfer((uint8_t)(address >> 8));
    SPI.transfer((uint8_t)address);

    for (i = 0; i < 32; i++)
    {
        SPI.transfer(buffer170);
    }
    digitalWrite(cs_pin, HIGH);
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-*/

uint32_t i, j, n;
uint32_t value;
uint32_t num = 0;
uint32_t total_send = 10;
uint8_t buff[32];
uint32_t index = 0;
uint8_t total_buff[32*128];
int inByte;

int pin_hold = 11;
int pin_select = 10;
int pin_mosfet = 12;

void readSRAM(){
  SPI.begin();
  digitalWrite(pin_select, LOW);
  digitalWrite(pin_hold, HIGH);
  digitalWrite(pin_mosfet, HIGH);
  delay(100);

// read
  for (j = 0; j < maxpage/128; j++){
    index = 0;
    for (i = 0; i < 128; i++)
    {
      Spi23LC1024Read32(j*128+i, cs_pin,buff);
      memcpy(&total_buff[index], buff, sizeof(buff));
      index += 32;
    }

    for (i = 0; i< index; i++){
      Serial.println(total_buff[i], HEX);
    }
  }

   digitalWrite(pin_select, HIGH);
  digitalWrite(pin_hold, HIGH);
  digitalWrite(pin_mosfet, LOW);

  SPI.end();
}

void writeSRAM(){
  SPI.begin();
  digitalWrite(pin_select, LOW);
  digitalWrite(pin_hold, HIGH);
  digitalWrite(pin_mosfet, HIGH);
  delay(100);

// write
  for (j = 0; j < maxpage/128; j++){
    index = 0;
    for (i = 0; i < 128; i++)
    {
      Spi23LC1024Write32(j*128+i, (uint8_t) 0, cs_pin);
    }
  }

  digitalWrite(pin_select, HIGH);
  digitalWrite(pin_hold, HIGH);
  digitalWrite(pin_mosfet, LOW);

  SPI.end();
}

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

  delay(100);

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(pin_select, OUTPUT);
  pinMode(pin_hold, OUTPUT);
  pinMode(pin_mosfet, OUTPUT);
}

void setup(void)
{
  set();

  readSRAM();

  writeSRAM();
}

void loop()
{
}


texts:
I want to have a LED turn on when I push a button and go off when I push the button a second time.

This code doesn't work:

const int buttonPin = 4;
const int motorPin =  10;
const int ledPin = 6;
 int x = 1;
// variables will change:
int buttonState = 0;

void setup() {
  // initialize the LED pin as an output:
  pinMode(motorPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH && x==1) {
     digitalWrite(motorPin , 1);
     x=0;
    }
  if (buttonState == HIGH && x==0){
    digitalWrite(motorPin, 0);
    x=1;
  }
  delay(1);
}

What could be wrong?


texts:
I am making a circuit which turns a LED on and off through internet. I am connecting an Arduino to a LED and to an Ethernet controller(ENC28J60), but when I make a GET request to the device, it takes too long to respond - around 2 minutes - but my internet connection is fast.Before i get ip "ether.begin(sizeof Ethernet::buffer, mymac,8)" command fails it returns zero still i am able to control it.

Code:

#include <EtherCard.h>

#define STATIC 0

// mac address
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
// ethernet interface ip address
static byte myip[] = { 172,26,40,250 };
// gateway ip address
static byte gwip[] = { 172,26,40,1 };

// LED to control output
int ledPin10 = 10;

byte Ethernet::buffer[700];

const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
""
"<title>"
"Service Temporarily Unavailable"
"</title>"
""
"
This service is currently unavailable
"
"
"
  "The main server is currently off-line.
"
  "Please try again later."
"
"
""
""
;

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

  Serial.begin(9600);
  Serial.println("Trying to get an IP...");

  Serial.print("MAC: ");
  for (byte i = 0; i < 6; ++i) {
    Serial.print(mymac[i], HEX);
    if (i < 5)
      Serial.print(':');
  }

  if (ether.begin(sizeof Ethernet::buffer, mymac,8) == 0)
    Serial.println( "Failed to access Ethernet controller");
  else
    Serial.println("\nEthernet Controller Initialized");

#if STATIC
  Serial.println( "Getting static IP.");
  if (!ether.staticSetup(myip, gwip)){
    Serial.println( "could not get a static IP");

  }
#else

  Serial.println("Setting up DHCP");
  if (!ether.dhcpSetup()){
    Serial.println( "DHCP failed");
  }
#endif

  ether.printIp("My IP: ", ether.myip);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);
}

void loop () {

  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);

  // IF LED10=ON turn it ON
  if(strstr((char *)Ethernet::buffer + pos, "GET /?LED10=ON") != 0) {
  Serial.println("Received ON command");
  digitalWrite(ledPin10, HIGH);
}

// IF LED10=OFF turn it OFF
if(strstr((char *)Ethernet::buffer + pos, "GET /?LED10=OFF") != 0) {
  Serial.println("Received OFF command");
  digitalWrite(ledPin10, LOW);
}

// show some data to the user
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}


texts: Program hangs at am2315.begin() - ideas?

texts:
In working with the AM2315 temperature/humidity sensor, my program hangs at the am2315.begin(); line.

The only output I get is "Serial on"

Here is the code:

#include "cactus_io_AM2315.h"
AM2315 am2315;

void setup() {
     Wire.begin(0X20);
     Serial.begin(9600);
     Serial.println("Serial on");
     Serial.println(am2315.begin());
     Serial.println("- - - - Weather station - - - - - - - -");
     Serial.println(" ");
     Serial.print("RH\t\tTemp (C)\tTemp(F)");
     Serial.println(" ");
}  // end setup

I have tried it both with and without the 10K pull-up resisters and get the same result.  I'm not comfortable including them in any case because I will eventually use I2C&Power to link the I2C bus to many other devices and am not sure what that might do..

Right now none of that is hooked up.  It is just the sensor and the Arduino and the laptop.

Voltages have been measured so I know the device is getting 5V power.

My connections and software are based on this article:  http://cactus.io/hookups/sensors/temperature-humidity/am2315/hookup-arduino-to-am2315-temp-humidity-sensor

UPDATE:  New information:  When I am using I2C&Power, I provide power from only one of the dual-port units.  But I discovered that leaving the SDA and SCL unterminated there it breaks the I2C that is trying to pass through it.  By putting in 4.7K pull-up resistors there it restored the connection.


texts:
I am just playing with the UART interface of my board to learn about how it works. Since I have only one board, I send data out just to receive them by my own board, which is working so far.

Now I wanted to find out what Serial.setTimeout() is for. As per description on the Arduino homepage, it sets the maximum time for to wait for data. The description says, upon others Serial.find() will use it.

So I set Serial.setTimeout() to 100ms, and between sending and trying to receive data, I put a delay of 500ms. Therefore my expectation would be, Serial.find() will not detect a message, since there is more than 100ms no traffic on the bus. But I am still recieving data, it seems that the Serial.setTimeout() has no effect.

What is wrong in my understanding/usage of Serial.setTimeout()?

Here is my example sketch:

#include <M5Stack.h> // needed for my board M5Stack

HardwareSerial Serial2(2); // R2: Recieve Serial2, 17: Transmit Serial2  --> connnect pin R2 and 17

unsigned char buf_recive[1];
unsigned char buf_transmit[2] = {0x42, 0x00};

void setup()
{
  M5.begin();
  Serial.begin(9600);    // setting baud rate for COM3
  Serial2.begin(9600);   // setting baud rate for M5Stack2M5Stack communication
  Serial2.setTimeout(100);    //set the Timeout to 100ms
}

void loop()
{
  delay(500);
  // send buf_transmit
  Serial2.write(buf_transmit, 2);
  delay(500);
  // detect first byte of recieve message
  if (Serial2.find(0x42))
  { //start to read when detect 0x42
    Serial2.readBytes(buf_recive, 1);
    Serial.println(buf_recive[0]);
  }
  buf_transmit[1] = buf_transmit[1] + 0x01; // just to see that something's going on
}

And here some prove, that I am still receiving data:


texts: Couldn't connect to local server using Ethernet Shield and Arduino Mega 2560

texts:
I'm trying to connect the arduino mega and ethernet shield and try to send some data to a php script. I have connect the ethernet shield to the laptop. Lap is connected to router through wi-fi. Any help in advance please.

#include <SPI.h>
#include <Ethernet.h>

/******************** ETHERNET SETTINGS ********************/

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x85, 0xD9 };   //physical mac address
byte ip[] = { 192, 168, 1, 5 };                   // ip in lan
byte subnet[] = { 255, 255, 255, 0 };              //subnet mask
byte gateway[] = { 192, 168, 0, 1 };              // default gateway

IPAddress server(192,168,1,2);
EthernetClient client;

void setup() {
    Serial.begin(9600);  // Initialize serial communications with the PC
    while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    Ethernet.begin(mac,ip,gateway,subnet);     // initialize Ethernet device
    Serial.print("My IP address: ");
    for (byte thisByte = 0; thisByte < 4; thisByte++) {
      Serial.print(Ethernet.localIP()[thisByte], DEC);
      Serial.print(".");
    }
    Serial.println();
    Serial.println("connecting....");
}

void loop()
{
  if (client.connect(server,1234)) { // REPLACE WITH YOUR SERVER ADDRESS
    Serial.println("Server connection OK");
    client.println("GET /add.php?temp1=10&hum1=20 HTTP/1.1");
    client.println("Host:" + server);// SERVER ADDRESS HERE TOO
    client.println("Content-Type: text/plain");
  } else {
    Serial.println("connection failure");
  }

  if (client.connected()) {
    client.stop();// DISCONNECT FROM THE SERVER
    Serial.println("disconnected");
  }

  delay(5000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
}

Serial Out Put

My IP address: 192.168.1.5.
connecting....
connection failure
connection failure
connection failure
connection failure
connection failure
connection failure
connection failure


texts:
what are the SDA & SCL pins in NodeMCU? (Pins 20 & 21 in Arduino MEGA2560) I already implemented a simple project to read 2 accelerometers values from Arduino and send them through wifi to firebase database. I used Arduino Mega before for the same project and the sensors gave me readings between approximately -300 to 300. Now when I moved to NodeMCU the sensors became very sensitive and are getting values up to 65500+. And with a very small angle change the axis reading drop down to 20 or less.

I used pins D1 and D2 for SCL and SDA. Are the pins correct? And What about the reading values how to fix that?


texts: I want to log GPS coordinates using my Arduino and other sensors.  The difficulty is that I will be in forested conditions.  Would it be better to hardwire a gps device to the Arduino or to bluetooth an external device (a much more accurate, Trimble device that I know will give me the accuracy I need)?  Can such devices pair to a bluetooth receiver that would hardwire to my Arduino, or do I need an intermediate device like my iPhone?


texts: Timer interrupt library for new Arduino based on MCU SAMD21

texts:
I'm looking for a timer interrupt library for the new Arduinos based on MCU SAMD21.

I want to wake up periodically the MCU form sleep state, do some task and go sleep again. Using one timer interrupt Arduino wakes up. For new Arduino MKR family.

Do you know a library to do this?


texts: yellow LED not turning off in traffic light simulation

texts:
I wanted to make a simulation of a traffic light, and since I don't have any sensors I used a button to change between the different states (red/stop and green/drive). When the states are changing I wanted to have a short yellow blink-
 just like normal traffic lights work. But in the first state(green), yellow doesn't turn off. In the second the same problem occurs, but if I press the button, that I connected to GPIO pin 2, the LED turns off. It makes no sense to me, as the switch sentence turn off the yellow LED before powering the others (in both cases). In addition, I can't wrap my head around the fact that the yellow LED turns off after I press the button once more, as I only have two cases in the switch sentence, but it now seems like there is three.

void loop() {
// Turn the green led on (GPIO PIN 11) if button pressed once. If button is pressed again switch to yellow then to red.

if(switchLedBtn.pressed()) {
colour = colour + 1;
if(colour > 3) {
  colour = 1;
 }
}

switch(colour) {

// Turn off red, turn on yellow in half a second, then power green (green(0), yellow(1) and red(2))
case 1: digitalWrite(ledPins[2], LOW); digitalWrite(ledPins[1], HIGH); delay(500); digitalWrite(ledPins[1], LOW); digitalWrite(ledPins[0], HIGH);
        break;

// Turn green off, turn yellow on for a second, then power red
case 2: digitalWrite(ledPins[0], LOW); digitalWrite(ledPins[1], HIGH); delay(1000); digitalWrite(ledPins[1], LOW); digitalWrite(ledPins[2], HIGH);
        break;


texts: Is it possible to read somehow VGA port of graphics card by Arduino? Even with some minimal 320 x 240 resolution and minimal frame rate per second, to convert pixels into numbers (for example) somehow. Who can show where to dig?


texts: How can I do this sentence show me in arduino."WARNING: Category 'USB' in library Mouse/keyboard is not valid.Setting to 'Uncategorized'


texts: attiny85: ISR not triggering for PCINT2?

texts:
I am using an attiny85 to read the fan speed reported by a pair of 4-wire fans. I had planned to attach the TACH output from the fans to pins 1 and 2, but I ran into a problem: I was able to handle interrupts on pin 1 without a problem, but I can't get the ISR to trigger for changes on pin 2.  Code demonstrating the problem looks like this:

#define PIN_LED 0
#define PIN_TACH2 2

void setup() {
  cli();
  pinMode(PIN_TACH2, INPUT_PULLUP);
  pinMode(PIN_LED, OUTPUT);

  GIMSK |= _BV(PCIE);
  PCMSK |= _BV(digitalPinToPCMSKbit(PIN_TACH2));
  sei();
}

void loop() {
  digitalWrite(PIN_LED, 1);
  delay(2000);
}

ISR(PCINT0_vect) {
  byte tach2;

  tach2 = (PINB & _BV(PIN_TACH2));

  if (! tach2) {
    digitalWrite(PIN_LED, 0);
  }
}

If I replace the definitions of PIN_TACH2 and PIN_TACH2_INT with
pin 1, such as...

#define PIN_TACH2 1
#define PIN_TACH2_INT PCINT1

...it works just fine (interrupts also works for pins 0 and 3).

Why can't I handle pin change interrupts for pin 2?

for @chrisl

This is just testing code. The LED remains on until the ISR fires, at which point it will go out for up to 2 seconds.  With interrupts attached to pins 1 or 3, it works as expected: a falling edge on the pin causes the LED to go off.

On pin 2, the ISR never triggers.


texts: See compiled assembly output (Visual Micro)

texts: I'm curious about what some of my code is being compiled into, is there a way to have the compiler save the intermediate assembly files, ideally somewhere in the project folder?  I read some forum posts about holding down shift when compiling from the Arduino IDE, but even that seems pretty hackish.


texts: ESP32 Ticker Vs ESP8266 Ticker inside a class

texts:
I'm trying to create a class including Ticker library when using ESP32. A question asked here, concluded the situation. BUT after answered, I could not understand or even implement the answer.
Please you kind assistance


texts: Audio stops playing after rtc is connected

texts:
I am trying to play a song using arduino while at the same time display time using a rtc board using the tmrpcm library. However, if the rtc board is connected no sound is played.

I do understand that the tmrpcm may be interfering with the wire.h library but even commenting the same doesn't resolve the problem.

I am using the following code:

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <RTClib.h>
#include<Wire.h>
#include <Arduino.h>
#include "SevenSegmentTM1637.h"
#include "SevenSegmentExtended.h"
#include "SevenSegmentFun.h"
#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

const int ProxSensor=3;
int inputVal = 0;
#define CLK 8
#define DIO 7

// The amount of time (in milliseconds) between tests
#define TEST_DELAY   2000

SevenSegmentFun    display(CLK, DIO);

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
  Serial.begin(9600);
  if(!SD.begin(SD_ChipSelectPin))
  {
    Serial.println("SD fail");
    return;
  }
  while (!Serial); // for Leonardo/Micro/Zero
  tmrpcm.speakerPin=9;
  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(2019, 10, 19, 01,41,00));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
  pinMode(ProxSensor,INPUT);    //Pin 2 is connected to the output of proximity sensor
  display.begin();
}

void loop(){
  DateTime now = rtc.now();
  display.print((now.unixtime() / 86400L )-17963);
  Serial.print((now.unixtime() / 86400L )-17963);
  while(digitalRead(ProxSensor)==LOW)      //Check the sensor output
  {
    tmrpcm.setVolume(5);
    tmrpcm.play("test.wav");
      repeat:
    if(digitalRead(ProxSensor==LOW))
      goto repeat;
  }
}

Can anyone please help me?


texts: New to Arduino and I have a WIP code for a class. ERROR with LEDs working?

texts:
(EDIT) My goal with this code is to use two potentiometers, pot0 and pot1 respectively, to control 8 leds. Pot0 controls which sequence the leds are running (1, 2, or 3) and pot1 controls which LEDs within each sequence are active. Currently, I am having a problem because I am running Sequence 1 (the first if statement) to my arduino, but I can't seem to make the LEDs light up when being called out by the potentiometer. The only LED that works is LED 0, and that's only if both potentiometers were in the proper positions when the code begins running.

int pot0 = 0;
int pot1 = 1;
int led[] = {7, 6, 5, 4, 3, 2, 1, 0};

void setup() {

for (int i = 0; i < led; i++){
  pinMode(led, OUTPUT)
;}
}
void loop() {
  int potread = analogRead(pot0);
  int val = analogRead(pot1);
  int potR = map(val, 0, 1023, 0, 7);

if (potread <= 341) {
  for (int i; i == potR;)
  digitalWrite(led[i], HIGH);

}

else if (potread <= 682) {

}
else {

}
}


texts: What are the Ramps pins on my Arduino mega?

texts:
I've been working on a 3D printer and I've come to the last step, which is wiring it all up.

The 3D printer I'm making works ONLY with the Arduino Mega. No Ramps. If I need to get Ramps later, I will, but for now, can someone please help me understand which of the Ramps pin goes with which Arduino pin. For example, in the Repetier firmware, the code is like this:

#define X_STEP_PIN         54
#define X_DIR_PIN          55
#define X_ENABLE_PIN       38
#define X_MIN_PIN           3
#define X_MAX_PIN           2

But Arduino doesn't have a 54 and a 55 pin. I've been googling this and I found that Ramps pins 54 - 69  are the same as pins A0 - A15 on the Arduino Mega.

I know this but not for the other pins...

Can someone please tell me the connection of all the Ramps pins to the Arduino pins?

Like: pin 54 on Ramps = A0 on Arduino. I need this for all of the pins.


texts:
I would like to have an array of eight 7- and 8-segment LED numerical displays on my Adafruit Trinket.
I know that there are some prebuilt arrays of 4 LED's. So 2 in array would do just fine.
However, my Adafruit Trinket doesn't have enough ports for that. I have heard something about connecting it to a small piece of controlling hardware that makes me able to have way less ports in need.
What is the appropriate way of connecting a lot of those LED's on only a few ports on a micro controller?

My ideal output would be as follow:
88 88:88:88 or maybe 88 88.88.88
So ideally there would be a small space between the first group of 2 digits and the rest.
Basically, the last 6 digits will represent a time in minutes, seconds and hundreds of seconds.


texts:
I've trying to write my code in plain C++ dropping out the Arduino's IDE. Although I've succeed in compiling the code, whenever I try to upload it to the board it doesn't run, seems that it stucks at some unknown point.

After that, everytime I try to upload a new code to the board it stops responding and avrdude throws this message:

$ ino upload -m leonardo -p /dev/ttyACM1
/dev/ttyACM1 doesn't exist. Is Arduino connected?

It doesn't matter if I unplug and then plug again the board, that message is still showing up.

In order to restart the board, I open the Arduino IDE and then I upload any sketch, then the board comes to live again.

The first time I tried overriding the main() function and the program didn't run I thought it was the tool I was using at that moment, arduino.mk, the one that was doing something strange.

Then I tried the ino tool, but the result was the same.

I don't think avrdude is failing because it actually uploads the .hex to the board.

My original main() code was:

#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    pinMode(LED_PIN, OUTPUT);

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);
    }
    return 0;
}

Then I tried to mimic the one that comes with Arduino:

#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    pinMode(LED_PIN, OUTPUT);

#if defined (USBCON)
    USBDevice.attach();
#endif

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);

        if (serialEventRun) serialEventRun();
    }
    return 0;
}

Sadly, with both codes the board gets stucked at some point.

While I figure out how to solve this issue I've been exercising this solution inside a sketch:

const int LED_PIN = 13;

void setup() {
}

void loop() {
    pinMode(LED_PIN, OUTPUT);

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);
    }
}

Any ideas that led me to a solution? Thank you!


texts: Problem uploading my sketch onto my arduino. Arduino 1.8.13, Linux Ubuntu 20.4

texts:
This is my log, honestly no idea what the problem is here, tried updating java, didnt work.

Sketch uses 11216 bytes (4%) of program storage space. Maximum is 262144 bytes.
Global variables use 2384 bytes (7%) of dynamic memory, leaving 30384 bytes for local variables. Maximum is 32768 bytes.
processing.app.debug.RunnerException
    at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
    at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
    at processing.app.SketchController.upload(SketchController.java:732)
    at processing.app.SketchController.exportApplet(SketchController.java:703)
    at processing.app.Editor$UploadHandler.run(Editor.java:2055)
    at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port '/dev/ttyACM0'.
    at processing.app.Serial.touchForCDCReset(Serial.java:107)
    at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
    ... 5 more
Caused by: jssc.SerialPortException: Port name - /dev/ttyACM0; Method name - openPort(); Exception type - Permission denied.
    at jssc.SerialPort.openPort(SerialPort.java:170)
    at processing.app.Serial.touchForCDCReset(Serial.java:101)
    ... 6 more


texts: How should I initialize a RepRap Discount 12864 on u8glib?

texts:
I was taking the advantage of an existing piece of hardware (RepRapDiscount Full Graphic Smart Controller) for my present project.

Here is a link for the RepRap wiki about the controller

#define LCD_PIN_SCLK   A4
#define LCD_PIN_MOSI   6
#define LCD_PIN_CS   8
U8GLIB_ST7920_128X64_1X u8g(A4,6,8, U8G_PIN_NONE);

But all I got is a blank screen with no light at all. What has happened?


texts: Where should a modified "pins_arduino.h" be stored for Arduino IDE compile?

texts:
Our PCB uses an ATmega2560 chip and uses most of the pins, including some that are not defined in the standard pins_arduino.h module, since that module only provides for the pins that are brought out to headers on the Arduino Mega2560 PCB.

We have a modified pins_arduino.h module that has all pins defined, but it doesn't get included in the Arduino IDE compile.  It was cataloged in the same directory as the standard module (that we renamed original).  The path where the modified module is stored is C:/Arduino/hardware/arduino/avr/variants/mega, where the original was also located.

In the sketch, we added #include "pins_arduino.h" as well as #include <pins_arduino.h>, but neither seemed to have included the modified module, so the extra pins are not accessible.  Putting the module in the same library as the sketch didn't help either.

Any suggestions?


texts: Formula / calculation of the function random() / randomSeed()

texts:
In which file can I find the calculation that is called with random()? If it is not too much could you also post the content in your answer? I am using an Arduino Uno and its standard IDE.

I found this in the "WMath.cpp" but that is not the final calculation.

void randomSeed(unsigned int seed)
{
  if (seed != 0) {
    srandom(seed);
  }
}

long random(long howbig)
{
  if (howbig == 0) {
    return 0;
  }
  return random() % howbig;
}

long random(long howsmall, long howbig)
{
  if (howsmall >= howbig) {
    return howsmall;
  }
  long diff = howbig - howsmall;
  return random(diff) + howsmall;
}


texts: Reconstruct uint32_t from char array to RTC.set

texts:
I am currently experimenting with a Digistump ATTiny85. Since it has no Serial, I use the basic DigiUSB library for communication. The RTC library used is this one: https://github.com/JChristensen/DS3232RTC/. The DigiUSB library is from Digispark.

I attached a DS3232 via TWI to the Digistump, because I want to use this construct as a USB-Realtime-Clock.

Initially setting the time in the setup method works as follows

  RTC.set(1532341020);

But I am unable to transfer the time via the pseudo serial connection and set it remotely. What I've tried so far:

Using union with char and uint32_t. Althougt the char representation is correct (tried DigiUSB.println()), the uint32_t representation of this union is not what I need.
Tried to adapt to some shifting examples, but seriously got lost here. All examples where about 4 byte streams.
atoi and some other functions with no success.

Here is my current sketch

#include <DS3232RTC.h>
#include <DigiUSB.h>

//union ArrayToInteger {
//  char array[10];
//  uint32_t integer;
//};

unsigned char foo[10];
uint32_t num;

void setup() {
  RTC.begin();
  //RTC.set(1532341020);
  DigiUSB.begin();
}

void loop() {
  if (DigiUSB.available() >= 10) {
    for (int i=0; i<=10; i++) {
    foo[i] = DigiUSB.read();
  }
  RTC.set((uint32_t)foo);
  DigiUSB.delay(100);
  DigiUSB.refresh();
  //DigiUSB.println(_foo.array);
  DigiUSB.println(RTC.get());
} else {
  DigiUSB.refresh();
  DigiUSB.println(RTC.get());
  DigiUSB.refresh();
  DigiUSB.delay(1000);
  }
}

In the end I need the a char _foo 0123456789 represented as/converted to uint32_t num 0123456789

Kinda stuck here. Can anyone point me in the right direction ore provide an example?


texts: I purchased the arduino pro mini atmega328 and equipped it with FTDI breakout board with USB, a battery charging board, Wireless transmitter and a wireless receiver.  I'm assuming they can all be connected.  My question is, how do I download programs to the arduino board?  And where might I find specific programs to download?


texts: Arduino Timer 1 Library manipulate Timer value

texts:
I'm using Timer1 library for generation of pulse.
But in my code, at some places i need to change the timer values.
Can anyone suggest the ways to do it.

In below code in place of 370000, I need to change the value after getting some inputs in conditional loops.
Ex. if (x==1) Timer value should be 370000 else 185000.

#include <TimerOne.h>

int count = 0;
int LED = 13;

void setup() {
 pinMode(LED, OUTPUT);
 Timer1.initialize(370000);
 Serial.begin(9600);
}

void loop() {
 Serial.print("Count Value: ");
 Serial.println(count++);
}


texts: I want to use a single Arduino board and link it to both the ANALOG CO2 GAS SENSOR (MG-811 SENSOR) and ANALOG PH SENSOR - METER KIT. I was wondering if the Uno Rev 3 had enough pins or do I have to go with the Mega.


texts: RF 433 Module with VirtualWire: transmit and receive using the same Arduino board

texts:
I was wondering if it was possible to work, in the same Arduino board, both Transmitter and Receiver RF 433 MHz modules. Is it feasible?

Here is the schematics I tried:

1) a pushbutton toggles a state value (0 or 1) and triggers the RF transmitter to send it as a message to the receiver module

2) the RF receiver, whenever reading the message, turns on or off a LED according to the corresponding value (0 or 1)

Here is the source code I wrote:

#include <VirtualWire.h>

#define BTN_PIN A0    // pushbutton que aciona a transmissao
#define LED_PIN 13    // LED aceso ao receber o sinal
#define TX_PIN   4    // ligado ao pino DATA do transmissor RF
#define RX_PIN   7    // ligado ao pino DATA do receptor RF

#define SPEED  5000   // velocidade de comunicacao (bits por segundo)

int estado = 0;

void setup() {
  pinMode(BTN_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);

  vw_set_tx_pin(TX_PIN);  // transmissor
  vw_set_rx_pin(RX_PIN);  // receptor
  vw_setup(SPEED);
  vw_rx_start();

  Serial.begin(9600);
}

void loop() {
  int pressionado = !digitalRead(BTN_PIN);
  char msg[4];

  if (pressionado) {
    estado = !estado;
    itoa(estado, msg, 10);

    vw_send((uint8_t *) msg, strlen(msg));
    vw_wait_tx();

    Serial.print("Mensagem enviada: [");
    Serial.print(msg);
    Serial.println("]");

    delay(500);
  }

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  int recebido = 0;

  memset(msg, 0, 4);
  if (vw_get_message(buf, &buflen)) {

    for (int i = 0; i < buflen; i++)
      msg[i] = char(buf[i]);
    msg[buflen] = '\0';

    Serial.print("Mensagem recebida: [");
    Serial.print(msg);
    Serial.println("]");

    recebido = atoi(msg);

    Serial.print("recebido = ");
    Serial.println(recebido);

    digitalWrite(LED_PIN, recebido);
  }
}

When I run it, according to Serial Monitor it sends the message. The problem is no message comes to the RF receiver.

Does anyone have an idea of what could be wrong?


texts: Arduino Micro just blinks, won't connect to PC

texts:
Edit - Sorry it's a Micro not a Nano

I have a Micro board hooked up to an EasyDriver breakout using its 5V output to power the Micro.

Today I plugged it in and instead of booting up like normal the power LEDs on the wall plug, the easy driver, and the Arduino started flashing. The Micro became very hot, but not hot enough to burn.

After that if I plug the Micro into the USB port it just rapidly blinks the pin 13 LED. The PC does not detect the device but it does receive power.

Holding or pushing the reset button doesn't seem to help at all. I've used different USB cables, and different ports on the PC as well to no effect.

Is this something it can recover from? Why did all the LEDs blink like that?


texts:
I'm working on a small car (<1 kg) which will drive when there is light and stop when there isn't. Below is a plan with code drawn up (the only numbers I know for sure are the current gains for the TIP31C transistor and the rated load current of the 6 V motor I'm using). I'm going to map the analog voltages to a digital signal output.

I read that the maximum digital output was 40 mA and also that analogWrite gives a pulse width modulation (PWM) which can be set to 100% (255) [the code: outputval/1], 50% (127) [the code: outputval/2]. I'm concerned with the lack of control I have here over the current. Will Arduino by default draw 7.75 mA maximum if the input signal is high [giving the output signal also as high]? If not, can I control the current in this manner reliably? Also are there anything I should worry about if I added another 6 V motor in parallel? Coding and electrical suggestions greatly welcomed.

TIP31 transistor: http://www.hobbytronics.co.uk/datasheets/TIP31.pdf

6 V dc motor: http://www.kysanelectronics.com/graphics/RF-370CA-22170.pdf

maximum digital output: https://www.arduino.cc/en/Tutorial/DigitalPins

PWM: https://www.arduino.cc/en/Tutorial/PWM

The code:

const int transistorbase = 9;
void setup() {
  //set the base as digital output:
  pinMode(transistorbase, OUTPUT);
}
void loop() {
  //read voltage at divider:
  int inputval=analogRead(A0);
  //map voltage to digital
  int outputval=map(inputval,0,1023,0,255);
  //control transistor:
  analogWrite(transistorbase,outputval);
}

tl;dr
Codewise, how do I control the digital output current to my needs? Am I seeing ghosts?


texts: Arduino extended database library data type. Is char str[] in Arduino the equivalent of VARCHAR in SQL?

texts:
I am new to Arduino and I am currently working with an Arduino Uno and SD card module - SD/MMC for database storage using the Arduino database library from https://github.com/jwhiddon/EDB.

My question is, is the char str[] type the equivalent of VARCHAR?

Here is my arbitrary record definition for my table:

struct LogEvent {
  int logId;
  int unumber;
  char username[10];
  char fname[15];
  char lname[15];
  char role[6];
  char boxid[10];
  char userStatus[2];
} logEvent;


texts:
I live in India, and unfortunately here the unlicensed band ranges only from 865MHz to 867M Hz. The IBM LoRa code for Arduino (as node) for RFM95 module allow you to choose between 915 Mhz and 868 Mhz only. I initially created a gateway using a Pi3 listening at 865.7 (to conform with Indian rules), but it couldn't receive any payloads from my node running at 868 Mhz. Then, eventually, I tried again with my gateway listening at 868 Mhz, and it worked like a charm. No hiccups.

But, obviously, it seems to be against the rules, and I don't fancy prison. So I want to know if I can get the RFM95 module working somewhere in the range of 865 Mhz to 867 Mhz? And if yes, how can I do it? There certainly doesn't seem to be an option to choose a frequency other than 868 Mhz or 915 Mhz in the IBM Lora code. Here is the link to the code library. https://github.com/matthijskooijman/arduino-lmic


texts: avrdude: stk500v2_getsync(): timeout communicating with programmer error

texts:
When I try to upload I get this error. I cannot upload the program into my Arduino Mega ADK board. I tried putting the drivers agiain too, but it does not work.

avrdude: stk500v2_getsync(): timeout communicating with programmer

Is it the problem with the hardware or the system?
Please help me. Thank you :)


texts: How can configuration values be stored on an ESP8266?

texts:
I have a project that uses an MQTT service, and I'm wondering how to best store the configuration settings (server, user, password, port) for the service as right now they are just hard-coded into some constants.

I saw that EEPROM can be used for this but I'm not sure it is the best way. I went to look at the code for WifiManager to see how it accomplishes this task for the SSID and password since it works so well and it removed its EEPROM dependency back in 2015: https://github.com/tzapu/WiFiManager/commit/659df9cb277c5f93946d9d8795e39a5ae5863ab1

I can't figure out how those settings are persisted.

If EEPROM is the best way for storing something like this, I'd like to write my values without overwriting/corrupting existing values, is that possible? How can I set the initial values of the EEPROM to the constants that I need?

Edit: well after digging into the esp8266/Arduino repository I found that the WiFi.SSID() and WiFi.psk() settings come from wifi_station_get_config and stored with wifi_station_set_config although I haven't found how those work so I think EEPROM might be the way to go here, I just need a bit of guidance and clarification on the right way to use it.


texts:
I'm trying to build a door sensor with the esp8266. I want it to be battery powered and use deepSleep for power saving. I'm going to use a normally closed reed switch between D0 (GPIO16) and RST.

I set the deepsleep to be for about 30 seconds (time to close the door). After that GPIO16 goes LOW and when the door is opened it will close the circuit and connect GPIO16 to RST and reboot the board.

Since the Red onboard LED is connected to GPIO16 and is activated on LOW as well, at the end of deepsleep it turns on.

2 Questions

Is this setup a good approach to powersaving on the esp8266? My concern is how much power setting GPIO16 to LOW uses.
Is it save to just rip off the LED from the board? I figure it being on would be the biggest drain of battery power. I already did some googling and it SEEMS safe? But I trust stack over forums.


texts:
I've been trying to create a sine wave using the pwm function of the Arduino DUE.
The sine wave has te be at higher rates than the analogWrite() function can handle, so I've been using the native capabilties of the SAM3X8E.

To test it, instead of creating sinus I've been doing it linear. The code to do that is:

  REG_PWM_ENA = REG_PWM_SR | B11111111; //enable output
  REG_PWM_CMR3 = 0x00000; //deadtime 0
  REG_PWM_CPRD3 = value;
  REG_PWM_CMR2 = 0x00000; //deadtime 0
  REG_PWM_CPRD2 = value;
  int i =0 ;
  waittime = 100;
  value = 30

  while (!Serial.available()) {
    REG_PWM_OS = 0x0000C;

for (i = 0; i < value; i++) {
      pwmc_duty(i);
      pwmc_duty4(i);
      wait(waittime);
    }

for (i = value; i > 0; i--) {
  pwmc_duty(i);
  pwmc_duty4(i);
  wait(waittime);
}
REG_PWM_OS = 0xC000C;
wait(1);
pwmc_duty(value);
pwmc_duty4(value);
REG_PWM_OS = 0xC0000;

for (i = value; i > 0; i--) {
  pwmc_duty(i);
  pwmc_duty4(i);
  wait(waittime);
}

for (i = 0; i < value; i++) {
  pwmc_duty(i);
  pwmc_duty4(i);
  wait(waittime);
}

REG_PWM_OS = 0xC000C;
wait(1);
pwmc_duty(0);
pwmc_duty4(0);
}

inline void pwmc_duty(unsigned short duty0) {
   // REG_PWM_CPRD3 = duty0;
    REG_PWM_CDTY3 = duty0;
}
inline void pwmc_duty4(unsigned short duty0) {
   // REG_PWM_CPRD3 = duty0;
    REG_PWM_CDTY2 = duty0;
}

void wait(int times){
  for (int i =0;  i < times; i++){
    __asm__("nop\n\t");
  }
}

I expect the code to gradually increase the duty cycle of the signal and than slowly decrease. And that works!
The problem is that i do not get a normal PWM signal out of it.

I've attached one of the previous test signals to this post, with a bit different code, to show the problem.

i've expected the pwm more clear like demonstrated in this paint picture:

How do I get from these spikes to a more normal block signal?


texts:
Can I replace Atmega8 with Atmega328 in my freeduino board?
If so, let me know the steps needed.


texts:
I am building a motion following robot. It has two PIR sensors on the left and right. It has an ultrasonic sensor in the front. When either of the PIR sensors detect motion then it turns to that side.
When both the PIR sensors sense motion then I calculate the distance first( with the ultrasonic sensor, if distance <= 50 cm and > 5 cm then the robot moves forward. But it could mean that the motion is either in the front or in the back. Thus, my robot moves forward even the motion is behind it.
 I need some help devising a method so that when motion is detected behind then the robot will turn back. I tried making the robot turn right when both the sensors detect motion, then it will turn towards the left(i.e. front) or right(i.e. back). But in reality this method is not so practical as it would to a lot of confusion when the intruder we are trying to detect is still in motion. Plz help. A sample sketch would help.


texts:
I have a question regarding the LM35. The sensor is supposed to have values that are to be directly proportional. But instead of the temperature increasing, the sensor values decrease.
This is my setup below. It seems to be a standard setup in different LM35 tutorial pages.

const int sensor= A0; // Assigning analog pin A0 to variable 'sensor'

void setup() {
  pinMode(sensor,INPUT); // Configuring sensor pin as input
  Serial.begin(9600);
}

void loop() {

  float reading=analogRead(sensor); //Reading the value from sensor
  float vout= (reading*5000)/1024;
  float temp= vout/10;

  Serial.print("in DegreeC= ");
  Serial.print(temp);
  Serial.println("");

  delay(500); //Delay of 1 second for ease of viewing

}

These are the results. From room temperature, I applied heat through the use of a lighter and it went lower instead of higher.

I read somewhere that it has something to do with the power supplied by the Arduino. However, when I used a 12V supply to power the Arduino, the readings became very erratic and unstable.
UPDATE:
I have finally returned from the city (Took a long time because of Quarantine Restrictions) and I brought 3 LM35 from another shop. All 3 of the new LM35 worked as intended and didn't lower its temp reading when exposed to heat (With the same configuration). I could rule out these possibilities as to the reason why the LM35 didn't work.
1. Manufacturing Defect - all three of the LM35 didn't work as intended. They all had their temperature lowered when exposed to heat. There could be a defect in the manufacturing process because it doesn't work as advertised. (Leaning towards this)
2. Static Electricity - I remember receiving the LM35 in a plastic bag as packaged by the shop. It could have been affected by static electricity and damaged the circuit inside (on all three though?). The LM35s I received recently had been packaged in those electrostatic discharge protection packaging so it could have probably contributed to it? I need more insight on this I apologize for not being able to properly word it out.
There could be more but these are the most I could come up with as a conclusion.


texts:
I'm a beginner in coding and I have a problem with this code, it doesn't work and after compiling it I get "a function definition is not allowed before '{' token" it's probably just stupid problem but I can't help it
#include <fstream>
using namespace std;
bool spr_poprawne(float a1,float b1, float a2, float b2);
int w_g(float a1,float b1, float a2, float b2);
int w_x(float b1,float b2, float c1, float c2);
int w_y(float a1,float a2, float c1, float c2);
int main(){
    float a1, a2, b1, b2, c1, c2, w, wx, wy, x, y;
    char nazwa[100];
    cout << "Podaj nazwe pliku ";
    cin >> nazwa;
    //utworzenie obiektu klasy ifstream
    ifstream plik_liczby(nazwa);
    if (!plik_liczby){
        cout << "Pliku nie mozna otworzyc " << endl;
    }
    while(!plik_liczby.eof()){
        plik_liczby>>a1, a2, b1, b2, c1, c2, w, wx, wy, x, y;
    cout << "To sa wspolczynniki a1, b1, a2, b2\n";
    cout << a1 << b1 << a2 << b2;
    if(spr_poprawne(a1,b1,a2,b2)){
        cout << "To sa wspolczynniki c1 i c2\n";
        cout << c1 << c2;

        w = w_g(a1,b1,a2,b2);
        wx = w_x(b1,b2,c1,c2);
        wy = w_y(a1,a2,c1,c2);

        if(w != 0){
            x = wx/w;
            y = wy/w;
            cout << "x=" << x << "\n";
            cout << "y=" << y << "\n";
        }

        if((w==0) && (wx==0) && (wy==0))
            cout << "Uklad ma nieskonczonosc rozwiazan";
        if((w==0) && ((wx!=0) || (wy!=0)))
            cout << "Uklad nie ma rozwiazania";
    }

    else
            cout << "Wspolczynniki a1,a2,b1,b2 nie moga rownac sie 0";
        return 0;
    }
    {

    bool spr_poprawne(float a1, float b1, float a2,float b2){

        if((a1!=0)||(b1!=0)||(a2!=0)||(b2!=0))
                return true;
            else
                return false;
    }

    int w_g(float a1,float b1,float a2,float b2){
        return a1*b2-b1*a2;
    }

    int w_x(float b1,float b2, float c1, float c2){
        return c1*b2-b1*c2;
    }

    int w_y(float a1,float a2, float c1, float c2){
        return a1*c2-c1*a2;
    }
}
return 0;
}


texts:
I'm using the ESP32 DevkitC board with Fastlib and a WS2801 LED strip.
The LED strips works fine, i connected it properly (sometimes all LEDs are on, no flickering).

I Connected the light strip's Data cable (blue) to GPIO16 and Clock cable (red) to GPIO17.
Compiling works but at first shows this error:

"No hardware SPI pins defined.  All SPI access will default to bitbanged output"

When the script starts, only the first 3 LEDs are glowing in light blue (instead of blinking) - here's my code:

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 42

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 16
#define CLOCK_PIN 17

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
      // Uncomment/edit one of the following lines for your leds arrangement.
      // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
      // FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);

      // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS);

       FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
}

void loop() {
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);
}

Any ideas what's wrong?


texts: Reading 4 to 20ma pressure sensor using uno

texts:
I have a OsiSense™ XMLP pressure sensor that I want to read from my Arduino uno. This is the circuit I am looking at building for measure 4 to 20 milliamp.

I've read online to find out how to build the circuit.  Can you tell me if it is correct?

Also I dont understand why it works and I'm hoping you can correct my thinking.  Following ohms law we want to leave 5v when 20 milliamps goes through the circuit.  We know the voltage on the circuit is a constant 24 volts (short cable runs) and we know the maximum current is 20 milliamps so my maths says :

Resistance = Voltage  / I (current)

We need to leave 5 volts for the Arduino to read when the sensor is at maximum pressure so we subtract 5 from 24.

Resistance = 19  / 20 milliamp

So the resistor to select to give us a maximum of 5 volts is a 0.95 Kilohms resistor.  I dont see where the 250 ohm resistor comes in? please help.


texts: Boost an audio signal for analog read - Envelope Detector

texts:
I'm working on my first Arduino project and I have a sensitivity issue.

I'm building a module to listen to an audio signal and to start the power source of my speaker with a relay. Everything seems to work fine, but if I drop the volume of my sound, the analog pin doesn't record values (at maximum volume, it peaks at around 50, which is not a lot).

I thought about getting a capacitor but I'm really not sure on what I should get and how the wiring should be done.


texts: Getting error ets jan 8 2013,rst cause:4,boot mode(1,6) wdt reset

texts:
I'm working on a project to send ultrasonic sensor data to my webserver. For that I'm using ESP8266  WiFi module, 3.3V regulator IC by giving input volt of 5v from aduino uno.

I successfully uploaded a code but in serial monitor I got an error

ets jan 8 2013,rst cause:4,boot mode(1,6) wdt reset.

Please, tell what does it mean?

Here is my code. Guide me if I made something wrong. Thanks in  advance.

Note:
Before sending sensor values I successfully send a raw data  manually to webserver, i.e string data, but when I try to send sensor values, I got an error.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "VENTURE 11";
const char* pass = "12345678";

WiFiClient clientx;
const int trigPin = 8;  //Digital port D5
const int echoPin = 9;  //Digital port D6

long duration;
float distance;
float Mdistance;
float MAX_HEIGHT = 0;

void setup() {

  Serial.begin(115200);                                  //Serial connection
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);

  WiFi.begin("VENTURE 11", "12345678");   //WiFi connection
  Serial.println("Setup iniated");
  while (WiFi.status() != 3) {  //Wait for the WiFI connection completion
    delay(500);
    Serial.println("Waiting for connection");
    Serial.print("WIFI STATUS : ");
    Serial.println(String(WiFi.status()));
  }
  Serial.println(String(WiFi.status()));
}

void loop() {
  Serial.println(String(WiFi.status()));
  if (WiFi.status() != 3)
  {
    WiFi.begin("VENTURE", "12345678");   //WiFi connection
    while (WiFi.status() != 3)
    {
      Serial.println("Waiting for connection");
    }
  }
  else
  {
    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;

    if (MAX_HEIGHT == 0) {
      //MAX_HEIGHT = distance;
      Serial.print("Max height has been set to ");
      //Serial.print(distance);
      Serial.println(" cm");
      Serial.println("Waiting for 5 seconds...");
      delay(5000);
    } else {
      Serial.print("Distance:\n");
      Serial.print(distance);
      Serial.print("cm\n");
      Serial.print("Distance:\n");
      Serial.print(distance / 100);
      Serial.print("m\n");
      delay(1000);

    }

    HTTPClient http;
    String Data = "x=" + (String)distance + "&y=" + (String)MAX_HEIGHT + "&z=0";
    //String Data = "x=Finally&y=Did&z=it;)";
    http.begin("http://testingblahblah.000webhostapp.com/IOTCON.php");
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    int sent = http.POST(Data);
    Serial.println(sent);
    String httpPayload = http.getString();
    Serial.println(httpPayload);
    if (sent > 0)
    {
      Serial.println("Message has been sent");
    } else {
      Serial.println("unable to send data");
    }
    delay(20000);

  }
}`


texts: avrdude: stk500_recv(): programmer is not responding AVRDUDE ERROR

texts:
I cannot use any Arduino board such as UNO, Nano , RedBoard something etc.
I am using Mojave 10.14.6 and Arduino IDE 1.8.12.

ERROR :

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
...


texts: Program jumps alone from void loop() to another void

texts:
//simple alarm system
int RipSensor1 = 12;
int RmkeyA = 3;
int RmkeyB = 5;
int RmkeyC = 6;
//--------------------------------------------------------------------------

void setup()
 {
  Serial.begin(9600);
  pinMode(RipSensor1,INPUT);
  pinMode(RmkeyA,INPUT);
  pinMode(RmkeyB,INPUT);
  pinMode(RmkeyC,INPUT);
  pinMode(13,OUTPUT);
  Serial.println(F("System Is Up & Running")); }
  //----------------------------------------------------------------------

void loop()
 {
  Serial.println(F("Main Loop Start"));
  digitalWrite(13,LOW);   //for debugging
  if (digitalRead(RmkeyA) == HIGH)
   {
    Rip1Status();
   }
 }
//----------------------------------------------------------------------

void AlarmSMS1()
 {
  //send sms to admin1
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Serial.println(F("SMS Sending to 1st ADMIN --->"));
  Rip1Status();   // return to this void (monitoring)
 }
//----------------------------------------------------------------------

void Rip1Status()
 {
  Serial.println(F("VOID Rip1 Start..."));
  while (digitalRead(RmkeyB) == LOW) //Arm mode
   {
    digitalWrite(13,HIGH);
    if (digitalRead(RipSensor1) == HIGH) //when Rip sensor sense motion
     {
      Serial.println(F("Movement ALARM --> PowerUP Relay 1 & 2"));
      long RipTimer1 = 0;
      long Rip01 = 0;
      int z = 0;
      int x = 0;
      while (digitalRead(RmkeyC) == LOW)
       {
        RipTimer1++;
        Serial.println(RipTimer1);   //for debugging
        if((z==0) && (RipTimer1 - Rip01 > 500))   //1st CheckPoint do something
         {
          z = 1;
          Serial.println(F("1st CheckPoint OK"));
         }
        else if((x==0) && (RipTimer1 - Rip01 > 3000))   //2nd CheckPoint go on other void
         {
          x = 1;
          AlarmSMS1();
         }
       }
      Serial.println(F("C Key Pressed --> False Alarm"));    //if button C pressed
      RipTimer1 = 0;
      z = 0;
      x = 0;
      Serial.println(F("Monitoring Loop ends --> GoTo Main Loop"));
      break;
     }
    else Serial.println(F("Monitoring"));  //for debugging
   }
  Serial.println(F("B Key Pressed --> Disarming"));  //for debugging
  Serial.println(F("Monitoring Loop ends --> GoTo Main Loop"));
  loop();
 }

I make this code & i have this problem:
Program start & wait for A key pressed to Arm mode. works ok
Press A key go to Arm mode (monitoring). works ok
When its on "monitoring", if i press B key, system disarming then go to void loop() and wait. works ok
When its on "monitoring" & Rip sensor sense movement, then alarm start and if i press C key then disarming as false alarm and go to void loop() and wait. works ok
When its on "monitoring" & Rip sensor sense movement, if i left alarm to complete, go to sms void send sms to admin and return to Rip void (monitoring).
But on this point if i press B button to disarm system this happen...

Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
B Key Pressed --> Disarming
Monitoring Loop ends --> GoTo Main Loop
Main Loop Start
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012.............

Why this happen?
What i am doing wrong?