message:
What Ohm Termination Resistor is needed for this schema ? What, Where and How?

I'm building a Master-Slave system using some arduino pro mini as slaves and a Mega 2560 as Master to communicate over RS485 config via MAX485. Since i'm newbie in RS485 i know that i need to put some termination resistor somewhere is the line but i don't know where and how, also i don't know how much ohm should it be. My Baud rate is 9600 and i'm using twisted pair cable (CAT5) and it's 120 meters long.

**UPDATE 1:**
My goal is to get data from each slave time to time, every slave is connected to a temperature sensor and sends temperature value to master on demand (when master asks for it.) The master asks for temperature value from all slaves separately (of course!) and repeatedly every 500 ms. First it asks slave 1 to send data and then slave 1 sends data to master, then master asks slave 2 to send data and slave 2 sends data to master and so on. after 500 ms, it does this again.

[![please see the schematic photo][1]][1]

  [1]: https://i.stack.imgur.com/Lww5P.jpg

**UPDATE 2:**

Master side code (Mega 2560):

    #include <AltSoftSerial.h>
    #define DE 2 //RS485 Data enable pin. HIGH=Transmit, LOW=Receive
    String inputS = "";
    boolean stringComplete = false;
    AltSoftSerial altSerial;

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

    void loop() {
     digitalWrite(DE, HIGH); //Transmit
     altSerial.println("MEGA:ProMini1");
     altSerial.flush();
     digitalWrite(DE, LOW); //Receive
     CheckAndReceiveFromMax(); //Check if data received
     if(stringComplete){
       inputS.trim();
       if(inputS.equals("ProMini1:ACK"))
        Serial.println("MEGA: ProMini1 Acknowledged: " + inputS);
       else
        Serial.println("MEGA: Not valid On ProMini1: " + inputS);
       stringComplete = false;
       inputS = "";
     }
    delay(100);
    digitalWrite(DE, HIGH); //Transmit
    altSerial.println("MEGA:ProMini2");
    altSerial.flush();
    digitalWrite(DE, LOW); //Receive
    CheckAndReceiveFromMax();
    if(stringComplete){
      inputS.trim();
      if(inputS.equals("ProMini2:ACK"))
        Serial.println("MEGA: ProMini2 Acknowleged: " + inputS);
      else
        Serial.println("MEGA: Not valid On ProMini2: " + inputS);
      stringComplete = false;
      inputS = "";
    }
    delay(500);
    }

    void CheckAndReceiveFromMax()
    {
     while (altSerial.available()) {
     char inChar = (char)altSerial.read();
     inputS1 += inChar;
     if (inChar == '\n')
      stringComplete1 = true;
     }
    }

Slave side code (Pro Mini1):

    #include <AltSoftSerial.h>
    #define DE 7
    String inputS = "";
    boolean stringComplete = false;
    AltSoftSerial altSerial;

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

    void loop() {
     digitalWrite(DE, LOW); //Receive
     CheckAndReceiveFromMax(); //Check if data received
     if(stringComplete){
      Serial.print("String received: ");
      inputS.trim();
      Serial.println(inputS);
      if(inputS.equals("MEGA:ProMini1")){
       Serial.println("ProMini1: Mega called me!");
       digitalWrite(DE, HIGH); //Transmit
       altSerial.println("ProMini1:ACK");
       altSerial.flush();
       digitalWrite(DE, LOW);
      }
     stringComplete = false;
     inputS = "";
     }
    }

    void CheckAndReceiveFromMax()
    {
     while (altSerial.available()) {
     char inChar = (char)altSerial.read();
     inputS += inChar;
     if (inChar == '\n')
      stringComplete1 = true;
     }
    }
And the same code for ProMini2, ProMini3 and so on.

**OUTPUTS:**
When master calls ProMini1, the ProMini2 answers, and when master calls ProMini2, ProMini1 aswers. Also, received data is not always in correct format.

Server Serial Monitor:

     MEGA: Not valid On ProMini1:  roMini1:ACK
      :
    MEGA: Not valid On ProMini2: ProMini1:ACK
    MEGA: Not valid On ProMini1:  roMini1:ACK

    MEGA: Not valid On ProMini2: ProMini1:ACK

    MEGA: Not valid On ProMini2:  roMini1:ACK

.
.
.

body: For low data speeds, like 9600bps, termination is usually not necessary.


sender: user

sender: assistant

body: try 120ohm carbon resistor, not wirewound, at each end of the line ( two resistors in total)


message:
Sending Multiple Information from BNO055 IMU to BridgeClient on Yun

I have an __Arduino Yun__ which is interfaces via __I2C__ to a Adafruit BNO055 breakout board.

My Aim is to use __Python Flask__ in conjunction with __BridgeServer__ and __BridgeClient__ to obtain the Sensor Information from the __ATmega32u4__ microcontroller to the Microprocessor and use __HTML5 Server Side Event (SSE)__ to display live sensor information on Network interfaces.

I would like to show the Euler angles and Linear Acceleration values:

1. heading
2. pitch
3. roll
4. linear_accerlation_x
5. linear_acceleration_y
6. linear_acceleration_z

An Example of similar concept can be obtained from [Smart Measuring Cup by Adafruit](https://github.com/tdicola/SmartMeasuringCup). However, in the code sketch the user sends only one value :

    BridgeClient client;
    ....
    client.println(volume, 5);

And at the __Python Flask__ end the code opens up a socket and uses `makefile()` method to read value

    def yunserver_sse():
     try:
      # Connect to YunServer instance that's listening on localhost.
      soc = socket.create_connection(('localhost', 5678))
      socfile = soc.makefile()
      while True:
       # Get data from server.
       line = socfile.readline()
       # Stop if the server closed the connection.
       if not line:
        raise StopIteration
       # Send the data to the web page in the server sent event format.
       yield 'data: {0}\n\n'.format(line)
       # Sleep so the CPU isn't consumed by this thread.
       time.sleep(0)
     except socket.error:
      # Error connecting to socket. Raise StopIteration to quit.
    raise StopIteration

Instead of sending just _one_ measured parameter how can I send all above mentioned 6 at the same time?

__note__

I tried using __ArduinoJson__ library but I find it difficult to parse the JSON on the Python Flask end as `readline()` expects a `\n` at the end of the string.

body:
Apparently the solution to my problem was a simple `client.println()` after my JSON was ready to be printed to the __BridgeClient__.

__Snippet__:

    root.printTo(client); client.println();

where `root` is `DynamicJsonBuffer` from the __ArduinoJson__ library. The `client.println()` would immediately print `\n` and this would be read by the `readline()` python code.


message:
Arduino Mega 2560 serial port location

I am having trouble finding the serial input (or port whatever) on my mega can someone plz show me a pic of this pin thanks

body:
For information on an Arduino board your first stop should always be the product page, which contains some helpful documentation. For the Mega 2560 the page is https://store.arduino.cc/usa/arduino-mega-2560-rev3. If you had checked there you would see this:

>Serial: 0 (RX) and 1 (TX); Serial 1: 19 (RX) and 18 (TX); Serial 2: 17 (RX) and 16 (TX); Serial 3: 15 (RX) and 14 (TX). Used to receive (RX) and transmit (TX) TTL serial data. Pins 0 and 1 are also connected to the corresponding pins of the ATmega16U2 USB-to-TTL Serial chip.

You will find those pins on the rightmost header on the top edge of the board in this picture:
[![Mega 2560 serial pins][1]][1]

  [1]: https://i.stack.imgur.com/Nwb1D.jpg


message:
Problem : Trigger limit switch to stop DC motor

I want to make a project about automatic gate and garage door via Android app and connected by HC-05 bluetooth module.
Each of the gate and garage door have two limit switches(located at each end of travel) to trigger the DC motor to stop.

I have made some code and do researches, but the DC motor will only stop when I pressed it, if I release it again it will start automatically. I want to make it stop until the bluetooth module send the code again.
I have input the pull-down resistor into the limit switch.

Can anybody please help me?

Here's my current code, thank you

    // Motor for Gate (MotorA)
    int IN1 = 2;
    int IN2 = 3;
    int EnableMotorA = 9;

    // Motor for Garage Door (MotorB)
    int IN3 = 4;
    int IN4 = 5;
    int EnableMotorB = 10;

    const int LimitSwitch1 = A1;
    const int LimitSwitch2 = A2;
    const int LimitSwitch3 = A3;
    const int LimitSwitch4 = A4;

    int state;

    void setup(){
      pinMode(IN1,OUTPUT);
      pinMode(IN2,OUTPUT);
      pinMode(EnableMotorA,OUTPUT);

      pinMode(IN3,OUTPUT);
      pinMode(IN4,OUTPUT);
      pinMode(EnableMotorB,OUTPUT);

      pinMode(LimitSwitch1, INPUT);
      pinMode(LimitSwitch2, INPUT);
      pinMode(LimitSwitch3, INPUT);
      pinMode(LimitSwitch4, INPUT);

      digitalWrite(LimitSwitch1, LOW);
      digitalWrite(LimitSwitch2, LOW);
      digitalWrite(LimitSwitch3, LOW);
      digitalWrite(LimitSwitch4, LOW);

      Serial.begin(9600);
    }

    void loop(){
      if(Serial.available() > 0){
        state = Serial.read();
        }
        if(state == 'A') {
          OpenGate();
          if(digitalRead(LimitSwitch2) == HIGH){
          StopMotorA();
          }
        }
        else if(state == 'B') {
          CloseGate();
          if(digitalRead(LimitSwitch1) == HIGH){
          StopMotorA();
          }
        }
        else if(state == 'C') {
          OpenGarageDoor();
          if(digitalRead(LimitSwitch4) == HIGH){
          StopMotorB();
          }
        }
        else if(state == 'D') {
          CloseGarageDoor();
          if(digitalRead(LimitSwitch3) == HIGH){
          StopMotorB();
          }
        }
    }

    //******************   Motor A control   *******************
    void OpenGate(){
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      analogWrite(EnableMotorA, 250);
      }
    void CloseGate(){
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      analogWrite(EnableMotorA, 250);
    }
    void StopMotorA(){
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, LOW);
      analogWrite(EnableMotorA, 0);
     }
    //******************   Motor B control   *******************
    void OpenGarageDoor(){
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      analogWrite(EnableMotorB, 250);
    }
    void CloseGarageDoor(){
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      analogWrite(EnableMotorB, 250);
    }
    void StopMotorB(){
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, LOW);
      analogWrite(EnableMotorB, 0);
    }
    //**********************************************************

body:
DISCLAIMER: I haven't tested the code in this answer, but I hope there are no problems.

Your code has a major problem: what happens when one gate is moving and you trigger another movement? (reply: something bad). This design issue can be solved by using a standard way of designing these kind of state machine.

In your case a small state machine is what best fits your problem. Better give your states a meaningful name, no?

Ok, so just to start, let's define the states and how to transition through them.

You have basically an idle state, open gate, close gate, open garage door, close garage door. What should you do in these states, both when entering the state and during the time you are in the state? Here is a table to summarize

    State       | Enter         | During time
    ----------------------------------------------
    Idle        | Stop motors   | -
    OpenGate    | Start A dir 1 | -
    CloseGate   | Start A dir 2 | -
    OpenGarage  | Start B dir 1 | -
    CloseGarage | Start B dir 2 | -

The transitions are pretty straightforward. Exit from idle when you receive a (valid) command, exit from the others when you reach the endstop.

The implementation is pretty standard:

    // Motor for Gate (MotorA)
    const byte IN1 = 2;
    const byte IN2 = 3;
    const byte EnableMotorA = 9;

    // Motor for Garage Door (MotorB)
    const byte IN3 = 4;
    const byte IN4 = 5;
    const byte EnableMotorB = 10;

    const byte LimitSwitch1 = A1;
    const byte LimitSwitch2 = A2;
    const byte LimitSwitch3 = A3;
    const byte LimitSwitch4 = A4;

    const byte State_Idle = 0;
    const byte State_OpenGate = 1;
    const byte State_CloseGate = 2;
    const byte State_OpenGarage = 3;
    const byte State_CloseGarage = 4;
    byte currentState;

    void setup(){
     pinMode(IN1,OUTPUT);
     pinMode(IN2,OUTPUT);
     pinMode(EnableMotorA,OUTPUT);

     pinMode(IN3,OUTPUT);
     pinMode(IN4,OUTPUT);
     pinMode(EnableMotorB,OUTPUT);

     pinMode(LimitSwitch1, INPUT);
     pinMode(LimitSwitch2, INPUT);
     pinMode(LimitSwitch3, INPUT);
     pinMode(LimitSwitch4, INPUT);

     Serial.begin(9600);
     currentState = 0xFF; // Force a change to enter the idle state
    }

    void loop(){
     // Check if we need to change state
     byte nextState = currentState;
     switch (currentState)
     {
     case State_Idle:
      { // If we received a valid command, start the operation
       if(Serial.available() > 0)
       {
        switch (Serial.read())
        {
        case 'A':
         nextState = State_OpenGate;
         break;
        case 'B':
         nextState = State_CloseGate;
         break;
        case 'C':
         nextState = State_OpenGarage;
         break;
        case 'D':
         nextState = State_CloseGarage;
         break;
        default:
         // Here you can notify that there was a bad command
         break;
        }
       }
      }
      break;
     case State_OpenGate:
      if(digitalRead(LimitSwitch2)) // == HIGH is not necessary
       nextState = State_Idle;
      break;
     case State_CloseGate:
      if(digitalRead(LimitSwitch1)) // == HIGH is not necessary
       nextState = State_Idle;
      break;
     case State_OpenGarage:
      if(digitalRead(LimitSwitch4)) // == HIGH is not necessary
       nextState = State_Idle;
      break;
     case State_CloseGarage:
      if(digitalRead(LimitSwitch3)) // == HIGH is not necessary
       nextState = State_Idle;
      break;
     default:
      nextState = State_Idle;
      break;
     }

     // If there was a change, switch state and trigger enter condition
     if (nextState != currentState)
     {
      currentState = nextState; // Move in the new state
      switch (currentState)
      { // Entering the new state
      case State_Idle:
       // Stop motor A
       digitalWrite(IN1, LOW);
       digitalWrite(IN2, LOW);
       analogWrite(EnableMotorA, 0);
       // Stop motor B
       digitalWrite(IN3, LOW);
       digitalWrite(IN4, LOW);
       analogWrite(EnableMotorB, 0);
       break;
      case State_OpenGate:
       // Start motor A
       digitalWrite(IN1, LOW);
       digitalWrite(IN2, HIGH);
       analogWrite(EnableMotorA, 250);
       break;
      case State_CloseGate:
       // Start motor A
       digitalWrite(IN1, HIGH);
       digitalWrite(IN2, LOW);
       analogWrite(EnableMotorA, 250);
       break;
      case State_OpenGarage:
       // Start motor B
       digitalWrite(IN3, LOW);
       digitalWrite(IN4, HIGH);
       analogWrite(EnableMotorB, 250);
       break;
      case State_CloseGarage:
       // Start motor B
       digitalWrite(IN3, HIGH);
       digitalWrite(IN4, LOW);
       analogWrite(EnableMotorB, 250);
       break;
      }
     }
    }

(Note: I changed some types because your poor 8-bit uC asked me to avoid complicating its calculations unnecessarily)

One modification to your algorithm is to detach the two loops, since they seem, well, detached.

    // Motor for Gate (MotorA)
    const byte IN1 = 2;
    const byte IN2 = 3;
    const byte EnableMotorA = 9;

    // Motor for Garage Door (MotorB)
    const byte IN3 = 4;
    const byte IN4 = 5;
    const byte EnableMotorB = 10;

    const byte LimitSwitch1 = A1;
    const byte LimitSwitch2 = A2;
    const byte LimitSwitch3 = A3;
    const byte LimitSwitch4 = A4;

    const byte StateA_Idle = 0;
    const byte StateA_Open = 1;
    const byte StateA_Close = 2;
    byte currentStateA;

    const byte StateB_Idle = 0;
    const byte StateB_Open = 1;
    const byte StateB_Close = 2;
    byte currentStateB;

    void setup(){
     pinMode(IN1,OUTPUT);
     pinMode(IN2,OUTPUT);
     pinMode(EnableMotorA,OUTPUT);

     pinMode(IN3,OUTPUT);
     pinMode(IN4,OUTPUT);
     pinMode(EnableMotorB,OUTPUT);

     pinMode(LimitSwitch1, INPUT);
     pinMode(LimitSwitch2, INPUT);
     pinMode(LimitSwitch3, INPUT);
     pinMode(LimitSwitch4, INPUT);

     Serial.begin(9600);
     currentStateA = 0xFF; // Force a change to enter the idle state
     currentStateB = 0xFF; // Force a change to enter the idle state
    }

    void loop()
    {
     byte readChar = 0;
     if(Serial.available() > 0)
      readChar = Serial.read();

     stateMachineA(readChar);
     stateMachineB(readChar);
    }

    void stateMachineA(byte readChar)
    {
     // Check if we need to change state
     byte nextState = currentStateA;
     switch (currentStateA)
     {
     case StateA_Idle:
      { // If we received a valid command, start the operation
       if(readChar > 0)
       {
        switch (readChar)
        {
        case 'A':
         nextState = StateA_Open;
         break;
        case 'B':
         nextState = StateA_Close;
         break;
        default:
         // Here you can notify that there was a bad command
         break;
        }
       }
      }
      break;
     case StateA_Open:
      if(digitalRead(LimitSwitch2)) // == HIGH is not necessary
       nextState = StateA_Idle;
      break;
     case StateA_Close:
      if(digitalRead(LimitSwitch1)) // == HIGH is not necessary
       nextState = StateA_Idle;
      break;
     default:
      nextState = StateA_Idle;
      break;
     }

     // If there was a change, switch state and trigger enter condition
     if (nextState != currentStateA)
     {
      currentStateA = nextState; // Move in the new state
      switch (currentStateA)
      { // Entering the new state
      case StateA_Idle:
       // Stop motor A
       digitalWrite(IN1, LOW);
       digitalWrite(IN2, LOW);
       analogWrite(EnableMotorA, 0);
       break;
      case StateA_Open:
       // Start motor A
       digitalWrite(IN1, LOW);
       digitalWrite(IN2, HIGH);
       analogWrite(EnableMotorA, 250);
       break;
      case StateA_Close:
       // Start motor A
       digitalWrite(IN1, HIGH);
       digitalWrite(IN2, LOW);
       analogWrite(EnableMotorA, 250);
       break;
      }
     }
    }

    void stateMachineB(byte readChar)
    {
     // Check if we need to change state
     byte nextState = currentStateB;
     switch (currentStateB)
     {
     case StateB_Idle:
      { // If we received a valid command, start the operation
       if(readChar > 0)
       {
        switch (readChar)
        {
        case 'C':
         nextState = StateB_Open;
         break;
        case 'D':
         nextState = StateB_Close;
         break;
        default:
         // Here you can notify that there was a bad command
         break;
        }
       }
      }
      break;
     case StateB_Open:
      if(digitalRead(LimitSwitch4)) // == HIGH is not necessary
       nextState = StateB_Idle;
      break;
     case StateB_Close:
      if(digitalRead(LimitSwitch3)) // == HIGH is not necessary
       nextState = StateB_Idle;
      break;
     default:
      nextState = StateB_Idle;
      break;
     }

     // If there was a change, switch state and trigger enter condition
     if (nextState != currentStateB)
     {
      currentStateB = nextState; // Move in the new state
      switch (currentStateB)
      { // Entering the new state
      case StateB_Idle:
       // Stop motor B
       digitalWrite(IN3, LOW);
       digitalWrite(IN4, LOW);
       analogWrite(EnableMotorB, 0);
       break;
      case StateB_Open:
       // Start motor B
       digitalWrite(IN3, LOW);
       digitalWrite(IN4, HIGH);
       analogWrite(EnableMotorB, 250);
       break;
      case StateB_Close:
       // Start motor B
       digitalWrite(IN3, HIGH);
       digitalWrite(IN4, LOW);
       analogWrite(EnableMotorB, 250);
       break;
      }
     }
    }

This second implementation has two parallel state machines (sharing only the serial input). This will allow you to control both gates at the same time (for instance when the gate is closin you can open the garage)


message:
Store RAM and PROGMEM strings in one variable

I want to store a number of strings in an object. Currently I have:

    class MyClass {
      int numStrings = 0;
      ??? strings[20];

      public:
        void addString(const char str[]);
        void print();
    };

    void MyClass::addString(const char str[]) {
      strings[numStrings] = str;
      numStrings++;
    }

    void MyClass::print() {
      for (int i = 0 ; i < numStrings ; i++) {
        Serial.println(strings[i]);
      }
    }

`Serial.println()` works with strings in RAM and in PROGMEM alike.

Is there a type that I can give to my `strings` variable that allows me to store both types of strings?

    MyClass s;

    s.addString("This should work");
    s.addString(F("This should work, too"));

body:
> Is there a type that I can give to my strings variable that allows me to store both types of strings?

No, but you could tag the pointer or add a vector with type information or ultimately use a class hierarchy (BaseString<-SRAMString, PROMEMString).

As a pointer is 16-bit (Arduino Uno) and there is limited amount of SRAM it is possible to add a magic number to pointers to determine the address space.

Obviously the print() member function will have to use the right type and you will also need a new addString for F() strings. Check how F() is defined.

Cheers!


message:
Less hardware dependent development?

I'm working on a little Arduino game project that uses neopixel strips as a display. Uploading every code change to the Arduino and testing it on the LEDs is slow and drains hardware lifetime.

Usually I test as much I can using the Serial Monitor, but I can't get it to clear from code which I learned is only possible e.g. when using a terminal. I did that, but it comes with other issues.

Is there a better way to test code on the dev machine instead of the Arduino?
Is there a best practice to have a Serial Monitor (or anything else) act like a display that I can actually refresh/clear? Serial.println() empty lines to scroll the content is not very practical.

body:
You can unit test your code by creating stubs of the functions you are calling, like replacing a couple of includes with their dumb counterparts.
My friend Jan Beayens did something very valuable on that front and he is also the main author of a good replacement for the Arduino IDE when you start needing some more advanced capabilities: [Sloeber][1] is the product name and it also contains an improved version of the serial monitor with clear and scroll lock capabilities.

Go check it out.

Disclaimer : I'm a contributor of the project

  [1]: http://sloeber.io "Sloeber"


body:
As you've probably noticed, trying to run tests over the serial port is frustrating.  Worse, the relatively large delays associated with writing serial data can affect the accuracy of your measurements.

To cope with this, I wrote my own [unit testing framework for Arduino](https://github.com/ifreecarve/arduino_ci), which lets you fully mock (simulate) the hardware so that you can verify the operation of the software.

There are some [examples of how my library accomplishes that, in the project README](https://github.com/ifreecarve/arduino_ci#using-godmode).  Here is one for pins:

    unittest(pin_history)
    {
      GodmodeState* state = GODMODE();
      int myPin = 3;
      state->reset();            // pin will start LOW
      digitalWrite(myPin, HIGH);
      digitalWrite(myPin, LOW);
      digitalWrite(myPin, LOW);
      digitalWrite(myPin, HIGH);
      digitalWrite(myPin, HIGH);

      assertEqual(6, state->digitalPin[1].size());
      bool expected[6] = {LOW, HIGH, LOW, LOW, HIGH, HIGH};
      bool actual[6];

      // convert pin history to an array, and verify expected results
      int numMoved = state->digitalPin[myPin].toArray(actual, 6);
      assertEqual(6, numMoved);

      // verify each element
      for (int i = 0; i < 6; ++i) {
        assertEqual(expected[i], actual[i]);
      }
    }

You may also like [the example for mocking Serial port data](https://github.com/ifreecarve/arduino_ci#serial-data), although I probably need to improve that documentation.

The beauty of all this is that I was able to develop this framework and all these tests without ever plugging an Arduino board into my computer.


message:
How to save a float variable to the EEPROM?

This is my first post here and I'm hoping there are some Arduino hobbyists here to help me.

Does anyone here know how to save a float variable directly to the EEPROM? If so, could you have a look at the program I wrote and hopefully explain how it would be set up to work with the other 2 variables I'm saving to the EEPROM?

The program I wrote displays a voltmeter to the LCD. The program has an adjustable alarm set point as to when to sound an alarm when the voltage drops below a user-set alarm set point. I want to be able to declare the alarm set point as a float variable and save it directly to the EEPROM. I can't seem to find any programs that I could use as an example to try and figure out how to do that.

I did manage to get my program working to save my Volt_Alarm_Set_Point by declaring it as an int var and then comparing it to my Volt_Set_Point (declared as a float var) to 165 if statements to save the right Volt_Alarm_Set_Point value. And it works a treat but uses up 4956 bytes of program space. That's ok if I'm using an Arduino Mega but I'd like to be able to have my program run on an Arduino Nano which could cause problems with some bigger programs.

If anyone here could show me how to do this it would be greatly appreciated and I would be in your dept. Here is my code below. I don't understand how the code is suppose to be put here? Other forums are dead easy to post code but I can't figure this one out. Sorry about that...
Thanks
jessey

<!-- language: c++ -->

     #include <EEPROM.h>
     #include <LiquidCrystal_I2C.h>
     LiquidCrystal_I2C lcd(0x27, 20, 4);

    //----------Volt Meter Code----------//
        int analogInput = A6;
        float vout = 0.0;
        float vin = 0.0;
        float R1 = 99300.0;
        float R2 = 9970.0;
        int value = 0;
    //----------Volt Meter Code----------//

      int Volt_Alarm_Set_Point; // this works
      float Volt_Set_Point;
    //  float Volt_Alarm_Set_Point; // this dosen't work
      int s = 0;
      int a = 0;
      int b = 0;

     int Button_1 = 5;
     int Button_2 = 6;
     int Button_3 = A1;
     int Button_4 = A0;
     int Alarm_Relay_1 = A3;
     int Relay_2 = A2;
     int Relay_3 = 8;
     int Blinking_Led = 3;// this one is ready to be used anytime

     #define VOLT_ALARM_SET_POINT_ADDR 0
     #define A_ADDR VOLT_ALARM_SET_POINT_ADDR + sizeof(int)
     #define B_ADDR A_ADDR + sizeof(int)

     #define Is_Pressed  0  // used for pushbuttons
     #define Is_Turned_On 1  // used for the relays
     #define Is_Turned_Off 0 // used for the relays

     //|---------void setup---------void setup---------|//
    void setup() {

        pinMode(Alarm_Relay_1, OUTPUT);
        pinMode(Relay_2, OUTPUT);
        pinMode(Relay_3, OUTPUT);
        pinMode(Blinking_Led, OUTPUT);
        pinMode(Button_1, INPUT); // on pin 5
        pinMode(Button_2, INPUT); // on pin 6
        pinMode(Button_3, INPUT); // on pin A1
        pinMode(Button_4, INPUT); // on pin A0
    //-----------Volt Meter Code--------------//
        pinMode(analogInput, INPUT);
    //-----------Volt Meter Code--------------//

        lcd.begin();

        lcd.setCursor(0, 0);
        lcd.print(F("  This Program Is   "));
        lcd.setCursor(0, 1);
        lcd.print(F("to try and save a   "));
        lcd.setCursor(0, 2);
        lcd.print(F("float variable      "));
        lcd.setCursor(0, 3);
        lcd.print(F("to the eeprom       "));
        delay(500);

        lcd.clear();

        EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, Volt_Alarm_Set_Point);
        EEPROM.get(A_ADDR, a);
        EEPROM.get(B_ADDR, b);
    //  EEPROM.put( VOLT_ALARM_SET_POINT_ADDR, Volt_Alarm_Set_Point);
    //  EEPROM.put(A, a);
    //  EEPROM.put(B, b);

    }// end of the void setup()

    //|---------void setup---------void setup---------|//
    //|---------void loop---------void loop---------|//

    void loop() {

        delay(50);
      //increment & decrement Volt_Alarm_Set_Point
        if (digitalRead(Button_1)==Is_Pressed
          ||digitalRead(Button_2)==Is_Pressed)
          {Adjust_The_Volt_Alarm_Set_Point();}

        Read_Volt_Meter();
        //Multiply_By_0_Point_1;
        Display_A_Float_Voltage_Reference();

        lcd.setCursor(0, 0);
        lcd.print(F("This is the Volt adj"));
        lcd.setCursor(0, 1);
        lcd.print(F("Volt Set Pnt = "));

        if (Volt_Alarm_Set_Point<=9){
        lcd.setCursor(16, 1);
        lcd.print(" ");}
        lcd.setCursor(15, 1);
        lcd.print(Volt_Set_Point);

        lcd.setCursor(0,2);
        lcd.print(F("VoltageX= "));
        lcd.setCursor(10, 2);
        lcd.print(vin);

        if (Volt_Alarm_Set_Point<=9){
        lcd.setCursor(17, 2);
        lcd.print(" ");}
        lcd.setCursor(16, 2);
        lcd.print(Volt_Alarm_Set_Point);

        if (vin < Volt_Set_Point){digitalWrite(Relay_3, Is_Turned_On);}
        if (vin > Volt_Set_Point){digitalWrite(Relay_3, Is_Turned_Off);}

        lcd.setCursor(0, 3);lcd.print("A = ");lcd.setCursor(4, 3);lcd.print(a);
        lcd.setCursor(6, 3);lcd.print("B = ");lcd.setCursor(11, 3);lcd.print(b);

        if (a==0) {digitalWrite(Relay_2, Is_Turned_Off);}
        if (a==1) {digitalWrite(Relay_2, Is_Turned_On);}

        if (b==0) {digitalWrite(Alarm_Relay_1, Is_Turned_Off);}
        if (b==1) {digitalWrite(Alarm_Relay_1, Is_Turned_On);}

        if (digitalRead(Button_4)==Is_Pressed){
          if (a==0){a=1;}else{a=0;}
          while (digitalRead(Button_4)==Is_Pressed){
          if (a==0) {digitalWrite(Relay_2, Is_Turned_Off);}
          if (a==1) {digitalWrite(Relay_2, Is_Turned_On);}
          lcd.setCursor(0, 3);lcd.print("A = ");lcd.setCursor(4,3);lcd.print(a);
          lcd.setCursor(6, 3);lcd.print("B = ");lcd.setCursor(11,3);lcd.print(b);
          }
          EEPROM.put(A_ADDR, a); EEPROM.put(B_ADDR, b);
        }

        if (digitalRead(Button_3)==Is_Pressed){
         if (b==0){b=1;}else{b=0;}
         while (digitalRead(Button_3)==Is_Pressed){
         if (b==0) {digitalWrite(Alarm_Relay_1, Is_Turned_Off);}
         if (b==1) {digitalWrite(Alarm_Relay_1, Is_Turned_On);}
         lcd.setCursor(0, 3);lcd.print("A = ");lcd.setCursor(4,3);lcd.print(a);
         lcd.setCursor(6, 3);lcd.print("B = ");lcd.setCursor(11,3);lcd.print(b);
         }
         EEPROM.put(A_ADDR, a); EEPROM.put(B_ADDR, b);
        }
      }// end of the void loop()

    //|---------void loop---------void loop---------|//
    //======= Subroutine Area ======= Subroutine Area =======//
    ///*
    void Display_A_Float_Voltage_Reference()
    {
    if (Volt_Alarm_Set_Point==0){Volt_Set_Point=0.00;}// this code uses 165 if statements for 4956 bytes of program space and 4 bytes of dynamic memory.
    if (Volt_Alarm_Set_Point==1){Volt_Set_Point=0.10;}
    if (Volt_Alarm_Set_Point==2){Volt_Set_Point=0.20;}
    if (Volt_Alarm_Set_Point==3){Volt_Set_Point=0.30;}
    if (Volt_Alarm_Set_Point==4){Volt_Set_Point=0.40;}
    if (Volt_Alarm_Set_Point==5){Volt_Set_Point=0.50;}
    if (Volt_Alarm_Set_Point==6){Volt_Set_Point=0.60;}
    if (Volt_Alarm_Set_Point==7){Volt_Set_Point=0.70;}
    if (Volt_Alarm_Set_Point==8){Volt_Set_Point=0.80;}
    if (Volt_Alarm_Set_Point==9){Volt_Set_Point=0.90;}
    if (Volt_Alarm_Set_Point==10){Volt_Set_Point=1.00;}

    if (Volt_Alarm_Set_Point==11){Volt_Set_Point=1.10;}
    if (Volt_Alarm_Set_Point==12){Volt_Set_Point=1.20;}
    if (Volt_Alarm_Set_Point==13){Volt_Set_Point=1.30;}
    if (Volt_Alarm_Set_Point==14){Volt_Set_Point=1.40;}
    if (Volt_Alarm_Set_Point==15){Volt_Set_Point=1.50;}
    if (Volt_Alarm_Set_Point==16){Volt_Set_Point=1.60;}
    if (Volt_Alarm_Set_Point==17){Volt_Set_Point=1.70;}
    if (Volt_Alarm_Set_Point==18){Volt_Set_Point=1.80;}
    if (Volt_Alarm_Set_Point==19){Volt_Set_Point=1.90;}
    if (Volt_Alarm_Set_Point==20){Volt_Set_Point=2.00;}

    if (Volt_Alarm_Set_Point==21){Volt_Set_Point=2.10;}
    if (Volt_Alarm_Set_Point==22){Volt_Set_Point=2.20;}
    if (Volt_Alarm_Set_Point==23){Volt_Set_Point=2.30;}
    if (Volt_Alarm_Set_Point==24){Volt_Set_Point=2.40;}
    if (Volt_Alarm_Set_Point==25){Volt_Set_Point=2.50;}
    if (Volt_Alarm_Set_Point==26){Volt_Set_Point=2.60;}
    if (Volt_Alarm_Set_Point==27){Volt_Set_Point=2.70;}
    if (Volt_Alarm_Set_Point==28){Volt_Set_Point=2.80;}
    if (Volt_Alarm_Set_Point==29){Volt_Set_Point=2.90;}
    if (Volt_Alarm_Set_Point==30){Volt_Set_Point=3.00;}

    if (Volt_Alarm_Set_Point==31){Volt_Set_Point=3.1;}
    if (Volt_Alarm_Set_Point==32){Volt_Set_Point=3.2;}
    if (Volt_Alarm_Set_Point==33){Volt_Set_Point=3.3;}
    if (Volt_Alarm_Set_Point==34){Volt_Set_Point=3.4;}
    if (Volt_Alarm_Set_Point==35){Volt_Set_Point=3.5;}
    if (Volt_Alarm_Set_Point==36){Volt_Set_Point=3.6;}
    if (Volt_Alarm_Set_Point==37){Volt_Set_Point=3.7;}
    if (Volt_Alarm_Set_Point==38){Volt_Set_Point=3.8;}
    if (Volt_Alarm_Set_Point==39){Volt_Set_Point=3.9;}
    if (Volt_Alarm_Set_Point==40){Volt_Set_Point=4.0;}

    if (Volt_Alarm_Set_Point==41){Volt_Set_Point=4.1;}
    if (Volt_Alarm_Set_Point==42){Volt_Set_Point=4.2;}
    if (Volt_Alarm_Set_Point==43){Volt_Set_Point=4.3;}
    if (Volt_Alarm_Set_Point==44){Volt_Set_Point=4.4;}
    if (Volt_Alarm_Set_Point==45){Volt_Set_Point=4.5;}
    if (Volt_Alarm_Set_Point==46){Volt_Set_Point=4.6;}
    if (Volt_Alarm_Set_Point==47){Volt_Set_Point=4.7;}
    if (Volt_Alarm_Set_Point==48){Volt_Set_Point=4.8;}
    if (Volt_Alarm_Set_Point==49){Volt_Set_Point=4.9;}
    if (Volt_Alarm_Set_Point==50){Volt_Set_Point=5.0;}

    if (Volt_Alarm_Set_Point==51){Volt_Set_Point=5.1;}
    if (Volt_Alarm_Set_Point==52){Volt_Set_Point=5.2;}
    if (Volt_Alarm_Set_Point==53){Volt_Set_Point=5.3;}
    if (Volt_Alarm_Set_Point==54){Volt_Set_Point=5.4;}
    if (Volt_Alarm_Set_Point==55){Volt_Set_Point=5.5;}
    if (Volt_Alarm_Set_Point==56){Volt_Set_Point=5.6;}
    if (Volt_Alarm_Set_Point==57){Volt_Set_Point=5.7;}
    if (Volt_Alarm_Set_Point==58){Volt_Set_Point=5.8;}
    if (Volt_Alarm_Set_Point==59){Volt_Set_Point=5.9;}
    if (Volt_Alarm_Set_Point==60){Volt_Set_Point=6.0;}

    if (Volt_Alarm_Set_Point==61){Volt_Set_Point=6.1;}
    if (Volt_Alarm_Set_Point==62){Volt_Set_Point=6.2;}
    if (Volt_Alarm_Set_Point==63){Volt_Set_Point=6.3;}
    if (Volt_Alarm_Set_Point==64){Volt_Set_Point=6.4;}
    if (Volt_Alarm_Set_Point==65){Volt_Set_Point=6.5;}
    if (Volt_Alarm_Set_Point==66){Volt_Set_Point=6.6;}
    if (Volt_Alarm_Set_Point==67){Volt_Set_Point=6.7;}
    if (Volt_Alarm_Set_Point==68){Volt_Set_Point=6.8;}
    if (Volt_Alarm_Set_Point==69){Volt_Set_Point=6.9;}
    if (Volt_Alarm_Set_Point==70){Volt_Set_Point=7.0;}

    if (Volt_Alarm_Set_Point==71){Volt_Set_Point=7.1;}
    if (Volt_Alarm_Set_Point==72){Volt_Set_Point=7.2;}
    if (Volt_Alarm_Set_Point==73){Volt_Set_Point=7.3;}
    if (Volt_Alarm_Set_Point==74){Volt_Set_Point=7.4;}
    if (Volt_Alarm_Set_Point==75){Volt_Set_Point=7.5;}
    if (Volt_Alarm_Set_Point==76){Volt_Set_Point=7.6;}
    if (Volt_Alarm_Set_Point==77){Volt_Set_Point=7.7;}
    if (Volt_Alarm_Set_Point==78){Volt_Set_Point=7.8;}
    if (Volt_Alarm_Set_Point==79){Volt_Set_Point=7.9;}
    if (Volt_Alarm_Set_Point==80){Volt_Set_Point=8.0;}

    if (Volt_Alarm_Set_Point==81){Volt_Set_Point=8.1;}
    if (Volt_Alarm_Set_Point==82){Volt_Set_Point=8.2;}
    if (Volt_Alarm_Set_Point==83){Volt_Set_Point=8.3;}
    if (Volt_Alarm_Set_Point==84){Volt_Set_Point=8.4;}
    if (Volt_Alarm_Set_Point==85){Volt_Set_Point=8.5;}
    if (Volt_Alarm_Set_Point==86){Volt_Set_Point=8.6;}
    if (Volt_Alarm_Set_Point==87){Volt_Set_Point=8.7;}
    if (Volt_Alarm_Set_Point==88){Volt_Set_Point=8.8;}
    if (Volt_Alarm_Set_Point==89){Volt_Set_Point=8.9;}
    if (Volt_Alarm_Set_Point==90){Volt_Set_Point=9.0;}

    if (Volt_Alarm_Set_Point==91){Volt_Set_Point=9.1;}
    if (Volt_Alarm_Set_Point==92){Volt_Set_Point=9.2;}
    if (Volt_Alarm_Set_Point==93){Volt_Set_Point=9.3;}
    if (Volt_Alarm_Set_Point==94){Volt_Set_Point=9.4;}
    if (Volt_Alarm_Set_Point==95){Volt_Set_Point=9.5;}
    if (Volt_Alarm_Set_Point==96){Volt_Set_Point=9.6;}
    if (Volt_Alarm_Set_Point==97){Volt_Set_Point=9.7;}
    if (Volt_Alarm_Set_Point==98){Volt_Set_Point=9.8;}
    if (Volt_Alarm_Set_Point==99){Volt_Set_Point=9.9;}
    if (Volt_Alarm_Set_Point==100){Volt_Set_Point=10.0;}

    if (Volt_Alarm_Set_Point==101){Volt_Set_Point=10.1;}
    if (Volt_Alarm_Set_Point==102){Volt_Set_Point=10.2;}
    if (Volt_Alarm_Set_Point==103){Volt_Set_Point=10.3;}
    if (Volt_Alarm_Set_Point==104){Volt_Set_Point=10.4;}
    if (Volt_Alarm_Set_Point==105){Volt_Set_Point=10.5;}
    if (Volt_Alarm_Set_Point==106){Volt_Set_Point=10.6;}
    if (Volt_Alarm_Set_Point==107){Volt_Set_Point=10.7;}
    if (Volt_Alarm_Set_Point==108){Volt_Set_Point=10.8;}
    if (Volt_Alarm_Set_Point==109){Volt_Set_Point=10.9;}
    if (Volt_Alarm_Set_Point==110){Volt_Set_Point=11.0;}

    if (Volt_Alarm_Set_Point==111){Volt_Set_Point=11.1;}
    if (Volt_Alarm_Set_Point==112){Volt_Set_Point=11.2;}
    if (Volt_Alarm_Set_Point==113){Volt_Set_Point=11.3;}
    if (Volt_Alarm_Set_Point==114){Volt_Set_Point=11.4;}
    if (Volt_Alarm_Set_Point==115){Volt_Set_Point=11.5;}
    if (Volt_Alarm_Set_Point==116){Volt_Set_Point=11.6;}
    if (Volt_Alarm_Set_Point==117){Volt_Set_Point=11.7;}
    if (Volt_Alarm_Set_Point==118){Volt_Set_Point=11.8;}
    if (Volt_Alarm_Set_Point==119){Volt_Set_Point=11.9;}
    if (Volt_Alarm_Set_Point==120){Volt_Set_Point=12.0;}

    if (Volt_Alarm_Set_Point==121){Volt_Set_Point=12.1;}
    if (Volt_Alarm_Set_Point==122){Volt_Set_Point=12.2;}
    if (Volt_Alarm_Set_Point==123){Volt_Set_Point=12.3;}
    if (Volt_Alarm_Set_Point==124){Volt_Set_Point=12.4;}
    if (Volt_Alarm_Set_Point==125){Volt_Set_Point=12.5;}
    if (Volt_Alarm_Set_Point==126){Volt_Set_Point=12.6;}
    if (Volt_Alarm_Set_Point==127){Volt_Set_Point=12.7;}
    if (Volt_Alarm_Set_Point==128){Volt_Set_Point=12.8;}
    if (Volt_Alarm_Set_Point==129){Volt_Set_Point=12.9;}
    if (Volt_Alarm_Set_Point==130){Volt_Set_Point=13.0;}

    if (Volt_Alarm_Set_Point==131){Volt_Set_Point=13.1;}
    if (Volt_Alarm_Set_Point==132){Volt_Set_Point=13.2;}
    if (Volt_Alarm_Set_Point==133){Volt_Set_Point=13.3;}
    if (Volt_Alarm_Set_Point==134){Volt_Set_Point=13.4;}
    if (Volt_Alarm_Set_Point==135){Volt_Set_Point=13.5;}
    if (Volt_Alarm_Set_Point==136){Volt_Set_Point=13.6;}
    if (Volt_Alarm_Set_Point==137){Volt_Set_Point=13.7;}
    if (Volt_Alarm_Set_Point==138){Volt_Set_Point=13.8;}
    if (Volt_Alarm_Set_Point==139){Volt_Set_Point=13.9;}
    if (Volt_Alarm_Set_Point==140){Volt_Set_Point=14.0;}

    if (Volt_Alarm_Set_Point==141){Volt_Set_Point=14.1;}
    if (Volt_Alarm_Set_Point==142){Volt_Set_Point=14.2;}
    if (Volt_Alarm_Set_Point==143){Volt_Set_Point=14.3;}
    if (Volt_Alarm_Set_Point==144){Volt_Set_Point=14.4;}
    if (Volt_Alarm_Set_Point==145){Volt_Set_Point=14.5;}
    if (Volt_Alarm_Set_Point==146){Volt_Set_Point=14.6;}
    if (Volt_Alarm_Set_Point==147){Volt_Set_Point=14.7;}
    if (Volt_Alarm_Set_Point==148){Volt_Set_Point=14.8;}
    if (Volt_Alarm_Set_Point==149){Volt_Set_Point=14.9;}
    if (Volt_Alarm_Set_Point==150){Volt_Set_Point=15.0;}

    } // end of void Display_A_Float_Voltage_Reference()
    //*/

      void Adjust_The_Volt_Alarm_Set_Point()
     { s=0;
      // push button to increase this Alarm Set Point
      if (digitalRead(Button_2) == Is_Pressed)
         { s=1;
          if (Volt_Alarm_Set_Point <= 150)
          {
           Volt_Alarm_Set_Point = Volt_Alarm_Set_Point  + 1;// this line is using a int variable
           if (Volt_Alarm_Set_Point > 150)
              {Volt_Alarm_Set_Point = 150;}
          }
         }
     // push button to decrease this Alarm Set Point
      if (digitalRead(Button_1) == Is_Pressed)
        { s=1;
         Volt_Alarm_Set_Point = Volt_Alarm_Set_Point  - 1;// this line is using a int variable
         if (Volt_Alarm_Set_Point <= 0)
         {Volt_Alarm_Set_Point = 0;}
        }
        if (s==1){EEPROM.put( VOLT_ALARM_SET_POINT_ADDR,Volt_Alarm_Set_Point);}
     }

    void Read_Volt_Meter()
    {
       //-------------------------------Volt Meter Code-------------------------------//
       //-----------------------------------// This code reads the value at analog
       value = analogRead(analogInput);//---// input A6 and this is where we can change
       vout = (value * 4.72) / 1024.0;//----// the volts value to what the actual supply
       vin = vout / (R2/(R1+R2));//---------// voltage is equal to by checking it with an
       if (vin<0.09) {//--------------------// accurate Digital Votl Meter then entering
       vin=0.0;//---------------------------// it here-->(value * 4.79) changing the 4.79
       }//----------------------------------// to whatever your meter reads...
       //-------------------------------Volt Meter Code-------------------------------//
    }
    //======= Subroutine Area ======= Subroutine Area =======//
    // end the Subroutine Area
    // end of the program...

body:
Since your floating point value always uses only 1 digit after the comma, why not multiply it by 10 and put it in an integer? For a value up to 15.0 (resulting in 150 int), you can use a simple byte and store it in EEPROM directly.

Then you can get rid of all `if` statements. To make a better formula, you can even add rounding *(so adding + 0.5 before converting to an int)*.

Thus:
```c++
EEPROM.put(VOLT_ALARM_SET_POINT_ADDR, (byte) (value * 10.0 + 0.5);
```

And to retrieve the value:
```c++
EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, f);
f = (float) (f / 10.0);
```


body:
@Michel Keijzers

I tried to use the code suggestion you sent but I couldn't get it set up properly to work with-in my code. I do thank you for your answer though. I did manage to figure out a way to save the value of my float variable to an integer and it works good. I'm including the working program below so if anyone ever googles the question I was asking they will find this and hopefully it'll be helpful to them because this works...

```c++
    {
        // this program uses 6986 bytes of program space
    // the old program with all the if statements used 11872 bytes
    // This program uses 4,886 less bytes of program space to accomplish the same thing

     #include <EEPROM.h>
     #include <LiquidCrystal_I2C.h>
     LiquidCrystal_I2C lcd(0x27, 20, 4);

    //----------Volt Meter Code----------//
        int analogInput = A6;
        float vout = 0.0;
        float vin = 0.0;
        float R1 = 99300.0;
        float R2 = 9970.0;
        int value = 0;
    //----------Volt Meter Code----------//

      int Volt_Alarm_Set_Point; // this works
      float Volt_Set_Point;
      int s = 0;
      int a = 0;
      int b = 0;

     int Button_1 = 5;
     int Button_2 = 6;
     int Button_3 = A1;
     int Button_4 = A0;
     int Alarm_Relay_1 = A3;
     int Relay_2 = A2;
     int Relay_3 = 8;
     int Blinking_Led = 3;// this one is ready to be used anytime

     #define VOLT_ALARM_SET_POINT_ADDR 0
     #define A_ADDR VOLT_ALARM_SET_POINT_ADDR + sizeof(int)
     #define B_ADDR A_ADDR + sizeof(int)

     #define Is_Pressed  0  // used for pushbuttons
     #define Is_Not_Pressed  1  // used for pushbuttons
     #define Is_Turned_On 1  // used for the relays
     #define Is_Turned_Off 0 // used for the relays

     //|---------void setup---------void setup---------|//
    void setup() {

        pinMode(Alarm_Relay_1, OUTPUT);
        pinMode(Relay_2, OUTPUT);
        pinMode(Relay_3, OUTPUT);
        pinMode(Blinking_Led, OUTPUT);
        pinMode(Button_1, INPUT); // on pin 5
        pinMode(Button_2, INPUT); // on pin 6
        pinMode(Button_3, INPUT); // on pin A1
        pinMode(Button_4, INPUT); // on pin A0
    //-----------Volt Meter Code--------------//
        pinMode(analogInput, INPUT);
    //-----------Volt Meter Code--------------//

        lcd.begin();

        lcd.setCursor(0, 0);
        lcd.print(F(" This Program Is an "));
        lcd.setCursor(0, 1);
        lcd.print(F("example on how to   "));
        lcd.setCursor(0, 2);
        lcd.print(F("save a float. Named "));
        lcd.setCursor(0, 3);
        lcd.print(F("Save_Float_Using_Int"));
        delay(3500);

        lcd.clear();

        EEPROM.get(VOLT_ALARM_SET_POINT_ADDR, Volt_Alarm_Set_Point);
        EEPROM.get(A_ADDR, a);
        EEPROM.get(B_ADDR, b);

    }// end of the void setup()

    //|---------void setup---------void setup---------|//
    //|---------void loop---------void loop---------|//

    void loop() {

        delay(50);
      //increment & decrement Volt_Alarm_Set_Point
        if (digitalRead(Button_1)==Is_Pressed
          ||digitalRead(Button_2)==Is_Pressed)
          {Adjust_The_Volt_Alarm_Set_Point();}

        Volt_Set_Point = Volt_Alarm_Set_Point*0.1;// this math displays the correct float value to the Lcd

        Read_Volt_Meter();

        lcd.setCursor(0, 0);
        lcd.print(F("This is the Volt adj"));

        if (Volt_Set_Point<10.00)// this if statement gets rid of leftover unwanted #'s
        {lcd.setCursor(19, 1);   // while decrementing the Volt_Set_Point variable
        lcd.print(" ");}
        lcd.setCursor(0, 1);
        lcd.print(F("Volt Set Pnt = "));
        lcd.setCursor(15, 1);
        lcd.print(Volt_Set_Point); // 2nd line of Lcd (displays float variable)

        lcd.setCursor(0,2);
        lcd.print(F("Voltage = "));
        lcd.setCursor(10, 2);
        lcd.print(vin);
        if (Volt_Alarm_Set_Point<10)//this if statement gets rid of leftover unwanted #'s
        {lcd.setCursor(17, 2);      // while decrementing the Volt_Alarm_Set_Point variable
        lcd.print(" ");}
        if (Volt_Alarm_Set_Point<100)// this if statement gets rid of leftover unwanted #'s
        {lcd.setCursor(18, 2);       // while decrementing the Volt_Alarm_Set_Point variable
        lcd.print("  ");}
        lcd.setCursor(16, 2);
        lcd.print(Volt_Alarm_Set_Point);  // 3rd line of Lcd (displays saved integer variable)

        if (vin <= Volt_Set_Point){digitalWrite(Relay_3, Is_Turned_On);}
        if (vin > Volt_Set_Point){digitalWrite(Relay_3, Is_Turned_Off);}

        lcd.setCursor(0, 3);lcd.print("A = ");lcd.setCursor(4, 3);lcd.print(a);
        lcd.setCursor(6, 3);lcd.print("B = ");lcd.setCursor(10, 3);lcd.print(b);

        if (a==0) {digitalWrite(Relay_2, Is_Turned_Off);}
        if (a==1) {digitalWrite(Relay_2, Is_Turned_On);}

        if (b==0) {digitalWrite(Alarm_Relay_1, Is_Turned_Off);}
        if (b==1) {digitalWrite(Alarm_Relay_1, Is_Turned_On);}

        if (digitalRead(Button_4)==Is_Pressed){
          if (a==0){a=1;}else{a=0;}
          while (digitalRead(Button_4)==Is_Pressed){
          if (a==0) {digitalWrite(Relay_2, Is_Turned_Off);}
          if (a==1) {digitalWrite(Relay_2, Is_Turned_On);}
          lcd.setCursor(0, 3);lcd.print("A = ");lcd.setCursor(4,3);lcd.print(a);
          }
          EEPROM.put(A_ADDR, a); EEPROM.put(B_ADDR, b);
        }

        if (digitalRead(Button_3)==Is_Pressed){
         if (b==0){b=1;}else{b=0;}
         while (digitalRead(Button_3)==Is_Pressed){
         if (b==0) {digitalWrite(Alarm_Relay_1, Is_Turned_Off);}
         if (b==1) {digitalWrite(Alarm_Relay_1, Is_Turned_On);}
         lcd.setCursor(6, 3);lcd.print("B = ");lcd.setCursor(10,3);lcd.print(b);
         }
         EEPROM.put(A_ADDR, a); EEPROM.put(B_ADDR, b);
        }
      }// end of the void loop()

    //|---------void loop---------void loop---------|//
    //======= Subroutine Area ======= Subroutine Area =======//

      void Adjust_The_Volt_Alarm_Set_Point()
     { s=0;
      // push button to increase this Alarm Set Point
      if (digitalRead(Button_2) == Is_Pressed)
         { s=1;
          if (Volt_Alarm_Set_Point <= 150)
          {
           Volt_Alarm_Set_Point = Volt_Alarm_Set_Point + 1;// this line is using a int variable
           if (Volt_Alarm_Set_Point > 150)
              {Volt_Alarm_Set_Point = 150;}
          }
         }
     // push button to decrease this Alarm Set Point
      if (digitalRead(Button_1) == Is_Pressed)
        { s=1;
         Volt_Alarm_Set_Point = Volt_Alarm_Set_Point - 1;// this line is using the int variable
         if (Volt_Alarm_Set_Point <= 0)
         {Volt_Alarm_Set_Point = 0;}
        }// the s variable here insures we save once & only when a button is pressed
        if (s==1){EEPROM.put( VOLT_ALARM_SET_POINT_ADDR,Volt_Alarm_Set_Point);}
     }

    void Read_Volt_Meter()
    {
       //-------------------------------Volt Meter Code-------------------------------//
       //-----------------------------------// This code reads the value at analog
       value = analogRead(analogInput);//---// input A6 and this is where we can change
       vout = (value * 4.72) / 1024.0;//----// the volts value to what the actual supply
       vin = vout / (R2/(R1+R2));//---------// voltage is equal to by checking it with an
       if (vin<0.09) {//--------------------// accurate Digital Votl Meter then entering
       vin=0.0;//---------------------------// it here-->(value * 4.79) changing the 4.79
       }//----------------------------------// to whatever your meter reads...
       //-------------------------------Volt Meter Code-------------------------------//
    }
    //======= Subroutine Area ======= Subroutine Area =======//
    // end the Subroutine Area
    // end of the program...
    }
```


message:
Serial Monitor and UART

After uploading the code, can I connect a UART peripheral's RX, TX to TX, RX (D0 ,D1) and use the serial monitor of the arduino together ? Will data reception from the peripheral properly work in this case, or will it conflict with the serial monitor ?

body:
You can *use* the serial monitor in this way, as long as you ensure you do not send anything from the serial monitor out to the Arduino or peripheral, only to monitor data.

That said, if you try to send debug prints from the Arduino to the serial monitor, they will also be sent to the peripheral device, where there may be conflict, depending on the peripheral.

So you technically can, but it's not advised because there are several ways it can go wrong.

One alternative is to use the [SoftwareSerial library][1] to create a second, bit-banged serial port. Note, however, that this library can't operate at high speed (probably best to keep at 9600 bps) reliably.

  [1]: https://www.arduino.cc/en/Reference/SoftwareSerial


message:
Overheating Shift-Register(74HC595)

I am working on a project where I need to use around 50 LED's connected to an Arduino UNO board. To begin with i worked on the tutorial provided by Arduino (https://www.arduino.cc/en/Tutorial/ShiftOut) to connect two shift registers(74HC595). Everything works fine, but the shift registers get very hot in just a few minutes. Is this normal?

body:
I can only think about two things:

1. (least probably): the entrance (VCC) voltage is too high.
2. (most probably): the resistors to the LEDs are (too) low .. Recalculate the values and check the max amperes which can be handled by the output pins of the shift registers.


message:
Error using Adafruit Feather M0

I am trying to upload an empty program on the Adafruit feather to see if it connects to my PC. So far, it isn't. I'm running a Windows 10 and I followed this guide:

https://learn.adafruit.com/adafruit-feather-m0-wifi-atwinc1500?view=all

But I get this error:

Couldn't find a Board on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload.

And the PORT submenu is greyed out.

body:
I found out the issue I was having, though I have a Gemma.

What worked for me:

* Selecting the correct board under "Tools" -> "Board:" (in your case, the Adafruit Feather 32u4 is probably the one you want)
* Selecting the "USBtinyISP" under "Tools" -> "Programmer:"

Then it was able to upload to the Gemma, after hitting it's reset button twice to get it into a 'programming mode' (I don't know if the feather has such a feature).

If you are still having problems make sure that you have properly set up your arduino IDE for adafruit boards, and just play around with settings (try different programmers).

I don't know why it was so hard finding this info out, and why it is not more visible on the documentation to set these things up. I think I found out the 'hitting reset twice' thing somewhere buried in a forum... I digress, but Adafruit does need to consolidate their documentation to make it clearer.

Hope this helps


body: A common problem on Windows for people who may be encountering this type of issue is actually having the wrong USB to UART Bridge drivers or none at all. You can download the most up to date ones [here](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers)


message:
Problem using ICSC (by majenkotech) in RS485 bus

I want to communicate with an RS485 Bus consisting of 5 Arduino Pro Minis as slaves and one Arduino Mega 2560 as Master. I found [a great library][1] for this.

According to the documentation provided by the author of library I can use:

`ICSC icsc(1, 9600, 7); //ID, BaudRate, DEpin`

But I also have to define a Serial port for ICSC to work with:

`ICSC icsc(1, 9600, Serial1);`

I cannot mix these two sentences. I mean I cannot define both **DEpin** and **Serial port** for the ICSC in one sentence. But I need it to be defined. I don't want to use Serial for that, which I need for Serial Monitor. I want to use Serial1 for this. What can I do? I couldn't find any updated documentation about this.

**UPDATE**:

I found out how to define Serial port and DEpin for ICSC. The problem is I cannot get an answer!

Here is Master code:

    #include <ICSC.h>
    ICSC icsc(Serial1, 1, 7); //Stream, ID, DEpin

    void setup() {
      Serial.begin(9600);
      Serial1.begin(9600);
      icsc.begin();
      icsc.registerCommand('R', &showTemperature);
    }

    void loop() {
      icsc.send(2, 'T', 0, NULL);
      icsc.process();
    }

    void showTemperature() {
      Serial.println("ACK");
    }

And here is the Slave code:

    #include <ICSC.h>
    ICSC icsc(Serial, 2, 7); //Stream, ID, DEpin
    String strAck = "ProMini2:ACK";

    void setup() {
      Serial.begin(9600);
      icsc.begin();
      icsc.registerCommand('T', &sendTemperature);
    }

    void loop() {
      icsc.process();
    }

    void sendTemperature() {
      icsc.send(1, 'R', sizeof(strAck) + 1, (char*)&strAck);
    }

Assume that there is just one slave and one master. I tried this code but got no answer. Where is the error?

  [1]: https://github.com/MajenkoLibraries/ICSC

body:
The documentation for the library notes a few different possible initialization methods:

    ICSC.begin(stationId, baudRate);
    ICSC.begin(stationId, baudRate, &SerialPort);
    ICSC.begin(stationId, baudRate, &SerialPort, DEPin);
    ICSC.begin(stationId, baudRate, DEPin);

So, if you need to define both a serial port and DE Pin, use the third option.

**EDIT:** Disregard this answer, as the library has changed initialization methods.


body:
The documentation for the constructors is out of date (I am re-writing as we speak, and is now [here](https://github.com/MajenkoLibraries/ICSC/tree/master/docs)).

The constructors in the header file are like this:

    ICSC(Stream *d, uint8_t station);
    ICSC(Stream &d, uint8_t station);
    ICSC(Stream *d, uint8_t station, int depin);
    ICSC(Stream &d, uint8_t station, int depin);

That means you need to provide the serial object as the first entry:

    ICSC icsc(Serial1, 'A', 5);

You need to manually start the serial object before ICSC.

    void setup() {
        Serial1.begin(9600);
        icsc.begin();
    }

This change was made to enable support for software serial and other Stream based devices.

----

Addendum for your update:

1. Don't spam the sending like you are. Send periodically, not constantly, or you will never be able to receive.
2. You cannot use String objects like that.
3. 1 and 2 aren't good choices of station IDs. Yes, they work, but not great, since 1 is the SOH character.


message:
cheap long lasting options for battery?

I recently made a differential drive using Arduino UNO, two BO dual shaft 9v Motor and ld293d.To power Arduino, I am using a Hi-Watt 9 volt battery, to power the ld293d 5v pin (VCC1) I am using Arduino 5v Vout pin and to power its motor driver pins (VCC2) I am using Hi-Watt 9 volt battery.

The problem is its not long lasting and after moving just a bit like 30 seconds it slows down and stops ,or one of the motor stops working.I have tried this with multiple new 9v batteries, I don't understand why is this happening because the batteries still seems to be work on other projects.Should I use some other kind of battery if yes then what would be the cheapest option?

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/Vws7z.png

body:
9V batteries are not meant for high-current discharge, as you would find when powering a motor. Not only that, they are low capacity. If you need to power motors, you should use batteries such as C or D cells in series to build the voltage required, or try Lithium-Polymer (LiPo) for a rechargeable option.

On a side note, the L293 H-Bridge is a poor choice of H-Bridge these days, especially for a battery-powered project, as there are more efficient motor driver ICs these days.


message:
what is arduino adc reference?

I'm using arduino for the first time and don't really understand what am I suppose to plug to the ADC refernce PIN... or if I even have to use it while plugging analog sensor to the arduino,
thanks!

body:
Well, I think you should read the manual first before you use (and even perhaps brake it).

Generally speaking, analog reference is a voltage value between 0.00 and 5.00V, which will be used as virtual reference for all the analog inputs, you connect to your arduino board.

About analog reference is on Arduino site:
https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/


body:
The AD converter in the ATMega microcontroller (as used in Arduino) converts an **input voltage** to a **number**.

This ADC happens to be 10 bit that means 2^10 states which is 1024.

The number 0 (zero) means 0 Volt input voltage.

The number 1023 means the **maximum** input voltage.

Since 0 is also a value the scale runs from 0 to 1023 making 1024 values.

The scale is linear so 511 means half of that maximum voltage.

*What is this maximum input voltage?*

That is the **ADC Reference voltage**. By default the power supply voltage is used so if you run your Arduino on 5 V, then 1023 = 5 V. But if you run your Arduino on 3.3 V, then 1023 = 3.3 V.

There is also in internal reference of 2.56 V (or 1.1 V depending on your Arduino), if you use that then, you guessed it, 1023 = 2.56 V (or 1.1V).

You might have a very fancy external reference voltage already available and if you want to use that, use the external setting and connect that reference voltage to the AREF pin.

If your analog sensor gives 0 to 5 V and your Arduino is also powered by 5 V then you should use the default setting so that the VCC is used as ADC reference.

If your sensor gives a voltage between 0 and 1 V then you could use the internal reference so that more of the 0 to 1023 range is usable. Giving you get better resolution.


body:
The default behaviour is for the analog reference to be Vcc which on many Arduinos is 5V. In that case *do not* connect anything to AREF.

However if you have a *precision voltage reference* then you can connect that to AREF (and GND) and specify in your sketch, **before doing an analogRead**:

     analogReference (EXTERNAL);

I have a [page about the ADC converter](http://www.gammon.com.au/adc) which may help explain, or may be too much detail. :)

---

> or if I even have to use it while plugging analog sensor to the arduino

Unless you are planning to use some different reference voltage, don't use it at all.

For a 5V Arduino the voltage measured with the default AREF would roughly be 4.88 mV per unit of measurement (ie. 5V / 1024), but more accurately:

    float voltage = ((float) rawADC  + 0.5 ) / 1024.0 * Vref;

---

The voltage you supply to VREF (if you supply any at all) must be between 1.0V and Vcc where Vcc would be 5V for an Arduino Uno.


body:
The AREF is a reference voltage input pin.

The reference voltage is maximum voltage when you measure analog signal.

In other words, you can measure 0V ~ AREF voltage by using ADC port.

Be aware that the minimum voltage of AREF is 1.0V.


message:
boolean always false after 32 seconds

I have a boolean expression (I think it's called), and it will always return false after 32 seconds of running, and I'm very confused now.

    if (millis() > stepTime+lightCmd[stepe][5]) {
      stepe = (stepe+1)%STEPS; //I'm bad at naming variables, sorry
      stepTime = millis();
      Serial.println("changing"); // debugging
    }

This runs inside the main loop.

Also, I've tried using an exponent when trying to get some lights to appear to fade linearly and in about the same amount of time, 32 seconds, it would start fading in reverse.

EDIT:

millis(); wouldn't go backwards after it stopped working

body:
When dealing with `millis` and `micros` you must always use `unsigned long` variables; otherwise, values will be overflow/truncate.

When doing time arithmetic, you must always use differences, not additions, because of the nature of unsigned arithmetic.

Your updated sketch is this:

    void setup()
    {
     Serial.begin(9600);
     while(!Serial);
     Serial.println(); Serial.println("Test");
    }

    #define STEPS 3
    unsigned long lightCmd[STEPS] = {4000, 60000, 90000};
    int stepe = 0;
    unsigned long stepTime = 0;

    void loop()
    {
     if(millis() - stepTime >= lightCmd[stepe]) {
      Serial.print(stepe);
      Serial.print(".- ");
      stepe = (stepe+1)%STEPS; //I'm bad at naming variables, sorry
      stepTime = millis();
      Serial.print(stepTime);
      Serial.println(" changing"); // debugging
     }
    }


message:
Additional Digital Input Pins

I require additional digital input pins for 5 PIR sensors. Can I use the shift register (74HC165) to read these input? And will I be able obtain real time values from all the 5 sensors?

body:
You could use a GPIO expander (MCP23017 or similar) which could give you 14 extra pins (16-2 for I2C bus), but this is putting extra load on the microprocessor.  (you haven't said which one by the way).

Or another option might be to revisit you design and see if you can split it out to multiple processors.  This is effectively the same as a GPIO Expander, just using an Uno or ESP8266 as the expander.


message:
Save a fingerprint to the database of the fingerprint sensor

I'm using the Adafruit Kookye fingerprint module in my project. Since it can only allocate 256 fingerprints I need to make a program to free the memory and add additional users. I have made the following function at the library:

    uint8_t Adafruit_Fingerprint::downloadModel(uint16_t id, uint8_t packet_1[], uint8_t packet_2[], uint8_t slot) {
      uint8_t packet[] = {FINGERPRINT_DOWNLOAD, slot};
      writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
      uint8_t len = getReply(recvPacket);

      if ((len != 1) && (recvPacket[0] != FINGERPRINT_ACKPACKET))
       return -1;
      if (recvPacket[1] == 0x00) {
        writePacket(theAddress, FINGERPRINT_DATAPACKET, sizeof(packet_1)+2, packet_1);
        writePacket(theAddress, FINGERPRINT_DATAPACKET, sizeof(packet_2)+2, packet_2);
        return recvPacket[1];
      } else {
        return recvPacket[1];
      }
    }
This function is working, it puts the fingerprints to the buffer 1 and when I call the function to save with the ID it also works. When I print the fingerprints in the sensor, the structure is exactly the same as if they had been added directly from enrolling. However, when I serach the fingerprints the sensor always returns that the user does not exist.

I don't know what's the problem.

body:
The `sizeof()` operator doesn't do what you think it does. It's not a function that is executed at runtime, it's an operator that is interpreted at compile time.

It takes a variable and returns the size (in bytes) of that variable. Since you are passing it a pointer it gives you the size of that pointer. That's 2 bytes on an 8-bit system like the Uno.

In C an array is not a single entity with a size. It's a pointer to a block of memory that has been reserved at the time the array is declared. All you get is that pointer, and it's up to your program to remember the size.

You will have to pass the size of the arrays your `packet_1` and `packet_2` pointers are pointing to, or always assume that those arrays are the same size at all times.


message:
Possibility to program the ATmega32u4 on the Arduino Yun using a configuration file

Is it possible to send a __Configuration File__ viz. `conf.json` that can be sent to the Arduino Yun via Ethernet and a Python Program can parse the configuration and set for example __Sampling Rate__ of a Sensor which is connected to the __32u4__?

The problem for me is that __Sampling Rate__ in the Arduino Sketch is actually a preprocessor directive and I understand that C++/Arduino Sketches need to be compiled once before the changes take place.

However, how can I change the preprocessor directive in the sketch using a configuration file?

__e.g.__

    #define SAMPLE_RATE (100)

in a `conf.json` file somewhere there might be:

    {"sample_rate": 1000}

Once the `.json` file is parsed using python is it possible to change

    #define SAMPLE_RATE (100) // to #define SAMPLE_RATE (1000)

body:
You can't. You'll have to change your macro into a variable and change that variable when suitable data is received through the serial port.

You may also have to trigger a reconfiguration of whatever software is doing the sampling, or reconfigure the hardware, depending on what it is you are sampling.


message:
How to control a DC Motor with absolute encoder using Arduino and Motor Driver?

I am a beginner in Arduino, I have only basic knowledge and a big appetite :)

I'm working on my cable-cam project. I've made all the mechanical parts by myself, bought all electricity parts through eBay, and everything works fine so far. With the basic RC controller I steer forward / back and I also have a speed potentiometer.

Now there is a question of security:
Since cable-cam runing on a rope fastened to two hubs/buildings/trees/piers,
up to 40 mph.
I would like to have the opportunity to program two points through which the cable-cam cannot overdrive, so that it would not go to the end of the rope and break itself.

THE concept: cable-cam is driven to point A and is marked. Then it is driven to point B and also marked. When the cable-cam reaches point B, it stops and can not go further, but it can go back to point A. And vice versa. Something like a "operation range control points" that can be programmed. Something like this: [end points with Hall sensor][1]

THE idea: on a non-powered wheel (for avoiding slippage and incorrect reading of data on the encoder), I'll set an absolute encoder to measure axis rotations and thus calculate the distance in both directions. The encoder would then be connected to the Arduino that would send the ESC signal to stop the engine when it reached that point, A or B. Stopping should be soft, not at the moment. The speed of the cable cam can be significant, so abrupt stoppage would also be a problem.

So...am I pre-ambitious? I need help with code for Arduino.

Parts:
RC: [Turnigy 9X][2]
ESC:[Syren 50A][3] and it has an Arduino library,
and the encoder:[Koyo TRD NA1024NW][4]

  [1]: https://youtu.be/M1JVqWaG6Yg
  [2]: https://oscarliang.com/turnigy-9x-review-9-channel-rc-transmitter/
  [3]: https://www.dimensionengineering.com/products/syren50
  [4]: http://koyoele.in/Product/Absolute-Rotary-Encoder/TRD-NA1024NW

body:
It is quite difficult to say any thing without the actual code, but if you are reading the position of the cam regularly you can implement a "if/else" condition. Some thing like this:

    if(position==A)
    reverse();
    else
    continue;
(this is very crude and undefined and there are many ways  to improve it)
Here position is assumed to be the position of the cam and A is the maximum that can be traversed to. A same condition can be applied in case of the other end as well. (also reverse() is a function that reverses the direction of motion. In addition to this, you can replace reverse() by some thing like stop() and after that check "position" is greater than A call the reverse function till the condition is met.
Hope this helped.


body:
This is a quite high-level question, so I will answer in general terms,
skipping the fine details. You can ask here more specific questions once
you are implementing the stuff.

Yours is a 10-bit absolute encoder. It can tell you its shaft position
with a resolution of 1/1024 revolution. It's way overkill for your
application. I suggest you connect only the four most significant bits
(pins 9 – 12), which will give you a resolution of 1/16 revolution.

It's better to read the four bits simultaneously. This can be done using
[direct port
manipulation](https://www.arduino.cc/en/Reference/PortManipulation). I
would connect pins 9 – 12 of the encoder to pins 4 – 7 of the Arduino
respectively. As the encoder outputs are open-collector, you have to
enable the pullups in `setup()`:

<!-- language-all: lang-c++ -->

    PORTD |= 0xf0;  // enable pullups on pins 4..7

and you can read the encoder simply as

    uint8_t ecoder_value = PIND & 0xf0;

Notice that this will give you a result that is left-aligned. This way
you can treat it as an 8-bit Gray code.

Next step is to decode the Gray code. I let you research how to do that,
as you can probably find examples, or even ready-made libraries for
that.

Next, you have to extend the value to a wider bit length in order to
know the absolute position of the cable-cam. The encoder only tells you
where you are _within a revolution_, but it doesn't tell you how many
revolutions you did. The extension is done by comparing the current
encoder position with the previous one, taking the difference (which can
be positive or negative), and adding it to the previously computed
absolute position. Something like this:

    int32_t absolute_position;

    void update_absolute_position(uint8_t encoder_position)
    {
        uint8_t old_position = absolute_position;  // extract LSB
        int8_t delta = encoder_position - old_position;
        absolute_position += delta;
    }

Beware of the types of the variables. The type of `delta`, for instance,
ensures that the result of the subtraction is wrapped the correct way to
yield a number between −128 and +127. Thus, the sign will tell you which
is the shortest path (clockwise or counterclockwise) from the previous
to the current position.

Note also that you have to call this function frequently enough: more
than once per half revolution. Otherwise it won't know which direction
the wheel turned. If your `loop()` runs fast enough (you don't use
`delay()`, right?), you just have to call this function once in
`loop()`. Otherwise you would have to setup a timer interrupt to ensure
the updates are frequent enough.

Lastly, you have to define the limits:

    int32_t left_limit = INT32_MIN;
    int32_t right_limit = INT32_MAX;

    // To set the left limit to the current position:
    if (user_pressed_the_relevant_button()) {
        left_limit = absolute_position;
    }
    // and likewise for the right limit.

and condition the maximum speed on the distance to the closets limit.
Assuming you store the speed as a signed number (the sign being the
direction), you would constrain it to always be between a negative
`min_speed` and a positive `max_speed`, which could be updated as
follows:

    // Slow down if close to a position limit.
    if (absolute_position - left_limit < BREAKING_DISTANCE) {
        min_speed = map(absolute_position,
            left_limit, left_limit + BREAKING_DISTANCE,
            0, -ABSOLUTE_MAX_SPEED);
    } else {
        min_speed = -ABSOLUTE_MAX_SPEED;
    }
    if (right_limit - absolute_position < BREAKING_DISTANCE) {
        max_speed = map(absolute_position,
            right_limit - BREAKING_DISTANCE, right_limit,
            +ABSOLUTE_MAX_SPEED, 0);
    } else {
        max_speed = +ABSOLUTE_MAX_SPEED;
    }
    speed_to_apply = constrain(requested_speed, min_speed, max_speed);

Note that this makes the speed limit a linear function of the position.
You may want to look into easing functions to have a smoother breaking.


message:
Connecting two analog multiplexers (CD4051b)

Is it possible to connect two CD4051b analog multiplexers together so that I can receive 14 analog inputs through  them? Just by using one analog pin and three digital pins on the Arduino UNO.

body:
Each CD4052B multiplexes 8 input to one output, and you need three digial pins to control it.  You have the six analogue input pins available and those pins can also serve as digital outputs, so you should be able to use  them to do what you need.

I would do as follows:

Assign three of your spare pins to be digital outputs.  Use these three to address both CD4052Bs together -- so both devices will receive the same addressing.

Connect the output of one CD4052B to the fourth analogue pin, and the output of the second CD4052B to the fifth analogue pin.  These will be your inputs.

On both CD4052Bs, tie the INHIBIT pin low, so they are permanently on.  (If you want to be able to switch them off, for some reason, you an use your sixth pin to control the INHIBIT line on both devices.)

Now when you want to read from sensor 1, you set `000` on the address lines (`A`, `B` and `C`) and read from the first input.  At the same time you'll have sensor 9 on the second input.

It would be well worth reading the [data sheet][1]

  [1]: http://www.ti.com/lit/ds/symlink/cd4052b.pdf "data sheet"


message:
Is this a good function for I2C receive?

I'm trying to fix my I2C code:

Is the following function correct because it has multiple returns. I don't know if that would work.

    uint8_t I2C_rx(uint8_t ack_rx)
    {
        uint8_t i;
        if (ack_rx)
        {
            TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA); // sending ACK
            while (!(TWCR & (1<<TWINT)));
            return TWDR;
        }
        else
        {
            TWCR = (1<<TWINT)|(1<<TWEN);           // sending NACK
            while (!(TWCR & (1<<TWINT)));
            return TWDR;
        }
    }

body:
No problem with multiple returns but it could be reduced to:

    uint8_t I2C_rx(bool ack_rx)
    {
      uint8_t cr = (1<<TWINT) | (1<<TWEN);
      if (ack_rx) cr |= (1<<TWEA);
      TWCR = cr;
      while (!(TWCR & (1<<TWINT)));
      return TWDR;
    }

or

    uint8_t I2C_rx(bool ack_rx)
    {
      TWCR = (1<<TWINT) | (1<<TWEN) | (ack_rx<<TWEA);
      while (!(TWCR & (1<<TWINT)));
      return TWDR;
    }

Cheers!


message:
Disable auto-reset Mega 2560 on serial monitor open using 60 ohm resistor

I tried preventing my Arduino Mega 2560 from restarting every time I open the serial monitor. [This link][1] didn't work for me at all.

I tried connecting the RESET pin to 3.3v pin via a 60 ohm resistor and it worked for me. The question is: If I leave that resistor permanently connected, will this solution damage my board as time passes?

  [1]: http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection

body: A 22uF cap between reset and ground does work on my Mega 2560 - opening the serial monitor will not restart the program. However, the Mega is then not downloadable. Therefore, I grounded the cap thru a normally closed relay and connected its control to a digital output. I normally operate with the relay closed. When I want to download a new program I open the relay first. It works great :-)


message:
How do I import data from serial monitor to excel document without copying and pasting?

I need to be able to import incoming data from a motion sensor and then from the serial monitor (where the data is) import the data to an excel document or file.

Any suggestions would help,

Thanks.

body:
The Arduino IDE's serial monitor is just one of many tools that can open a serial port and collect information from it.

The first step is to make sure the data you are writing to the `Serial` object in the Arduino is in a format suitable for importing into Excel. Separate multiple values on one line with a comma `","` or tab `"\t"` character.

If you are running windows, you can often just use the built-in `type` command from a command prompt to write the serial port to a file:

    type COM4 >> log.txt

(Assuming the Arduino is on COM4 and you want to write the data to a file called `log.txt`.)

If you're on a Mac, open the Terminal app and type:

    screen -L /dev/tty.usbmodem1441335 9600

(Assuming your Arduino is on serial port named `tty.usbmodem1441335` and your port speed is 9600 bps.) The session will be written to a file called `screenlog.0`.

Then you can open the text/log file in Excel. If you rename it to end in `.csv`, that may also help Excel recognize it as tabular data.


message:
What is FaryLink? [Access Point]

When powering up my WeMos D1 ESP8266, I suddenly find this hotspot named "FaryLink". What is this? I programmed the ESP to work as a web server, thus connecting to an existing hotspot and not providing any beacons or acting as an access point.

Google could not provide any information to this behaviour.

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/S91k7.png

What is the purpose of this AP and how can I use / disable it?

body:
Did you use `setmode()` to put it in station mode?

**wifi.setmode()**

Configures the WiFi mode to use. NodeMCU can run in one of four WiFi modes:

 - Station mode, where the NodeMCU device joins an existing network.
 - Access point (AP) mode, where it creates its own network that others can join.
 - Station + AP mode, where it both creates its own network while at the same time being joined to another existing network.
 - WiFi off.

When using the combined Station + AP mode, the same channel will be used for both networks as the radio can only listen on a single channel.

NOTE: WiFi Mode configuration will be retained until changed even if device is turned off.

**Syntax**

    wifi.setmode(mode)

**Parameters**

mode value should be one of

 - wifi.STATION for when the device is connected to a WiFi router. This is often done to give the device access to the Internet.
 - wifi.SOFTAP for when the device is acting only as an access point. This will allow you to see the device in the list of WiFi networks (unless you hide the SSID, of course). In this mode your computer can connect to the device, creating a local area network. Unless you change the value, the NodeMCU device will be given a local IP address of 192.168.4.1 and assign your computer the next available IP address, such as 192.168.4.2.
 - wifi.STATIONAP is the combination of wifi.STATION and wifi.SOFTAP. It allows you to create a local WiFi connection and connect to another WiFi router.
 - wifi.NULLMODE to switch off WiFi

**Returns**

current mode after setup


message:
I can't control my DC motors speed with analogWrite()

I have Arduino Uno and I attached it to 2 DC motors with L298N bridge.
I want to control the speed of the motors so they don't move at maximum speed.
I use `analogWrite()` but it does nothing,and the motors move at maximum speed

Here is my code:

<!-- language: lang-cpp -->

    //motor A
    int enA = 9;
    int in1 = 8;
    int in2 = 7;

    //motor B
    int enB = 3;
    int in3 = 5;
    int in4 = 4;

    void setup() {
      Serial.begin(9600);
      pinMode(enA, OUTPUT);
      pinMode(in1, OUTPUT);
      pinMode(in2, OUTPUT);
      pinMode(enB, OUTPUT);
      pinMode(in3, OUTPUT);
      pinMode(in4, OUTPUT);
    }

    void loop() {

      analogWrite(enA, 0);

      analogWrite(enB, 0);

      digitalWrite (in1, HIGH);
      digitalWrite (in3, HIGH);
      digitalWrite (in2, LOW);
      digitalWrite (in4, LOW);

      delay(50);
    }

body:
analogWrite() can take values between **0** and **255** as its second parameter. Where 255 will give you the maximum motor speed and 0 will give you the lowest (motor will not run).

For example, below code will give you almost the half of max speed.

    analogWrite(enA, 128);
    analogWrite(enB, 128);


body: I did find solutions for the problem. It turned out that the bridge does not work as it should be and the pins of en(A,B) is replaced with the in pins ..now I can control the speed but can't reverse the direction of the motors


message:
Not clear code procedure in Arduino wire library

The application code of sparkFun, has the following line which is difficult to understand.

It's requested 6, because it's requesting 6 bytes for HMC5883L module.

    Wire.requestFrom(address, 6);
    if(6<=Wire.available())

Where:

    int TwoWire::available(void)
    {
      return rxBufferLength - rxBufferIndex;
    }

So, the available function should return `return rxBufferLength - rxBufferIndex;` where `rxBufferIndex` is modified in `read` function:

    int TwoWire::read(void)
    {
      int value = -1;

      // get each successive byte on each call
      if(rxBufferIndex < rxBufferLength){
        value = rxBuffer[rxBufferIndex];
        ++rxBufferIndex;
      }

      return value;
    }

But, my current question is why decrementing `return rxBufferLength - rxBufferIndex;` where `rxBufferIndex` is initialized to 0 all the time, and there's no chance the returned value would be less than 6, because that would terminate the if statement?

body:
`rxBufferLength` is the number of bytes that have been received. `rxBufferIndex` is the byte you would next be handed with a `read()` function call.

So if you have received 6 bytes from the slave (which you will, since that is how many you requested) but not read any the `available` would be 6. Ergo, 6 <= 6. I.e., you asked for 6, it collected 6, and you are checking that it got at least 6 (it can never be >6 since you only asked for 6, so why they look for at least 6 I don't know).

`rxBufferIndex` is never decremented. It is incremented when you read a byte, up until `rxBufferLength == rxBufferIndex` at which point there is 0 bytes available.

----

> But, my current question is why decrementing return rxBufferLength - rxBufferIndex; where  rxBufferIndex is initialized to 0 all the time, and there's no chance the returned value would be less than 6, because that would terminate the if statement?

The way that Wire.h works is that `available()` will always return the number of bytes you requested if the call to `requestFrom()` succeeded until you first read some of that data. If you request 6 and the call worked then you have 6. The `if` could just as well be written as:

    if (Wire.available()) {...

since it will always be 6 immediately after a successful call. However, that makes assumptions about how the Wire API works and could be subject to change in the future or operate differently on different platforms.

So it checks that, right after the call to `requestFrom()` for 6 bytes it actually got *at least* 6 bytes. Without seeing what is inside the conditional `if`, all I can do is make assumptions, but I would assume that it is then reading those 6 bytes, and so it wouldn't care if there happened to be more for some reason. But it doesn't want there to be 5 or fewer bytes available when it is reading 6 of them.

An `if` statement doesn't "terminate" if its condition becomes false once it has been executed. It's not like a `while` that keeps running until it's false - it's a single decision made at a single point in time. If anything changes in the future that would have caused a difference decision to be made (e.g., you `read()` a byte, so `available()` would now return 5), the decision that has been made still stands.

An analogy for you:

You want to go out for a good healthy walk - but only if it's not raining.

    if (!raining) {
        walk_to_shop();
        walk_to_cafe();
        drink_coffee();
        walk_to_shop();
        walk_home();
    }

You go out for your walk to the shops, get a coffee, do some more shopping, and then walk home - but you only *start* doing that if it's not raining. If it starts raining while you're out you don't suddenly teleport back home.  You *could* make the decision, when you come out of the cafe and see it's raining, to cut your shopping trip short, but you have to actively make that decision. Just because `raining` becomes true doesn't affect the fact that you are outside and walking.


message:
Project structure to build for PC and Arduino

Recently I have started developing for Arduino Uno. I have 10 years experience in software development (C#, Delphi), but not much with C/C++.
Compiling the Arduino sketches seems a little slow, and debugging isn't as convenient as it could be on a PC (compile, upload, watch the serial monitor, modify code, start over.... way too slow with lots of unnecessary steps)
So what I would like to achieve is to organize my code in a way to be able to compile my code either to Arduino, or to PC for debugging purposes (to a small console app). I know that there are libraries that cannot be used on a PC, but those can be abstracted away (hidden behind a facade or something like that). Unfortunately I could not find any tutorials, or articles how to do this. So I hope you can help me out.

BTW I'm using Visual Studio (with Visual Micro) on a Windows 10 computer.

body:
I haven't done it yet, but you could do the following things to get a somewhat close approximation:

- Make three different projects, one for the PC (only), e.g. Visual Studio, and one for Arduino (with the default Arduino IDE or e.g. Visual Micro). The last will be a generic library to be used for both the PC and Arduino.
- Use the Arduino specific libraries only for the Arduino project.
- Create facade/wrapper classes for each Arduino library.
- Use a mock/stub for the Arduino libraries in the PC only project.
- Put all non-hardware related code in separate classes, to be used by both projects.
- Write unit tests for the PC only project.
- The PC project will be tested by unit tests, and can be debugged on a PC
- Only the specific Arduino libraries/interfaces have to be tested using the 'hard way', e.g. with Serial.

So the projects (including testing) will look like:

- PC Project
  - References common code
  - Stubs for Arduino libraries, stubs can possibly be reused by PC Unit tests
- PC Unit Tests
  - Unit tests
  - References common code
- Arduino Project
  - Containing Arduino libraries
  - References common code
- Common Code
  - All domain specific classes


message:
someVariable = { somethingThatLooksLikeAFunction }; possible?

Wasn't sure how to title this question...

I was curious whether the title example is possible somehow, and are there any good tricks to using it?

I have been using something similar quite a lot:

    newBool = (someTest) ? true:false;
    newInt  = (x + (y / z));
    [...]

However, I was curious if it was possible to add far more conditions, almost like a function?

For some simple(*) examples:

    someThing = {
        int _x = aFunction(_x);
        if(_x) {
            something = somethingElse;
            for(...){ ... }; // etc
        } else {
            /* otherStuff */
        }
    };

Or

    someThing = {
        for(_x=0;_x<y;_x++){
            z++;
        }
        someThing = (z>y) ? a:b;
    };

I understand it's worth just separating it off into functions most of the time, although I'm trying to get away from a function/library-fest as much as possible...  It's getting annoying crawling through everything when I could just have the useful stuff right there, where I need it, instead of 1000 lines away, or in another library.  It also allows the text editor to fold the code out of sight, starting from one variable, instead of on each clause.

With the few tests I have tried, I've not been successful in achieving what I'm experimenting with, so, is this kind of thing possible in any way? and if so, what are the rules/possibilities/different ways you could implement this?

\* Emphasis on simple! And a semi-pointless/completely useless "function" alert too!  I'm just curious about the "proof of concept" in the examples...

body:
You can do it with a `lambda` function, though the syntax is somewhat cryptic:

    int someThing = [](int y, int z, int a, int b){
        for (int _x = 0; _x < y; _x++) {
            z++;
        }
        return (z > y) ? a : b;
    }(100, 0, 10, 20);

In that you are defining a lamda function `[]` with four parameters, `y`, `z`, `a` and `b`. Then calling that function with four numbers `(100, 0, 10, 20)` and assigning the return value to `someThing`.

It's the same as writing a normal function but there's a lot more brackets around.


message:
How to get Velocity and Displacement from IMU sensor?

I have an imu mounted bot.I want to get the speed of the bot using imu i dont want to use the encoders. Imu gives acceleration how should i integrate that to get velocity and how much error would be there??

body:
The error in this method would be massive.

Velocity is the integration of acceleration over time. However, you don't have acceleration over time - you only have acceleration at discrete points in time - the times that you actually sample the acceleration.

You would want the total acceleration between two points in time, which you just don't have.

Take the following timeline of acceleration points:

    +3 +2 +5 +2 -3 -4 +3 -5 +3 +2 +6 -4 -2 +3 -4 -5 +6 -3 -1 -2 +7 -2
     ^           ^           ^           ^           ^           ^

The carets are the points where you are actually sampling the acceleration.

Assuming you start from 0m/s, and those are all changes in m/s, your calculated speed from your samples would be 3-3+3-2+6+7 = 14m/s.  However, the real velocity would be 7m/s.

In reality, there aren't discrete points of acceleration - just a single smooth waveform.

The faster you can sample the closer to reality you get, but there's always a chance that you would miss some critical brief change in velocity.

On top of that, you have noise. Quantisation noise, vibration, electrical noise, etc - all of which add a certain amount of uncertainty of their own.


message:
How to produce 6 PWM signals with 60 degrees phase shift?

How to produce 6 PWM signals with 60 degrees phase shift using Arduino Uno 6 PWM pins like in the image below?

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/z6r81.gif

body:
Using hardware it's not possible. Simply because you effectively only have three PWM timer units, each with two compare outputs.

That means you have three timebases, which are each compared with two values for two PWM signals each.

You would need a single master timebase with six independent offsettable counters with comparison for your needs.

It would be possible to (roughly) do it in software, though, depending on your needs. You get jitter from software generated PWM, due to interrupts getting in the way of your smooth execution. However you have complete control over how the waveform is generated. Instead of a 0-X duty cycle you could program it to have an X-Y duty cycle. And with all of them taken from the same counter value it's then all synchronised 100%.


body:
Use a timer to trigger an interrupt. Set the timer to 1/6 of the overall pwm cycle to get to 60degree phase. Each time the interrupt is triggered it turns on the next channel.

You could have a second timer and interrupt to turn them off working in the same manner.


body:
I found the correct method for 6-phase PWM as the OP requested. And it can have any duty-cycle you want. My erroneous findings for 50% only duty we're because I used Fast-PWM mode. When I switched to Phase-PWM (mode-10-PWM in a 2560 ARduino), I got the correct waveforms, the same as the OP wanted.

Below is a link to a logic-analyzer snapshot showing the 6-phases from a 2560. The frequency is 500 Hz but that's easy to change. 4 Timers in all used to realize this outcome. 3 Timers used mode-10-PWM, 1 mode-14-PWM at the same frequency.

The full project is documented at Runtime Micro.

[![enter image description here][1]][1]

**EDIT:**
I can now do this using an Uno. But there are limitations to duty-cycle and some other concerns. Provides usable N-channel (2, 3, 4, 5, and 6) phase-shift PWM from a single Uno board.

**EDIT:**
A full 6-channel PSPWM solution using only an Uno is now published at Runtime Micro under [Projects Menu][2]. You'll find details, images, code and diagram. There are limitations such as no channel-to-channel overlap in pulse-width.

FWIW

  [1]: https://i.stack.imgur.com/zFML3.jpg
  [2]: https://runtimemicro.com/Projects/Uno-Phase-Shift-PWM


message:
Code is not working (Matrix keypad)

I am new to Arduino. I am learning from Arduino Cookbook. I was using [tinkercad.com][1] for running my Arduino code. But it is not working.
The Serial monitor should show the key which I have pressed on the keypad.
I think there is some syntactical error in the code, I believe the connection is all right.
Any suggestion will be appreciated.
Please look into this:

<!-- language: lang-cpp -->

    const char keymap[4][4]={
      {'1','2','3','A'},
      {'4','5','6','B'},
      {'7','8','9','C'},
      {'*','0','#','D'}
     };
    const int rpin[]={9,8,7,6};
    const int cpin[]={5,4,3,2};
    void setup()
    {
      Serial.begin(9600);
      Serial.println("Program starting");//for debugging purpose and canbe removed later
      for(int i=0;i<4;i++)
      {
        pinMode(rpin[i],INPUT);
        digitalWrite(rpin[i],HIGH);
      }
      for(int j=0;j<4;j++)
      {
        pinMode(cpin[j],INPUT);
        digitalWrite(cpin[j],HIGH);
      }
    }
    void loop()
    {
      char key=getkey();
      if(key!=0)
      {
       Serial.println(key);
      }
    }
    char getkey()
    {
      char key=0;
      for(int i=0;i<4;i++)
      {
        digitalWrite(rpin[i],LOW);
        for(int j=0;j<4;j++)
        {
          if (digitalRead(cpin[j])==LOW)
          key=keymap[i][j];
        }
        digitalWrite(rpin[i],HIGH);
      }
      return key;
    }

and the connection pic:

[![enter image description here][2]][2]

update 1:
[![enter image description here][3]][3]

  [1]: https://www.tinkercad.com/circuits
  [2]: https://i.stack.imgur.com/xuHI6.png
  [3]: https://i.stack.imgur.com/uuQ41.png

body:
Cited comment:

> Check pin modes. Should be INPUT_PULLUP and OUTPUT. Also, consider
> debouncing. – Mikael Patel

Please, try:

<!-- language-all: lang-cpp-->

    const char keymap[4][4]={
      {'1','2','3','A'},
      {'4','5','6','B'},
      {'7','8','9','C'},
      {'*','0','#','D'}
     };
    const int rpin[]={9,8,7,6};
    const int cpin[]={5,4,3,2};
    void setup()
    {
      Serial.begin(9600);
      Serial.println("Program starting");//for debugging purpose and canbe removed later
      for(int i=0;i<4;i++)
      {
    //Should be INPUT_PULLUP and OUTPUT
        pinMode(rpin[i],OUTPUT);
        pinMode(cpin[i],INPUT_PULLUP);
      }
    }
    void loop()
    {
      char key=getkey();
      if(key!=0)
      {
       Serial.println(key);
       delay(200);              // Also, consider debouncing.
      }
    }
    char getkey()
    {
      char key=0;
      for(int i=0;i<4;i++)
      {
        digitalWrite(rpin[i],LOW);
        for(int j=0;j<4;j++)
        {
          if (digitalRead(cpin[j])==LOW)
          key=keymap[i][j];
        }
        digitalWrite(rpin[i],HIGH);
      }
      return key;
    }


message:
Using signal strength feature of nRF24L01 module

This is a walkie-talkie project and this circuit really worked, voice can be transmitted from one nRF module to another nRF. Additionally, I want to observe how well the signal strength is, by lighting up an LED.

 [![enter image description here][1]][1]

They talked about a test.RPD function [here][2] in order to do that. But it is said that we can't use this with nRF24L01, but can use only with nRF24L01P (I don't know what is the difference).

>
Test whether a signal (carrier or otherwise) greater than
or equal to -64dBm is present on the channel. Valid only
on ***nRF24L01P*** (+) hardware. On ***nRF24L01***, use testCarrier().
Useful to check for interference on the current channel and
channel hopping strategies.
@return true if signal => -64dBm, false if not
*/

---

***Can't we use it in nRF24L01 really?***

If I cannot use this how can I use the `testCarrier` function to light up an LED (as Bright, Low and Off) as mentioned in the quote?

If I can use this, what changes in the code should be done? (The member TmrhProjects talked about it a little)

---

He also hints to this code.

    bool rpd = radio.testRPD();

    while (radio.available()) {
      signalStrength = rpd + 1;
      radio.read, etc...
    }

**Should we write the above code in the `RF24.h` file or should we write it directly into the Arduino's main sketch?**

  [1]: https://i.stack.imgur.com/M2FaV.png
  [2]: https://forum.mysensors.org/topic/1022/nrf24l01-signal-strength-request/6
  [3]: https://i.stack.imgur.com/eHtvJ.png

body:
To get the signal strength just send 100 packets with no retries and see how many times the packet arrives.

    radio.begin();
    radio.setRetries(0,0); // by default nrf tries 15 times. Change to no retries to measure strength

    char buffer[32];
    int counter = 0;

    for(int i=0; i<100; i++)
    {
       int status = radio.send(buffer,32); // send 32 bytes of data. It does not matter what it is
       if(status)
           counter++;

       delay(1); // try again in 1 millisecond
    }

    // if counter > 80 signal strength is great
    {

    }

    // else if counter > 60 signal strength is good
    {

    }

    // etc

    radio.setRetries(5,15); change back to its default when done.

For this code to work the receiver must be listening for data. Just listen for data on the receiver there is no need to validate the data.