text:
Not enough memory error using OneSheeld.h
I'm a dairy farmer and I'm new to playing around with Arduino's. I created a code to send me SMS's when my equipment stops working as it should, but I run into a "Not enough memory" error. Here's my code:
#include <OneSheeld.h>
int IPFeed = 13;
int IPScraper = 12;
int IPPump = 11;
int XVal = 0;
int TFeedCharge = 0;
int TFeedRun = 0;
int TScraper = 0;
int TPump = 0;
int TLFeedCharge = 60;
int TLFeedRun = 60;
int TLManure = 2;
int TInc = 60000;

void setup() {
  pinMode(IPFeed, INPUT);
  pinMode(IPScraper, INPUT);
  pinMode(IPPump, INPUT);
  OneSheeld.begin();
}

void loop() {
  XVal = digitalRead(IPFeed);
  if (XVal == HIGH) {
    TFeedRun = 0;
    TFeedCharge = TFeedCharge +1;
    if (TFeedCharge == TLFeedCharge) {
      delay(150);
      SMS.send("613xxxxxx6","ProFeed 2020 is stoped at the charging station.");
      delay(150);
      SMS.send("613xxxxxx9","ProFeed 2020 is stoped at the charging station.");
      TFeedCharge = 0;
    }
  }
  else {
    TFeedCharge = 0;
    TFeedRun = TFeedRun +1;
    if (TFeedRun == TLFeedRun) {
      delay(150);
      SMS.send("613xxxxxx6","ProFeed 2020 is stopped away from the charging station.");
      delay(150);
      SMS.send("613xxxxxx9","ProFeed 2020 is stopped away from the charging station.");
      TFeedRun = 0;
    }
  }

  XVal = digitalRead(IPScraper);
  if (XVal == HIGH) {
    TScraper = TScraper +1;
    if (TScraper == TLManure) {
      delay(150);
      SMS.send("613xxxxxx6","The manure scraper has stopped working.");
      delay(150);
      SMS.send("613xxxxxx9","The manure scraper has stopped working.");
      TScraper = 0;
    }
  }

  XVal = digitalRead(IPPump);
  if (XVal == HIGH) {
    TPump = TPump +1;
    if (TPump == TLManure) {
      delay(150);
      SMS.send("613xxxxxx6","The manure pump has stopped working.");
      delay(150);
      SMS.send("613xxxxxx9","The manure pump has stopped working.");
      TPump = 0;
    }
  }

  delay(TInc);
}

Here is the error message:
Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega328P"

Sketch uses 24812 bytes (80%) of program storage space. Maximum is 30720 bytes.

Global variables use 2087 bytes (101%) of dynamic memory, leaving -39 bytes for local variables. Maximum is 2048 bytes.

Not enough memory; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing your footprint.

data section exceeds available space in board

Error compiling for board Arduino Nano.

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

Any ideas on how to fix this issue?

Comments are not for extended discussion; this conversation has been moved to chat.

Including the whole library, which is what you are doing, does not work on small boards like yours. Instead you have to only use the parts of the library that you need.
Fortunately the OneSheeld library provides a simple way of doing that, through the use of a couple of #define directives before you include the library.
Since you are only using the SMS functionality you only need to turn on that functionality - so start your sketch with:
#define CUSTOM_SETTINGS
#define INCLUDE_SMS_SHIELD

before the #include <OneSheeld.h> line and it will compile.

Your problem is caused by using too much RAM, not program memory, as the error message says:
Global variables use 2087 bytes (101%) of dynamic memory, leaving -39 bytes for local variables. Maximum is 2048 bytes.
The library you are using is likely occupying a large amount of RAM. However, currently your alert messages are stored in RAM as well, causing the limit to be exceeded.
To make the compiler store the strings in program memory (flash) instead of RAM, you can wrap each string in an F() macro. For example,
SMS.send("613xxxxxx6","ProFeed 2020 is stopped away from the charging station.");
becomes
SMS.send("613xxxxxx6",F("ProFeed 2020 is stopped away from the charging station."));
(You can also wrap the phone number to save even more RAM, but as the limit has only been exceeded by 39 bytes/characters it is unnecessary.)
Majenko's answer might potentially work too as the excluded parts of the library might happen to save just enough RAM, but the F() technique is still handy.

sms.send function doesn't accept a flash string. so it uses the version with String and creates a temporary String

Interesting. That makes removing includes the only solution.


text:
Separate from Serial for digitalWrite()
This is my current code (Arduino Mega 2560):
#define p1 2
#define p2 3

void setup() {
 pinMode(p1, OUTPUT);
 pinMode(p2, OUTPUT);
 Serial.println("ARDUINO : CONNECTED");
}

void loop() {
 if (Serial.available()) {
  String state = Serial.readString();

  if (state.startsWith("LED1ON")) {
    digitalWrite(p1, HIGH);
  }
  if (state.startsWith("LED1OFF")) {
    digitalWrite(p1, LOW);
  }
  if (state.startsWith("LED2ON")) {
    digitalWrite(p2, HIGH);
  }
  if (state.startsWith("LED2OFF")) {
    digitalWrite(p2, HIGH);
  }
  // ... and next condition LED
 }
}

how can i do for multiple input serial use seperator(";") ? like : LED1ON;LED2OFF
expacted:
one time command (LED1ON;LED2OFF) many condition (led turn on and led 2 turn off)
please, tks

This sounds like homework and the point of the homework is to learn parsing. And the delineation character is a semicolon.  Is that correct?

yes bro, using delimiter ; for command multiple condition. help me

You might want to get used to visit the Arduino library reference to learn what is possible and how to use it.
For your case, you are interested in the method readStringUntil().
The reading, understanding, experimenting, debugging, and finishing is left as an exercise to the user.

readString reads from Serial until it times out. This means it might undershoot or overshoot both the end of the line (if there is one) or the semicolon.
I suggest reading into a char buffer (say, of 30 bytes length) until either a newline or semicolon is reached. Then terminate the buffer with 0x00 (to make it a proper "C" string) and then do a simple string compare (strcmp).

Consider refactoring your code such that you read in strings then search through the string character by character copying each character to a new string until you find a semicolon.  When this happens do not copy the semicolon.  Instead execute the existing "if" statements to turn on / off the LEDs based on the content of the new string.  When done, erase the new string, loop back and continue to copy characters to the new string until the next semicolon.  If there is no more data to be copied, read in more data until data is unavailable.

There is a quicker way in C++ to parse through a string based on a given delineating character.  But it abstracts you from what is really going on.  Which is likely what is outlined in this answer.

source: Stack Exchange

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

sort: votes


text:
dht11 data on ESP32 NTP clock (updated)
I'm trying to get my ESP32 internet clock to show temperature and humidity data from a dht11 sensor on a MAX7219 display but my code seems to have some issues. After verifying the code there are no errors, however instead of showing time,temperature and humidity my display only reads two letters "rk." What am I doing wrong? Thanks.
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <DHT.h>
#define DHTPIN 1
#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);
float h;
float t;
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_H
#define MAX_DEVICES 4
#define CLK_PIN   18
#define DATA_PIN  23
#define CS_PIN    5
MD_Parola Display = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
const char* ssid     = "12345";
const char* password = "12345";
String Time, hour, minute;
String Formatted_date;

int interval = 1000;

unsigned long updateTimer;
unsigned long changeDisplayTimer;
unsigned long changeDisplayPeriod = 3000;
boolean printTime = true;

void setup() {
 Serial.begin(115200);
 WiFi.begin(ssid, password);

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

while (!timeClient.update()) {
  timeClient.forceUpdate();
  }
}

Serial.println("");
Serial.println("WiFi connected.");
timeClient.begin();
timeClient.setTimeOffset(0);

 //Display.begin();
 Display.begin(4);
 Display.setIntensity(0);
 Display.displayClear();
 dht.begin();
}

void loop() {

 // check if more time than stored in variable "changeDisplayPeriod"
 // has passed by since last time this period was over
 if ( TimePeriodIsOver(changeDisplayTimer, changeDisplayPeriod) ) {
   // if more time REALLY has passed by
   printTime = !printTime; // invert the value of flag "printTime"
  }

 if (printTime == true) {
   obtainTime();
  }
 else { // which means printTime == false)
   printHumTEmp();
  }
 }

 void obtainTime() {

 if ( TimePeriodIsOver(updateTimer, 1000) ) {
 Formatted_date = "does not work";//timeClient.getFormattedDate();
   Serial.println(Formatted_date);
   hour = Formatted_date.substring(11, 13);
   minute = Formatted_date.substring(14, 16);

   Time = hour + ":" + minute;
   Serial.println(Time);
   Display.setTextAlignment(PA_CENTER);
   Display.print(Time);
   }
 }

void printHumTEmp() {
 if ( TimePeriodIsOver(updateTimer, 1000) ) {
   // your code reading in
   // and printing humidity and temperature
  }
}

 // easy to use helper-function for non-blocking timing
  boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
   unsigned long currentMillis  = millis();
   if ( currentMillis - startOfPeriod >= TimePeriod ) {
   // more time than TimePeriod has elapsed since last time if-condition was true
   startOfPeriod = currentMillis; // a new period starts right here so set new starttime
   return true;
  }
  else return false;            // actual TimePeriod is NOT yet over
}

why do you think that there are issues? ... nobody will waste time trying to figure out what problems you are seeing ... please describe what you expect to happens, what actually happens and what errors you get ... add all of that to the question ... do not write a comment

my code seems to have some issues could mean anything. Describe the issues. We are not mind-readers.

To try to reproduce whatever these issues are we would have to download all those libraries you used, for which you have not provided links. It is not uncommon for libraries to be supplied on different sites, and be of different versions. If there is an error message please copy and paste it.

Move unsigned long currentMillis  = millis(); to the end of the setup() function, and move the rest of TimePeriodIsOver() (actually only two lines of codes needed) to the loop(), and reset the changeDisplayTimer if time is over (you never did that in your code). Write simple straightforward code, and only when it is work, then try to re-factor into function if necessary.

The 'rk' which you mentioned in the title comes from the end of the string "does not work". This statement extracts it: hour = Formatted_date.substring(11, 13);. The following statement reads past the end of the string so will return invalid data: minute = Formatted_date.substring(14, 16);. This comment in the program: // your code reading in and printing humidity and temperature is to inform you where you should write your code to complete this assignment.

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


text:
Looking for help with an improved vibration sensing method for Arduino
I am trying to test how vibration waves move through different material...ie how sensitive certain components are.
I am needing a vibration sensor that will send me back some kind of measurement say in the form of an integer between 1 and (a number).
I have tried the 801S with an Arduino board and it was successful. The problem though is it just returns a 1 for vibration and 0 for none. To get the results I had to keep retesting and moving the material further and further away to get it to fail.
I also tried a HiLetgo piezoelectric analog sensor. It does return a number...but the results are all over the place...from 5 to 250. I have a device that supplies a consistent "tap" to be measured...so the HiLetgo had to be letgo.
I did research SE and found this question Vibration sensor for arduino but it does not answer my question.

not a question about Arduino ... your question is off topic here

The sensor is for an Arduino.

Did you try with a microphone module it might pick up back ground noise too, better to do a FFT hmm.  Microphone module has a prebuilt in op amp to give analog values dc biased because Arduino picks only dc voltage values.

The sensor is for an Arduino that does not make it an Arduino specific question ... the same sensor could be used on a Raspberry Pi or any other microcontroller .... it's similar to having a question about a camping trailer roof and asking at a Porsche site because you are using a Porsche to pull the trailer

It is unclear how exactly you measured with the piezoelectric sensor. A vibration is a wave, thus the piezoelectric sensor will give you that wave in a specific range. To get something like vibration amplitude you would need to do further processing of the data/wave. You can do this in your code by finding the min and max value in a time interval and calculating the difference

@jsotola Look its a sensor for my Arduino board. Plain and simple. Just like the tag that says "Sensor". Whats the point of a "sensor" tag in the Arduino forum? Is a question about an ESP32 also not valid?

@chrisl I was just doing an analogRead(onThePin).  Are you saying I need to say: Start a process of recording and then do the tetst. Stop. and the process the measurments?

A vibration is when the body moves rapidly back and forth. Thus the signal will also rapidly move back and forth. In fact - since you want to measure "how vibration waves move through different material" - the vibration wave is just a sound wave in that material. A sound wave is an oscillating signal (look at the wave from any song or speech that you have). The sensor just gives you this wave. If you want the amplitude of the wave you would need to measure the wave values for a specific amount of time (at least one period of the wanted frequency) and then calculate the diff between min and max

So basically the sensor was probably totally ok. You just need to interpret the data in the correct way.

@chrisl Makes total sense...will give it another go.

Whats the point of a "sensor" tag in the Arduino forum? ... it is for a questions like how to use sensor XYZ with an Arduino? or is sensor XYZ suitable for use with Arduino? ... it is not for which sensor should I use?

@jsotola Your not helping...as a matter of fact your rather rude and a hinderance. I never asked which sensor to use. I was asking for suggestions....not insults.

@ChrisCatignani I am not trying to insult you ... my apologies to you if it made you feel that way

I did some experiments a year or so ago to sense vibration through a (physical) office desk top using the inbuilt accelerometer and gyroscope of an Arduino Uno Wi-Fi Rev2. That chip is an LSM6DSM but I would think that any such module (e.g., MPU6050) connected to any Arduino could be useful.
There’s a good comparison article at Seeed Studios introducing vibration sensors for Arduino.
Update. Looking at the similar question linked by the OP I see several comments that the MPU6050 which I suggested  would have poor resolution. You may have to study data sheets (or experiment) to find the best  device for your purpose.
Second update. This white paper, “Measuring vibration with accelerometers” has some good engineering notes about selecting suitable accelerometers for different purposes.

Thanks for your answer...

The STMicro IMU chip can be set up in a number of ways.  It's complex enough to seek the benefits of using the STMicro IDE to simplify its configuration.  And that would put this project onto an STMicro development board (not an Arduino). The short of it is, we don't know what type of testing you are doing.  For example are you interested in detecting a hammer hit or are you interested in how long the vibration lasts and at what frequencies. The answers dictate how the IMU is setup or even if an IMU is a solution to your problem.

@st2000 Im wanting to measure the signal strength through various materials. For example...I would expect the signal to be higher through rock versus a sponge.

Briefly, IMUs are normally used for much slower changes in force.  A tilt compensating compass or in a quadcopter. I think you can speed up the sampling time in that STMicro IMU.  But I don't know if that will be enough.  I think STMicro also makes an "X" series of sensors w/smarts built in.  You might be able to program those STMicro sensor to detect vibrations specifically. If you are designing a product maybe this is worth looking into. If this is a one-off project, then maybe just adjusting the 801S's sensitivity and repeating the test.

@st2000 saying that “IMUs are normally used for much slower changes in force.” is maybe a generalization? The lsm6dsm I mentioned specifically has vibration monitoring listed as an application. There are also papers using  cheap sensors for vibration analysis (link to follow…)

e.g., https://www.researchgate.net/profile/Duc-Nguyen-113/publication/326032887_Low-Cost_Vibration_Measurement_for_Behavior_of_Small-Scale_Steel_Modeling_using_MEMS_Raspberry_Pi-3_and_Arduino_Mega_2560/links/5bad5b99299bf13e6051db9a/Low-Cost-Vibration-Measurement-for-Behavior-of-Small-Scale-Steel-Modeling-using-MEMS-Raspberry-Pi-3-and-Arduino-Mega-2560.pdf

Agreed. My thinking was vibrations in a bridge are slower than vibrations in a truck chassis are slower than vibrations in a jet engine.  And an IMU may not be the best choice if interested in the higher frequencies.  But I think I understand the end game a bit better now.  That's why I suggested repeating the test while adjusting the 801S's sensitivity.  Actually, I think I'd automate it having the Arduino controlling the 801S's pot using a controllable volume module.

@st2000 I follow you. That’s worth writing up as an answer.


text:
CH340G based USB to UART adapter - Pinouts - Can't find schematics
This is the board I will be referring to.

There are different variations of it (with built in buttons etc.) but they all seem to be based on the CH340 chip.
My problem is, that I do not know what the pinouts on the board stand for. I cannot find any schematics for the adapter (I can find some for the CH340). Does anyone have a clue as to what the different pins are for?

This module appears to be designed for communicating with the ESP8266 ESP-01 board. The pinout for the ESP-01 is shown below, taken from a typical datasheet:

[Updated]The arrow on the CH340 board next to the yellow header indicates the connection orientation. The bulk of the ESP-01 goes on the side of the header pointed to by the arrow, covering the CH340 board, as shown below.

Information on the WCH CH340 product set including the G model is here.

There is plenty of online information on getting started with the ESP8266 ESP-01 using the Arduino IDE. A good example is at instructables.com.
The other model variations you mentioned (with built in buttons) are probably in response to a known problem with this board when flashing ESP-01s. See here for more info.

The orientation is indicated by the arrow on the board

Thanks @Majenko, yes I guessed that. Not being familiar with the board / ESP-01 I wasn’t sure how to interpret the arrow. Is it pointing to the side on which the bulk of the ESP-01 board should be?

Yes. The ESP-01 covers the main body of the board.

@RowanP Thank you very much for the help! Do you know by any chance, if it is possible to use it for general UART/Serial communication? Specifically, if I simply connect TX to my device's RX and vise versa, would there be anything against doing this?

@GeorgeWTrump I have not used the board myself, but I’m confident you could use jumpers to connect the RX, TX, Gnd, and maybe Vcc as you would for any CH340 adapter.


text:
How to obtain the real and imaginary signal parts using Arduino FFT
How do you obtain the real and imaginary parts of a signal using FFT in arduino?
I could not find a particular tutorial with code for this purpose in the internet.

Probably not.  The Arduino isn't exactly the tool of choice for digital signal processing.  All you need is any FFT implementation in C, and you should be able to port it to the Arduino pretty easily.  The problem is getting a steady, fast sampling rate on the Arduino - that, and processing it fast enough on a slow, general purpose processor.

There are some implementations around such as https://www.arduinolibraries.info/libraries/arduino-fft - whether it extracts the real and imaginary parts I do not know.

@PeterSmith Good hint, and it should return a imaginary part too! The Compute-Method takes two double pointers  one to the real part samples and one to an array of 0.0 initialized imaginary part samples. Both arrays must have the same size. After computation the imaginary array is filled with the imaginary parts of the FFT. The library also provides examples.

Most libraries will either take one array of samples as input and then fill two other arrays of real and imaginary data, or it will take one array of samples and one empty array as input, and the sample data will be replaced by the real data and the empty array filled with the imaginary data.
You will have to first choose a library to use and then read the examples or documentation to see what the format of the functions are.


text:
Servo motor (HSR-1425R) not running continuously
I'm trying to programme a servo motor to reach certain positions. I have a 360 degrees servo motor, so I can not use the Servo library and I can only control the speed. Therefore I want to regulate the time for the pulse. The setup is simple, 5 V, GND and pin 9 from the Arduino to the motor.
int servo1 = 9;

void setup{
    Serial.begin(9600);
    pinMode(servo1, OUTPUT);
}
void loop{
    digitalWrite(servo1, HIGH);
    delay(5000);
    Serial.println(digitalRead(servo1));
    digitalWrite(servo1, LOW);
    delay(5000);
    Serial.println(digitalRead(servo1));
}

Expected:
I expect the code to run the servo motor at full speed for 5 seconds.
Actual:
The motor runs at the first impulse and pauses for 10 seconds.
How can I improve the code to do what I expect?

what are your hardware connections and why are you reading an output pin?

My hardware connections are the three wires from the servo directly to the Arduino. I wanted to see what signals were sent.

Why do you think you cannot use the Servo library?  With continuous rotation servos it generally works where 0 spins one way 180 spins the other and something close to 90 stops it.

Also, to control that servo you don't just set the pin HIGH.  You have to send a specific pulse length that tells the servo how fast and what direction to rotate.  It is the same sort of signal that tells a regular servo what angle to go to.  That's why the Servo library is normally used to control these.

Apply some impulse which you need your servo to work on

Look at how servo motors are typically controlled. As far as I know there are no servos that can just be "enabled to rotate" like you seem to expect.
Usually a servo's position is set by applying a pulse of a specific length. This means you can apply a PWM signal with proper frequency. Then the duty cycle should be proportional to the servos position. From my experience timing is quite critical when controlling a servo, so going the way you do (timing a gpio's output state with delay()s) will not work well. You have to use the atmega's hardware modules (which already is the case when using the arduinos digital write) to achieve adequate timing.


text:
Continuous Rotation
I was wondering how can I make a Servo rotate continuously by using an Arduino code.
I looked through several forums and websites already, but all of them just show how to make it run by changing the servo physically, I wanted to be able to do it with just the code.
Thanks for your help already!

Please be detailed on what kind of servo you use? Analog or digital servo?

Can you please be more specific! As @dpw asks, what type of servo is it? Do you have any web links to this servo? What have you tried so far? Please add links to the forums visited. What do you mean by "all of them just show how to make it run by changing the servo physically"?

As long as you use a continuous rotation servo, you can use the standard Servo library on Arduino: 0 will stop the servo, 90 will make it go full speed forward, -90 will make it go full speed backward.

The objective you seek will require a servo that has been manufactured to be continuously rotatable. The locations you've found are for those with extra servos who might not want to purchase a slightly more expensive servo and might want to use what they have on hand.
Once you have such a servo, self-modified or purchased as such, your code will work as you suggest. You should be able to easily locate the necessary code to operate a 360 degree servo using current libraries.

Normally, a servo is rotating 180 degrees because it has a drag  inside on gears who stop rotating continuously (360 degrees).
To make a servo to rotate 360 degrees, you need to buy a new servo or modify this one.

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


text:
How can I stop my Servo rotating?
I have a continuous servo motor connected to my Arduino UNO. I want it to react to the Hexadecimal code received by an Infrared remote. I want the motor to rotate once in one direction and then rotate once in the reverse direction and then stop until triggered by the remote again. At the moment, the remote will cause the the motor to rotate once in one way but then it rotates continuously in the reverse direction. Any help would be much appreciated!
#include "IRremote.h"
#include <Servo.h>

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

Servo servoMain;
IRrecv irrecv(receiver);
decode_results results;

void setup()
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn(); // Start the receiver
  servoMain.attach(10);
}

void loop()
{
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    translateIR();
    irrecv.resume(); // receive the next value
  }
}

void translateIR() // takes action based on IR code received

// describing Remote IR codes
{

  switch (results.value)

  {

    case 551520375: servoMain.write(180); delay(1000); servoMain.write(0);     delay(1000); break;
    default: break;

  }

  delay(500); // Do not get immediate repeat

} //END translateIR

You never tell it to stop. I assume that writing op degrees would stop it.

Have you checked out linked and related questions?  Seems like this question may duplicate some of them.

http://arduino.stackexchange.com/questions/4076/what-is-commonly-done-to-stop-a-servo-after-reaching-desired-position

Unlike a normal servo motor where the argument of the Arduino's servo.write(angle) method represents a position, a continuous servo motor uses the argument for speed and direction.  Most continuous servo motors interpret stop to be approximately 90 degrees.  Full, say, reverse as 0 degrees.  And full, say, forward as 180 degrees.  As stated in the above link:

On a continuous rotation servo, this will set the speed of the servo
  (with 0 being full-speed in one direction, 180 being full speed in the
  other, and a value near 90 being no movement).

Also of interest, most continuous servo motors have an adjustment to set the "90 degree position" (full stop).  That is to say, servo motor control signals are analog, not digital!  It follows that the processor's interpretation of the "90 degree position" may not be the same as the servos' interpretation of the "90 degree position".  Hence the ability to adjust the servos' interpretation.
This picture from the parallax servo tutorials web site shows how this is done:

Thanks a lot for your help. I wasn't aware about the calibration and I got it working with some minor adjustments to the code as well.

I am posting that may help others in future. I have MG996R Servo Motors, this motor when I opened and inside I didn't find LOCK at main wheel and I assume its 360 degree.
I have similar problem that while testing Robotic Arm, my motor was loosing position and it was rotating 360 degree. I tried all sort of remedies but didn't find the solution.
MY SOLUTION: Connect your Servo with external power 5v supply, even connecting 5V to arduino board with round pin does not solve. once I connected with external power with 5V power my issue was solved and motors were retaining position

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


text:
Not getting proper readings on Arduino from MAP Sensor
In recent project, I have to take reading from MAP sensor. So basically, we used analog pin for this. But in my case, I don't get proper result which actually I want.
When I'm taking readings through multi-meter then I got proper readings. Means when I start the vehicle then it's show 0.99 V. When I provide full throttle then voltage also increase and it's reach to 1.66 V. And finally when suddenly come back to normal throttle then also voltage decrease around like 0.48 V and then within a second again show normal 0.99 V.
Here, when I'm taking readings from MAP sensor through multi-meter then I'm providing ground to multi-meter. And when I taking readings from MAP sensor through Arduino then I'm not providing any ground to Arduino. Because I think it may be damage my Arduino.
So, I think this is also one possibility and may be possible that's why I'm not getting that type of voltage output through Arduino.
Here, the ground which I provide to multi-meter is from 12V DC battery which is used in CNG Auto rickshaw. So, that's why I'm not providing ground to Arduino. So, give me some suggestions about this. What should I do for this. Providing ground to Arduino or not.
Here, it's my code.
int kMAP1 = 0;
float kMAP2 = 0;

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

void loop()
{
  kMAP1 = analogRead(A0);
  kMAP2 =  kMAP1 * (5.0 / 1023.0);

  Serial.print("MAP1: ");
  Serial.print(kMAP1);

  Serial.print("\t");

  Serial.print("      MAP2: ");
  Serial.println(kMAP2);

  delay(1000);
}

And it's my serial monitor output.
MAP1: 490         MAP2: 2.39
MAP1: 433         MAP2: 2.12
MAP1: 270         MAP2: 1.32
MAP1: 0           MAP2: 0.00
MAP1: 447         MAP2: 2.18
MAP1: 401         MAP2: 1.96
MAP1: 518         MAP2: 2.53
MAP1: 487         MAP2: 2.38
MAP1: 344         MAP2: 1.68
MAP1: 374         MAP2: 1.83
MAP1: 611         MAP2: 2.99
MAP1: 429         MAP2: 2.10
MAP1: 647         MAP2: 3.16
MAP1: 668         MAP2: 3.26
MAP1: 460         MAP2: 2.25
MAP1: 489         MAP2: 2.39
MAP1: 278         MAP2: 1.36
MAP1: 277         MAP2: 1.35
MAP1: 318         MAP2: 1.55
MAP1: 383         MAP2: 1.87
MAP1: 238         MAP2: 1.16
MAP1: 237         MAP2: 1.16
MAP1: 134         MAP2: 0.65
MAP1: 191         MAP2: 0.93
MAP1: 230         MAP2: 1.12
MAP1: 308         MAP2: 1.51
MAP1: 479         MAP2: 2.34
MAP1: 388         MAP2: 1.90
MAP1: 544         MAP2: 2.66
MAP1: 518         MAP2: 2.53
MAP1: 419         MAP2: 2.05
MAP1: 544         MAP2: 2.66
MAP1: 586         MAP2: 2.86
MAP1: 544         MAP2: 2.66
MAP1: 575         MAP2: 2.81
MAP1: 184         MAP2: 0.90
MAP1: 202         MAP2: 0.99
MAP1: 883         MAP2: 4.32
MAP1: 671         MAP2: 3.28
MAP1: 884         MAP2: 4.32
MAP1: 487         MAP2: 2.38
MAP1: 403         MAP2: 1.97
MAP1: 184         MAP2: 0.90
MAP1: 426         MAP2: 2.08
MAP1: 412         MAP2: 2.01
MAP1: 428         MAP2: 2.09
MAP1: 434         MAP2: 2.12
MAP1: 420         MAP2: 2.05
MAP1: 312         MAP2: 1.52
MAP1: 414         MAP2: 2.02
MAP1: 435         MAP2: 2.13
MAP1: 405         MAP2: 1.98
MAP1: 418         MAP2: 2.04
MAP1: 515         MAP2: 2.52
MAP1: 462         MAP2: 2.26
MAP1: 578         MAP2: 2.83
MAP1: 332         MAP2: 1.62
MAP1: 330         MAP2: 1.61
MAP1: 164         MAP2: 0.80
MAP1: 425         MAP2: 2.08
MAP1: 345         MAP2: 1.69
MAP1: 226         MAP2: 1.10
MAP1: 0           MAP2: 0.00
MAP1: 97          MAP2: 0.47
MAP1: 872         MAP2: 4.26
MAP1: 55          MAP2: 0.27
MAP1: 492         MAP2: 2.40
MAP1: 531         MAP2: 2.60
MAP1: 1023        MAP2: 5.00
MAP1: 43          MAP2: 0.21
MAP1: 6           MAP2: 0.03

For this to be a valid question here, you would need to provide a link to the data sheet of the sensor and a schematic of the circuit that powers it and connects it the arduino.

@ChrisStratton Ok. Got it. I will upload soon.

@jwpat7 Now, it's readable.

The ground does need to be connected. I have also added a RC filter to stabilize the sensor reading.
Connection :

Arduino 5V  ----> MAP Vcc
Arduino GND ----> MAP GND
Arduino Analog Pin A0 <---- RC Filter <---- MAP Output pin

Using this connection, I get the proper readings.
Readings on Serial Monitor :
// When Vehicle not start //
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84

//When start vehicle//
MAP1: 343         MAP2: 1.68
MAP1: 332         MAP2: 1.62
MAP1: 341         MAP2: 1.67
MAP1: 255         MAP2: 1.25
MAP1: 215         MAP2: 1.05
MAP1: 336         MAP2: 1.64
MAP1: 320         MAP2: 1.56
MAP1: 321         MAP2: 1.57
MAP1: 308         MAP2: 1.51
MAP1: 316         MAP2: 1.54
MAP1: 326         MAP2: 1.59
MAP1: 326         MAP2: 1.59
MAP1: 325         MAP2: 1.59
MAP1: 177         MAP2: 0.87
MAP1: 219         MAP2: 1.07
MAP1: 216         MAP2: 1.06
MAP1: 220         MAP2: 1.08
MAP1: 208         MAP2: 1.02
MAP1: 211         MAP2: 1.03

//Provide full throttle//
MAP1: 319         MAP2: 1.56
MAP1: 324         MAP2: 1.58
MAP1: 341         MAP2: 1.67
MAP1: 349         MAP2: 1.71
MAP1: 353         MAP2: 1.73
MAP1: 352         MAP2: 1.72
MAP1: 352         MAP2: 1.72
MAP1: 356         MAP2: 1.74
MAP1: 357         MAP2: 1.74
MAP1: 359         MAP2: 1.75
MAP1: 355         MAP2: 1.74
MAP1: 354         MAP2: 1.73
MAP1: 327         MAP2: 1.60

//Suddenly come back to normal throttle//
MAP1: 181         MAP2: 0.88
MAP1: 181         MAP2: 0.88
MAP1: 192         MAP2: 0.94
MAP1: 205         MAP2: 1.00
MAP1: 201         MAP2: 0.98
MAP1: 210         MAP2: 1.03
MAP1: 218         MAP2: 1.07
MAP1: 222         MAP2: 1.09

//Provide full throttle again//
MAP1: 309         MAP2: 1.51
MAP1: 375         MAP2: 1.83
MAP1: 395         MAP2: 1.93
MAP1: 376         MAP2: 1.84
MAP1: 261         MAP2: 1.28
MAP1: 360         MAP2: 1.76
MAP1: 307         MAP2: 1.50
MAP1: 361         MAP2: 1.76
MAP1: 259         MAP2: 1.27

//Suddenly back again normal throttle//
MAP1: 156         MAP2: 0.76

//Again provide full throttle//
MAP1: 295         MAP2: 1.44
MAP1: 267         MAP2: 1.30
MAP1: 287         MAP2: 1.40
MAP1: 372         MAP2: 1.82
MAP1: 380         MAP2: 1.86
MAP1: 375         MAP2: 1.83
MAP1: 229         MAP2: 1.12
MAP1: 359         MAP2: 1.75
MAP1: 339         MAP2: 1.66
MAP1: 337         MAP2: 1.65
MAP1: 359         MAP2: 1.75
MAP1: 344         MAP2: 1.68

//Again suddenly back to normal throttle//
MAP1: 121         MAP2: 0.59
MAP1: 164         MAP2: 0.80
MAP1: 202         MAP2: 0.99

//Again provide full throttle//
MAP1: 310         MAP2: 1.52
MAP1: 339         MAP2: 1.66
MAP1: 356         MAP2: 1.74
MAP1: 361         MAP2: 1.76
MAP1: 274         MAP2: 1.34

//Again suddenly back to normal throttle//
MAP1: 127         MAP2: 0.62
MAP1: 178         MAP2: 0.87
MAP1: 221         MAP2: 1.08
MAP1: 247         MAP2: 1.21
MAP1: 224         MAP2: 1.09

//Again provide full throttle//
MAP1: 292         MAP2: 1.43
MAP1: 278         MAP2: 1.36
MAP1: 265         MAP2: 1.30
MAP1: 367         MAP2: 1.79
MAP1: 328         MAP2: 1.60
MAP1: 358         MAP2: 1.75

//Again suddenly back to normal throttle//
MAP1: 182         MAP2: 0.89
MAP1: 174         MAP2: 0.85
MAP1: 242         MAP2: 1.18
MAP1: 253         MAP2: 1.24
MAP1: 261         MAP2: 1.28

//Vehicle stop//
MAP1: 307         MAP2: 1.50
MAP1: 360         MAP2: 1.76
MAP1: 375         MAP2: 1.83
MAP1: 375         MAP2: 1.83
MAP1: 375         MAP2: 1.83
MAP1: 376         MAP2: 1.84
MAP1: 375         MAP2: 1.83
MAP1: 375         MAP2: 1.83
MAP1: 376         MAP2: 1.84
MAP1: 376         MAP2: 1.84
MAP1: 377         MAP2: 1.84
MAP1: 377         MAP2: 1.84
MAP1: 377         MAP2: 1.84
MAP1: 377         MAP2: 1.84

Although the circuit isn't shown and description isn't perfectly clear, evidently there is some question about how to connect up the various grounds.
Voltage, being “the difference in electric potential energy between two points per unit electric charge” [ref Voltage article in Wikipedia], is measured between two points in an electric circuit.  If the two points are in unrelated and isolated circuits meaningful measurements can't be taken.
In typical MAP sensor circuits, the sensor output is relative to automotive ground, so your Uno's analog ground should be connected to automotive ground.  Whether this is electrically safe depends on several things:
• Sensor output voltage range – The multimeter readings showed a safe range.  The range is narrow compared to the Uno ADC's default +5V range; if you want a bit or two more resolution, you could either set up a 2 V external ADC reference, or could amplify the sensor output up to a range of about 5 V, or could use a unity gain op amp circuit followed by a voltage divider to get into a 0-to-1.1 V range, and use the internal 1.1 V bandgap reference.
• Uno power supply ground voltage – If the Uno's supply is isolated, its ground can be connected to automotive ground with no problem.  Or, if its supply ground already connects to automotive ground, no problem.  Where a problem might occur is if you measure a large voltage between automotive ground and Uno ground.  If so, connect a 100 Ω resistor between the two grounds and measure the voltage across it.  If the voltage is near zero, you can connect the grounds or could leave them connected by a small resistor like that.  If, on the other hand, some appreciable voltage appears across the resistor, or if it disappears in a puff of smoke, then they can't connect safely and you would need to use a different power supply for the Uno that doesn't have such a problem.
• Ground wire topology – The wiring path from Uno ground to automotive ground should not share any segments with high current devices.   In normal operation, or in case of a load dump, several volts difference can arise between the ends of a piece of ground wire to a high current device.

I once used an arduino to check the map sensor on my ford f150.  As an FYI, I will state that the ford map gave a digital pulse as output for the engine computer and was not analogue as the one you seem to be using.  I'm only commenting here for others who might be having trouble with a MAP sensor, so that they realize that some give pulse outputs and not voltage outputs.  So, I'm not sure about your map sensor, or turning the pulses into an average reading, but I simply used the interrupt to count pulses over a second and then recorded those readings over several minutes of drive time.  (I was having intermittent engine stumbling and I was ruling out the various sensors as causing the trouble.)  I was checking to make sure the MAP sensor didn't completely drop out from time to time.  In the end, it was my ignition module giving out due to heat fatigue that was the problem.  But, I can say that with a handful of resistors and a probe I was able to check all the sensors in the vehicle in short time...except for the oxygen sensor which I was afraid to damage due to its sensitivity.


text:
TPS/MAP calculation problem - SOLVED
In my recent project, I have to create TPS/MAP table, which is provide value of LOAD.
Here, it is my table. You can see two value of LOAD which is separate by /. (TPS LOAD / MAP LOAD)

But now here as you can see, TPS provide different value of LOAD and MAP provide different value of LOAD. So, every cell has a two value of LOAD. So, I decide just add this both LOAD and divide it by 2.
I made program for this but it access only just LAST COLUMN and LAST ROW and it provide wrong value of LOAD. I don't understand why this happen.
Here, my code.
float TPS[] = {0, 0.4, 0.8, 1.2, 1.6, 2, 2.4, 2.8, 3.2, 3.6, 4, 4.4, 4.8, 5};
float MAP[] = {0.85, 0.95, 1.05, 1.15, 1.25, 1.35, 1.45, 1.55, 1.65, 1.75, 1.85, 1.9};

float TPS_MIN = 0.00;
float TPS_MAX = 5.00;

float MAP_MIN = 0.85;
float MAP_MAX = 1.90;

float LOAD_MIN_TPS[] = {2, 3.23, 4.49, 5.73, 6.97, 8.22, 9.44, 10.63, 11.87, 13.11, 14.33, 15.00};
float LOAD_MAX_TPS[] = {10.00, 17.08, 24.11, 31.67, 38.30, 45.73, 52.63, 60.19, 67.22, 74.52, 81.68, 85.00};

float LOAD_MIN_MAP[] = {2, 2.64, 3.28, 3.92, 4.56, 5.21, 5.85, 6.47, 7.11, 7.76, 8.40, 9.05, 9.69, 10.00};
float LOAD_MAX_MAP[] = {15.00, 20.62, 26.17, 31.79, 37.35, 42.97, 48.66, 54.14, 59.76, 65.38, 70.93, 76.63, 82.18, 85.00};

float m1[12] = {};
float m2[14] = {};

float y1[14] = {};
float y2[12] = {};

float y[168] = {};

int i, j, n;

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

void loop()
{
  for(j = 0; j < 12; j++)
  {
    m1[j] = (LOAD_MAX_TPS[j] - LOAD_MIN_TPS[j]) / (TPS_MAX - TPS_MIN);

    Serial.print("m1 : ");
    Serial.println(m1[j]);

    for(i = 0; i < 14; i++)
    {
      y1[i] = m1[j] * (TPS[i] - TPS_MIN) + LOAD_MIN_TPS[j];

      Serial.print("TPS : ");
      Serial.print(TPS[i]);
      Serial.print("\t");
      Serial.print("LOAD : ");
      Serial.println(y1[i]);
   }
  }

  for(i = 0; i < 14; i++)
  {
    m2[i] = (LOAD_MAX_MAP[i] - LOAD_MIN_MAP[i]) / (MAP_MAX - MAP_MIN);

    Serial.print("m2 : ");
    Serial.println(m2[i]);

    for(j = 0; j < 12; j++)
    {
      y2[j] = m2[i] * (MAP[j] - MAP_MIN) + LOAD_MIN_MAP[i];

      Serial.print("MAP : ");
      Serial.print(MAP[j]);
      Serial.print("\t");
      Serial.print("LOAD : ");
      Serial.println(y2[j]);
    }
   }

  for(i = 0; i < 14; i++)
  {
    for(j = 0; j < 12; j++)
    {
      y[n] = (y1[i] + y2[j]) / 2;
      Serial.print("LOAD TPS : ");
      Serial.print(y1[i]);
      Serial.print("\t");
      Serial.print("LOAD MAP : ");
      Serial.print(y2[j]);
      Serial.print("\t");
      Serial.print("TPS : ");
      Serial.print(TPS[i]);
      Serial.print("\t");
      Serial.print("MAP : ");
      Serial.print(MAP[j]);
      Serial.print("\t");
      Serial.print("Final LOAD : ");
      Serial.println(y[n]);
    }
  }
  delay(1000000);
}

My serial monitor output :
LOAD TPS : 15.00    LOAD MAP : 10.00    TPS : 0.00  MAP : 0.85  Final LOAD : 12.50
LOAD TPS : 15.00    LOAD MAP : 17.14    TPS : 0.00  MAP : 0.95  Final LOAD : 16.07
LOAD TPS : 15.00    LOAD MAP : 24.29    TPS : 0.00  MAP : 1.05  Final LOAD : 19.64
LOAD TPS : 15.00    LOAD MAP : 31.43    TPS : 0.00  MAP : 1.15  Final LOAD : 23.21
LOAD TPS : 15.00    LOAD MAP : 38.57    TPS : 0.00  MAP : 1.25  Final LOAD : 26.79
LOAD TPS : 15.00    LOAD MAP : 45.71    TPS : 0.00  MAP : 1.35  Final LOAD : 30.36
LOAD TPS : 15.00    LOAD MAP : 52.86    TPS : 0.00  MAP : 1.45  Final LOAD : 33.93
LOAD TPS : 15.00    LOAD MAP : 60.00    TPS : 0.00  MAP : 1.55  Final LOAD : 37.50
LOAD TPS : 15.00    LOAD MAP : 67.14    TPS : 0.00  MAP : 1.65  Final LOAD : 41.07
LOAD TPS : 15.00    LOAD MAP : 74.29    TPS : 0.00  MAP : 1.75  Final LOAD : 44.64
LOAD TPS : 15.00    LOAD MAP : 81.43    TPS : 0.00  MAP : 1.85  Final LOAD : 48.21
LOAD TPS : 15.00    LOAD MAP : 85.00    TPS : 0.00  MAP : 1.90  Final LOAD : 50.00
LOAD TPS : 20.60    LOAD MAP : 10.00    TPS : 0.40  MAP : 0.85  Final LOAD : 15.30
LOAD TPS : 20.60    LOAD MAP : 17.14    TPS : 0.40  MAP : 0.95  Final LOAD : 18.87
LOAD TPS : 20.60    LOAD MAP : 24.29    TPS : 0.40  MAP : 1.05  Final LOAD : 22.44
LOAD TPS : 20.60    LOAD MAP : 31.43    TPS : 0.40  MAP : 1.15  Final LOAD : 26.01
LOAD TPS : 20.60    LOAD MAP : 38.57    TPS : 0.40  MAP : 1.25  Final LOAD : 29.59
LOAD TPS : 20.60    LOAD MAP : 45.71    TPS : 0.40  MAP : 1.35  Final LOAD : 33.16
LOAD TPS : 20.60    LOAD MAP : 52.86    TPS : 0.40  MAP : 1.45  Final LOAD : 36.73
LOAD TPS : 20.60    LOAD MAP : 60.00    TPS : 0.40  MAP : 1.55  Final LOAD : 40.30
LOAD TPS : 20.60    LOAD MAP : 67.14    TPS : 0.40  MAP : 1.65  Final LOAD : 43.87
LOAD TPS : 20.60    LOAD MAP : 74.29    TPS : 0.40  MAP : 1.75  Final LOAD : 47.44
LOAD TPS : 20.60    LOAD MAP : 81.43    TPS : 0.40  MAP : 1.85  Final LOAD : 51.01
LOAD TPS : 20.60    LOAD MAP : 85.00    TPS : 0.40  MAP : 1.90  Final LOAD : 52.80
LOAD TPS : 26.20    LOAD MAP : 10.00    TPS : 0.80  MAP : 0.85  Final LOAD : 18.10
LOAD TPS : 26.20    LOAD MAP : 17.14    TPS : 0.80  MAP : 0.95  Final LOAD : 21.67
LOAD TPS : 26.20    LOAD MAP : 24.29    TPS : 0.80  MAP : 1.05  Final LOAD : 25.24
LOAD TPS : 26.20    LOAD MAP : 31.43    TPS : 0.80  MAP : 1.15  Final LOAD : 28.81
LOAD TPS : 26.20    LOAD MAP : 38.57    TPS : 0.80  MAP : 1.25  Final LOAD : 32.39
LOAD TPS : 26.20    LOAD MAP : 45.71    TPS : 0.80  MAP : 1.35  Final LOAD : 35.96
LOAD TPS : 26.20    LOAD MAP : 52.86    TPS : 0.80  MAP : 1.45  Final LOAD : 39.53
LOAD TPS : 26.20    LOAD MAP : 60.00    TPS : 0.80  MAP : 1.55  Final LOAD : 43.10
LOAD TPS : 26.20    LOAD MAP : 67.14    TPS : 0.80  MAP : 1.65  Final LOAD : 46.67
LOAD TPS : 26.20    LOAD MAP : 74.29    TPS : 0.80  MAP : 1.75  Final LOAD : 50.24
LOAD TPS : 26.20    LOAD MAP : 81.43    TPS : 0.80  MAP : 1.85  Final LOAD : 53.81
LOAD TPS : 26.20    LOAD MAP : 85.00    TPS : 0.80  MAP : 1.90  Final LOAD : 55.60
LOAD TPS : 31.80    LOAD MAP : 10.00    TPS : 1.20  MAP : 0.85  Final LOAD : 20.90
LOAD TPS : 31.80    LOAD MAP : 17.14    TPS : 1.20  MAP : 0.95  Final LOAD : 24.47
LOAD TPS : 31.80    LOAD MAP : 24.29    TPS : 1.20  MAP : 1.05  Final LOAD : 28.04
LOAD TPS : 31.80    LOAD MAP : 31.43    TPS : 1.20  MAP : 1.15  Final LOAD : 31.61
LOAD TPS : 31.80    LOAD MAP : 38.57    TPS : 1.20  MAP : 1.25  Final LOAD : 35.19
LOAD TPS : 31.80    LOAD MAP : 45.71    TPS : 1.20  MAP : 1.35  Final LOAD : 38.76
LOAD TPS : 31.80    LOAD MAP : 52.86    TPS : 1.20  MAP : 1.45  Final LOAD : 42.33
LOAD TPS : 31.80    LOAD MAP : 60.00    TPS : 1.20  MAP : 1.55  Final LOAD : 45.90
LOAD TPS : 31.80    LOAD MAP : 67.14    TPS : 1.20  MAP : 1.65  Final LOAD : 49.47
LOAD TPS : 31.80    LOAD MAP : 74.29    TPS : 1.20  MAP : 1.75  Final LOAD : 53.04
LOAD TPS : 31.80    LOAD MAP : 81.43    TPS : 1.20  MAP : 1.85  Final LOAD : 56.61
LOAD TPS : 31.80    LOAD MAP : 85.00    TPS : 1.20  MAP : 1.90  Final LOAD : 58.40
LOAD TPS : 37.40    LOAD MAP : 10.00    TPS : 1.60  MAP : 0.85  Final LOAD : 23.70
LOAD TPS : 37.40    LOAD MAP : 17.14    TPS : 1.60  MAP : 0.95  Final LOAD : 27.27
LOAD TPS : 37.40    LOAD MAP : 24.29    TPS : 1.60  MAP : 1.05  Final LOAD : 30.84
LOAD TPS : 37.40    LOAD MAP : 31.43    TPS : 1.60  MAP : 1.15  Final LOAD : 34.41
LOAD TPS : 37.40    LOAD MAP : 38.57    TPS : 1.60  MAP : 1.25  Final LOAD : 37.99
LOAD TPS : 37.40    LOAD MAP : 45.71    TPS : 1.60  MAP : 1.35  Final LOAD : 41.56
LOAD TPS : 37.40    LOAD MAP : 52.86    TPS : 1.60  MAP : 1.45  Final LOAD : 45.13
LOAD TPS : 37.40    LOAD MAP : 60.00    TPS : 1.60  MAP : 1.55  Final LOAD : 48.70
LOAD TPS : 37.40    LOAD MAP : 67.14    TPS : 1.60  MAP : 1.65  Final LOAD : 52.27
LOAD TPS : 37.40    LOAD MAP : 74.29    TPS : 1.60  MAP : 1.75  Final LOAD : 55.84
LOAD TPS : 37.40    LOAD MAP : 81.43    TPS : 1.60  MAP : 1.85  Final LOAD : 59.41
LOAD TPS : 37.40    LOAD MAP : 85.00    TPS : 1.60  MAP : 1.90  Final LOAD : 61.20
LOAD TPS : 43.00    LOAD MAP : 10.00    TPS : 2.00  MAP : 0.85  Final LOAD : 26.50
LOAD TPS : 43.00    LOAD MAP : 17.14    TPS : 2.00  MAP : 0.95  Final LOAD : 30.07
LOAD TPS : 43.00    LOAD MAP : 24.29    TPS : 2.00  MAP : 1.05  Final LOAD : 33.64
LOAD TPS : 43.00    LOAD MAP : 31.43    TPS : 2.00  MAP : 1.15  Final LOAD : 37.21
LOAD TPS : 43.00    LOAD MAP : 38.57    TPS : 2.00  MAP : 1.25  Final LOAD : 40.79
LOAD TPS : 43.00    LOAD MAP : 45.71    TPS : 2.00  MAP : 1.35  Final LOAD : 44.36
LOAD TPS : 43.00    LOAD MAP : 52.86    TPS : 2.00  MAP : 1.45  Final LOAD : 47.93
LOAD TPS : 43.00    LOAD MAP : 60.00    TPS : 2.00  MAP : 1.55  Final LOAD : 51.50
LOAD TPS : 43.00    LOAD MAP : 67.14    TPS : 2.00  MAP : 1.65  Final LOAD : 55.07
LOAD TPS : 43.00    LOAD MAP : 74.29    TPS : 2.00  MAP : 1.75  Final LOAD : 58.64
LOAD TPS : 43.00    LOAD MAP : 81.43    TPS : 2.00  MAP : 1.85  Final LOAD : 62.21
LOAD TPS : 43.00    LOAD MAP : 85.00    TPS : 2.00  MAP : 1.90  Final LOAD : 64.00
LOAD TPS : 48.60    LOAD MAP : 10.00    TPS : 2.40  MAP : 0.85  Final LOAD : 29.30
LOAD TPS : 48.60    LOAD MAP : 17.14    TPS : 2.40  MAP : 0.95  Final LOAD : 32.87
LOAD TPS : 48.60    LOAD MAP : 24.29    TPS : 2.40  MAP : 1.05  Final LOAD : 36.44
LOAD TPS : 48.60    LOAD MAP : 31.43    TPS : 2.40  MAP : 1.15  Final LOAD : 40.01
LOAD TPS : 48.60    LOAD MAP : 38.57    TPS : 2.40  MAP : 1.25  Final LOAD : 43.59
LOAD TPS : 48.60    LOAD MAP : 45.71    TPS : 2.40  MAP : 1.35  Final LOAD : 47.16
LOAD TPS : 48.60    LOAD MAP : 52.86    TPS : 2.40  MAP : 1.45  Final LOAD : 50.73
LOAD TPS : 48.60    LOAD MAP : 60.00    TPS : 2.40  MAP : 1.55  Final LOAD : 54.30
LOAD TPS : 48.60    LOAD MAP : 67.14    TPS : 2.40  MAP : 1.65  Final LOAD : 57.87
LOAD TPS : 48.60    LOAD MAP : 74.29    TPS : 2.40  MAP : 1.75  Final LOAD : 61.44
LOAD TPS : 48.60    LOAD MAP : 81.43    TPS : 2.40  MAP : 1.85  Final LOAD : 65.01
LOAD TPS : 48.60    LOAD MAP : 85.00    TPS : 2.40  MAP : 1.90  Final LOAD : 66.80
LOAD TPS : 54.20    LOAD MAP : 10.00    TPS : 2.80  MAP : 0.85  Final LOAD : 32.10
LOAD TPS : 54.20    LOAD MAP : 17.14    TPS : 2.80  MAP : 0.95  Final LOAD : 35.67
LOAD TPS : 54.20    LOAD MAP : 24.29    TPS : 2.80  MAP : 1.05  Final LOAD : 39.24
LOAD TPS : 54.20    LOAD MAP : 31.43    TPS : 2.80  MAP : 1.15  Final LOAD : 42.81
LOAD TPS : 54.20    LOAD MAP : 38.57    TPS : 2.80  MAP : 1.25  Final LOAD : 46.39
LOAD TPS : 54.20    LOAD MAP : 45.71    TPS : 2.80  MAP : 1.35  Final LOAD : 49.96
LOAD TPS : 54.20    LOAD MAP : 52.86    TPS : 2.80  MAP : 1.45  Final LOAD : 53.53
LOAD TPS : 54.20    LOAD MAP : 60.00    TPS : 2.80  MAP : 1.55  Final LOAD : 57.10
LOAD TPS : 54.20    LOAD MAP : 67.14    TPS : 2.80  MAP : 1.65  Final LOAD : 60.67
LOAD TPS : 54.20    LOAD MAP : 74.29    TPS : 2.80  MAP : 1.75  Final LOAD : 64.24
LOAD TPS : 54.20    LOAD MAP : 81.43    TPS : 2.80  MAP : 1.85  Final LOAD : 67.81
LOAD TPS : 54.20    LOAD MAP : 85.00    TPS : 2.80  MAP : 1.90  Final LOAD : 69.60
LOAD TPS : 59.80    LOAD MAP : 10.00    TPS : 3.20  MAP : 0.85  Final LOAD : 34.90
LOAD TPS : 59.80    LOAD MAP : 17.14    TPS : 3.20  MAP : 0.95  Final LOAD : 38.47
LOAD TPS : 59.80    LOAD MAP : 24.29    TPS : 3.20  MAP : 1.05  Final LOAD : 42.04
LOAD TPS : 59.80    LOAD MAP : 31.43    TPS : 3.20  MAP : 1.15  Final LOAD : 45.61
LOAD TPS : 59.80    LOAD MAP : 38.57    TPS : 3.20  MAP : 1.25  Final LOAD : 49.19
LOAD TPS : 59.80    LOAD MAP : 45.71    TPS : 3.20  MAP : 1.35  Final LOAD : 52.76
LOAD TPS : 59.80    LOAD MAP : 52.86    TPS : 3.20  MAP : 1.45  Final LOAD : 56.33
LOAD TPS : 59.80    LOAD MAP : 60.00    TPS : 3.20  MAP : 1.55  Final LOAD : 59.90
LOAD TPS : 59.80    LOAD MAP : 67.14    TPS : 3.20  MAP : 1.65  Final LOAD : 63.47
LOAD TPS : 59.80    LOAD MAP : 74.29    TPS : 3.20  MAP : 1.75  Final LOAD : 67.04
LOAD TPS : 59.80    LOAD MAP : 81.43    TPS : 3.20  MAP : 1.85  Final LOAD : 70.61
LOAD TPS : 59.80    LOAD MAP : 85.00    TPS : 3.20  MAP : 1.90  Final LOAD : 72.40
LOAD TPS : 65.40    LOAD MAP : 10.00    TPS : 3.60  MAP : 0.85  Final LOAD : 37.70
LOAD TPS : 65.40    LOAD MAP : 17.14    TPS : 3.60  MAP : 0.95  Final LOAD : 41.27
LOAD TPS : 65.40    LOAD MAP : 24.29    TPS : 3.60  MAP : 1.05  Final LOAD : 44.84
LOAD TPS : 65.40    LOAD MAP : 31.43    TPS : 3.60  MAP : 1.15  Final LOAD : 48.41
LOAD TPS : 65.40    LOAD MAP : 38.57    TPS : 3.60  MAP : 1.25  Final LOAD : 51.99
LOAD TPS : 65.40    LOAD MAP : 45.71    TPS : 3.60  MAP : 1.35  Final LOAD : 55.56
LOAD TPS : 65.40    LOAD MAP : 52.86    TPS : 3.60  MAP : 1.45  Final LOAD : 59.13
LOAD TPS : 65.40    LOAD MAP : 60.00    TPS : 3.60  MAP : 1.55  Final LOAD : 62.70
LOAD TPS : 65.40    LOAD MAP : 67.14    TPS : 3.60  MAP : 1.65  Final LOAD : 66.27
LOAD TPS : 65.40    LOAD MAP : 74.29    TPS : 3.60  MAP : 1.75  Final LOAD : 69.84
LOAD TPS : 65.40    LOAD MAP : 81.43    TPS : 3.60  MAP : 1.85  Final LOAD : 73.41
LOAD TPS : 65.40    LOAD MAP : 85.00    TPS : 3.60  MAP : 1.90  Final LOAD : 75.20
LOAD TPS : 71.00    LOAD MAP : 10.00    TPS : 4.00  MAP : 0.85  Final LOAD : 40.50
LOAD TPS : 71.00    LOAD MAP : 17.14    TPS : 4.00  MAP : 0.95  Final LOAD : 44.07
LOAD TPS : 71.00    LOAD MAP : 24.29    TPS : 4.00  MAP : 1.05  Final LOAD : 47.64
LOAD TPS : 71.00    LOAD MAP : 31.43    TPS : 4.00  MAP : 1.15  Final LOAD : 51.21
LOAD TPS : 71.00    LOAD MAP : 38.57    TPS : 4.00  MAP : 1.25  Final LOAD : 54.79
LOAD TPS : 71.00    LOAD MAP : 45.71    TPS : 4.00  MAP : 1.35  Final LOAD : 58.36
LOAD TPS : 71.00    LOAD MAP : 52.86    TPS : 4.00  MAP : 1.45  Final LOAD : 61.93
LOAD TPS : 71.00    LOAD MAP : 60.00    TPS : 4.00  MAP : 1.55  Final LOAD : 65.50
LOAD TPS : 71.00    LOAD MAP : 67.14    TPS : 4.00  MAP : 1.65  Final LOAD : 69.07
LOAD TPS : 71.00    LOAD MAP : 74.29    TPS : 4.00  MAP : 1.75  Final LOAD : 72.64
LOAD TPS : 71.00    LOAD MAP : 81.43    TPS : 4.00  MAP : 1.85  Final LOAD : 76.21
LOAD TPS : 71.00    LOAD MAP : 85.00    TPS : 4.00  MAP : 1.90  Final LOAD : 78.00
LOAD TPS : 76.60    LOAD MAP : 10.00    TPS : 4.40  MAP : 0.85  Final LOAD : 43.30
LOAD TPS : 76.60    LOAD MAP : 17.14    TPS : 4.40  MAP : 0.95  Final LOAD : 46.87
LOAD TPS : 76.60    LOAD MAP : 24.29    TPS : 4.40  MAP : 1.05  Final LOAD : 50.44
LOAD TPS : 76.60    LOAD MAP : 31.43    TPS : 4.40  MAP : 1.15  Final LOAD : 54.01
LOAD TPS : 76.60    LOAD MAP : 38.57    TPS : 4.40  MAP : 1.25  Final LOAD : 57.59
LOAD TPS : 76.60    LOAD MAP : 45.71    TPS : 4.40  MAP : 1.35  Final LOAD : 61.16
LOAD TPS : 76.60    LOAD MAP : 52.86    TPS : 4.40  MAP : 1.45  Final LOAD : 64.73
LOAD TPS : 76.60    LOAD MAP : 60.00    TPS : 4.40  MAP : 1.55  Final LOAD : 68.30
LOAD TPS : 76.60    LOAD MAP : 67.14    TPS : 4.40  MAP : 1.65  Final LOAD : 71.87
LOAD TPS : 76.60    LOAD MAP : 74.29    TPS : 4.40  MAP : 1.75  Final LOAD : 75.44
LOAD TPS : 76.60    LOAD MAP : 81.43    TPS : 4.40  MAP : 1.85  Final LOAD : 79.01
LOAD TPS : 76.60    LOAD MAP : 85.00    TPS : 4.40  MAP : 1.90  Final LOAD : 80.80
LOAD TPS : 82.20    LOAD MAP : 10.00    TPS : 4.80  MAP : 0.85  Final LOAD : 46.10
LOAD TPS : 82.20    LOAD MAP : 17.14    TPS : 4.80  MAP : 0.95  Final LOAD : 49.67
LOAD TPS : 82.20    LOAD MAP : 24.29    TPS : 4.80  MAP : 1.05  Final LOAD : 53.24
LOAD TPS : 82.20    LOAD MAP : 31.43    TPS : 4.80  MAP : 1.15  Final LOAD : 56.81
LOAD TPS : 82.20    LOAD MAP : 38.57    TPS : 4.80  MAP : 1.25  Final LOAD : 60.39
LOAD TPS : 82.20    LOAD MAP : 45.71    TPS : 4.80  MAP : 1.35  Final LOAD : 63.96
LOAD TPS : 82.20    LOAD MAP : 52.86    TPS : 4.80  MAP : 1.45  Final LOAD : 67.53
LOAD TPS : 82.20    LOAD MAP : 60.00    TPS : 4.80  MAP : 1.55  Final LOAD : 71.10
LOAD TPS : 82.20    LOAD MAP : 67.14    TPS : 4.80  MAP : 1.65  Final LOAD : 74.67
LOAD TPS : 82.20    LOAD MAP : 74.29    TPS : 4.80  MAP : 1.75  Final LOAD : 78.24
LOAD TPS : 82.20    LOAD MAP : 81.43    TPS : 4.80  MAP : 1.85  Final LOAD : 81.81
LOAD TPS : 82.20    LOAD MAP : 85.00    TPS : 4.80  MAP : 1.90  Final LOAD : 83.60
LOAD TPS : 85.00    LOAD MAP : 10.00    TPS : 5.00  MAP : 0.85  Final LOAD : 47.50
LOAD TPS : 85.00    LOAD MAP : 17.14    TPS : 5.00  MAP : 0.95  Final LOAD : 51.07
LOAD TPS : 85.00    LOAD MAP : 24.29    TPS : 5.00  MAP : 1.05  Final LOAD : 54.64
LOAD TPS : 85.00    LOAD MAP : 31.43    TPS : 5.00  MAP : 1.15  Final LOAD : 58.21
LOAD TPS : 85.00    LOAD MAP : 38.57    TPS : 5.00  MAP : 1.25  Final LOAD : 61.79
LOAD TPS : 85.00    LOAD MAP : 45.71    TPS : 5.00  MAP : 1.35  Final LOAD : 65.36
LOAD TPS : 85.00    LOAD MAP : 52.86    TPS : 5.00  MAP : 1.45  Final LOAD : 68.93
LOAD TPS : 85.00    LOAD MAP : 60.00    TPS : 5.00  MAP : 1.55  Final LOAD : 72.50
LOAD TPS : 85.00    LOAD MAP : 67.14    TPS : 5.00  MAP : 1.65  Final LOAD : 76.07
LOAD TPS : 85.00    LOAD MAP : 74.29    TPS : 5.00  MAP : 1.75  Final LOAD : 79.64
LOAD TPS : 85.00    LOAD MAP : 81.43    TPS : 5.00  MAP : 1.85  Final LOAD : 83.21
LOAD TPS : 85.00    LOAD MAP : 85.00    TPS : 5.00  MAP : 1.90  Final LOAD : 85.00

NOTE : Here, I'm not providing all serial monitor output. Just needed part of OUTPUT here displayed.

Here, this is modified code which provide result which I want.
float TPS_MIN = 0.00;
float TPS_MAX = 5.00;

float MAP_MIN = 0.85;
float MAP_MAX = 1.90;

int LOAD_MIN = 2;
int LOAD_MAX = 100;

int RPM_MIN = 400;
int RPM_MAX = 6000;

float LOAD_MIN_TPS_MIN = 2.00;
float LOAD_MAX_TPS_MIN = 10.00;

float LOAD_MIN_TPS_MAX = 15.00;
float LOAD_MAX_TPS_MAX = 85.00;

float LOAD_MIN_MAP_MIN = 2.00;
float LOAD_MAX_MAP_MIN = 15.00;

float LOAD_MIN_MAP_MAX = 10.00;
float LOAD_MAX_MAP_MAX = 85.00;

float injTime_MIN_LOAD_MIN = 4.00;
float injTime_MAX_LOAD_MIN = 4.60;

float injTime_MIN_LOAD_MAX = 8.06;
float injTime_MAX_LOAD_MAX = 14.86;

float injTime_MIN_RPM_MIN = 4.00;
float injTime_MAX_RPM_MIN = 8.06;

float injTime_MIN_RPM_MAX = 4.60;
float injTime_MAX_RPM_MAX = 14.86;

float mTPSmin;
float mTPSmax;
float mMAPmin;
float mMAPmax;

float yTPSmin;
float yTPSmax;
float yMAPmin;
float yMAPmax;

float mTPS;
float mMAP;

float yTPS;
float yMAP;

float LOAD;

float TPS, MAP;

float mLOADmin;
float mLOADmax;
float mRPMmin;
float mRPMmax;

float yLOADmin;
float yLOADmax;
float yRPMmin;
float yRPMmax;

float mLOAD;
float mRPM;

float yLOAD;
float yRPM;

float yInjTime;

int RPM;

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

void loop()
{
    TPS = analogRead(A0) * (5.0 / 1023.0);
    MAP = analogRead(A1) * (1.90 / 1023.0);
    RPM = analogRead(A2) * (6000 / 1023.0);

    mTPSmin = (LOAD_MAX_TPS_MIN - LOAD_MIN_TPS_MIN) / (TPS_MAX - TPS_MIN);

    Serial.print("mTPSmin : ");
    Serial.println(mTPSmin);

    yTPSmin = mTPSmin * (TPS - TPS_MIN) + LOAD_MIN_TPS_MIN;

    Serial.print("TPS : ");
    Serial.print(TPS);
    Serial.print("\t");
    Serial.print("LOAD : ");
    Serial.println(yTPSmin);

    mTPSmax = (LOAD_MAX_TPS_MAX - LOAD_MIN_TPS_MAX) / (TPS_MAX - TPS_MIN);

    Serial.print("mTPSmax : ");
    Serial.println(mTPSmax);

    yTPSmax = mTPSmax * (TPS - TPS_MIN) + LOAD_MIN_TPS_MAX;

    Serial.print("TPS : ");
    Serial.print(TPS);
    Serial.print("\t");
    Serial.print("LOAD : ");
    Serial.println(yTPSmax);

    mMAPmin = (LOAD_MAX_MAP_MIN - LOAD_MIN_MAP_MIN) / (MAP_MAX - MAP_MIN);

    Serial.print("mMAPmin : ");
    Serial.println(mMAPmin);

    yMAPmin = mMAPmin * (MAP - MAP_MIN) + LOAD_MIN_MAP_MIN;

    Serial.print("MAP : ");
    Serial.print(MAP);
    Serial.print("\t");
    Serial.print("LOAD : ");
    Serial.println(yMAPmin);

    mMAPmax = (LOAD_MAX_MAP_MAX - LOAD_MIN_MAP_MAX) / (MAP_MAX - MAP_MIN);

    Serial.print("mMAPmax : ");
    Serial.println(mMAPmax);

    yMAPmax = mMAPmax * (MAP - MAP_MIN) + LOAD_MIN_MAP_MAX;

    Serial.print("MAP : ");
    Serial.print(MAP);
    Serial.print("\t");
    Serial.print("LOAD : ");
    Serial.println(yMAPmax);

    mTPS = (yMAPmax - yMAPmin) / (TPS_MAX - TPS_MIN);

    Serial.print("mTPS : ");
    Serial.println(mTPS);

    yTPS = mTPS * (TPS - TPS_MIN) + yMAPmin;

    Serial.print("TPS : ");
    Serial.print(TPS);
    Serial.print("\t");
    Serial.print("LOAD : ");
    Serial.println(yTPS);

    mMAP = (yTPSmax - yTPSmin) / (MAP_MAX - MAP_MIN);

    Serial.print("mMAP : ");
    Serial.println(mMAP);

    yMAP = mMAP * (MAP - MAP_MIN) + yTPSmin;

    Serial.print("MAP : ");
    Serial.print(MAP);
    Serial.print("\t");
    Serial.print("LOAD : ");
    Serial.println(yMAP);

    LOAD = (yTPS + yMAP) / 2;
    Serial.print("Final LOAD : ");
    Serial.println(LOAD);

    mLOADmin = (injTime_MAX_LOAD_MIN - injTime_MIN_LOAD_MIN) / (LOAD_MAX - LOAD_MIN);

    Serial.print("mLOADmin : ");
    Serial.println(mLOADmin);

    yLOADmin = mLOADmin * (LOAD - LOAD_MIN) + injTime_MIN_LOAD_MIN;

    Serial.print("LOAD : ");
    Serial.print(LOAD);
    Serial.print("\t");
    Serial.print("injTime : ");
    Serial.println(yLOADmin);

    mLOADmax = (injTime_MAX_LOAD_MAX - injTime_MIN_LOAD_MAX) / (LOAD_MAX - LOAD_MIN);

    Serial.print("mLOADmax : ");
    Serial.println(mLOADmax);

    yLOADmax = mLOADmax * (LOAD - LOAD_MIN) + injTime_MIN_LOAD_MAX;

    Serial.print("LOAD : ");
    Serial.print(LOAD);
    Serial.print("\t");
    Serial.print("injTime : ");
    Serial.println(yLOADmax);

    mRPMmin = (injTime_MAX_RPM_MIN - injTime_MIN_RPM_MIN) / (RPM_MAX - RPM_MIN);

    Serial.print("mRPMmin : ");
    Serial.println(mRPMmin);

    yRPMmin = mRPMmin * (RPM - RPM_MIN) + injTime_MIN_RPM_MIN;

    Serial.print("RPM : ");
    Serial.print(RPM);
    Serial.print("\t");
    Serial.print("injTime : ");
    Serial.println(yRPMmin);

    mRPMmax = (injTime_MAX_RPM_MAX - injTime_MIN_RPM_MAX) / (RPM_MAX - RPM_MIN);

    Serial.print("mRPMmax : ");
    Serial.println(mRPMmax);

    yRPMmax = mRPMmax * (RPM - RPM_MIN) + injTime_MIN_RPM_MAX;

    Serial.print("RPM : ");
    Serial.print(RPM);
    Serial.print("\t");
    Serial.print("injTime : ");
    Serial.println(yRPMmax);

    mLOAD = (yRPMmax - yRPMmin) / (LOAD_MAX - LOAD_MIN);

    Serial.print("mLOAD : ");
    Serial.println(mLOAD);

    yLOAD = mLOAD * (LOAD - LOAD_MIN) + yRPMmin;

    Serial.print("LOAD : ");
    Serial.print(LOAD);
    Serial.print("\t");
    Serial.print("injTime : ");
    Serial.println(yLOAD);

    mRPM = (yLOADmax - yLOADmin) / (RPM_MAX - RPM_MIN);

    Serial.print("mRPM : ");
    Serial.println(mRPM);

    yRPM = mRPM * (RPM - RPM_MIN) + yLOADmin;

    Serial.print("RPM : ");
    Serial.print(RPM);
    Serial.print("\t");
    Serial.print("injTime : ");
    Serial.println(yRPM);

    yInjTime = (yLOAD + yRPM) / 2;
    Serial.print("Final injTime : ");
    Serial.println(yInjTime);

    delay(1000000);
}


text:
avrdude: ser_open(): can't set com-state for "\\.\COM4"
My Arduino code is not getting uploaded. It gives me "avrdude: ser_open(): can't set com-state for "\.\COM4" error. It worked literally 5 mins ago. now it doesn't work. I updated the drivers and stuff. I have a new Arduino and my code worked 5 mins ago. when i made some changes to the code It stopped working. I am using an (unofficial) Arduino Uno R3. the USB to UART chip's name is ATMEL Mega 16U2 2048 TW which I'm pretty sure is the Arduino mega chip?? my Arduino uses the ATMEL ATMEGA328P U. Please help
Thanks in advance, Paradox

maybe you installed the wrong driver ... what is and stuff?

Is another program open which uses the COM port? Did you try to reboot?


text:
Can arduino show the power drawn from its output pin on serial monitor? If yes, what code should I use?
I want to know is it possible that arduino can show how much power my prototype is drawing from arduino and if it can what would be the code for that.

You cannot directly measure the power, no. But it's simple enough to arrange using a very small amount of extra hardware.
Depending on what the device is you want to monitor there are two ways of creating the circuit that you need. Both require just a single small resistor, and either one or two analog pins.
The simplest arrangement is the "low-side current shunt" and is simply a small resistor between the ground of your device and the ground of the Arduino. This causes a small voltage drop which raises the ground potential of your device slightly, so could have an effect on communication if you're not careful (see the alternative below). Then a connection from the "top" of that resistor to an analog input will allow you to monitor the voltage drop across that resistor. From that, using Ohm's Law, you can calculate the current. That then can give you the power.
Here's a schematic:

simulate this circuit – Schematic created using CircuitLab
This arrangement does have the benefit that it will work for any power supply voltage, not just the 5V supply pin (for example powering from the VIN pin or 3.3V pin).
If you are powering your device from no more than 5V you can place the resistor in the 5V feed and avoid the offset to the ground voltage. The idea is just the same: use an analog input to monitor the voltage drop across the resistor to calculate the current and hence the power:

simulate this circuit
If you want to measure the current being drawn out of a GPIO pin, though, there is an extra step you need to consider. The GPIO has a MOSFET within it which imposes a small resistance of its own on the output. This resistance will of course cause a variation in the output voltage depending on the current drawn from the output pin. So it is important to know what the actual output voltage is rather than assuming that it would be 5V.  For that a second analog input is needed:

simulate this circuit
Now the voltage drop is calculated as the difference between the voltages measured by A0 and A1. Then all the other calculations are the same.

No, it cannot do power measurement. With an Arduino (and most other microcontrollers) you only have voltage measurement (on the analog input pins).
Though this is half of the power measurement, since power is voltage multiplied by current. Measure the voltage on that pin with an analog pin. Then you need a way to measure the current. For that you need extra hardware. There are current sensors made for Arduino, which measure the current flowing through its pins and giving out a corresponding analog voltage, which you can then measure on an analog pin. Make sure that the current sensor is rated for the correct current range to not overload it or loose resolution (by having a way bigger range in the sensor than with the actual current). For a digital output pin of an Arduino Uno/Nano the max. current should be 20mA.
You can also google for something like "Arduino current sensor". A short search gave me some promising results.
Then when you have measured the voltage and current you can multiply them to get the power.


text:
Modify duty cycle of tone on AVR
I'm writing a MIDI - to square wave converter designed to interface between a MIDI instrument and a musical Tesla coil. Essentially, this should act like a monophonic MIDI synthesiser, but the requirements are slightly different to most projects:

I only want to generate (audible frequency) square waves.
It is essential that the pulse on time not exceed a configurable constant value, e.g. 160 microseconds.
I'd like to map the 'velocity' of a given note to the duty cycle, scaled appropriately.
Ideally, I'd like to generate envelopes for the pulse width with configurable attack, decay, sustain, release parameters.
I'd like to write the audio generation code "from scratch" for the sake of my own understanding of how timing registers work.

The gist of what I want is this (untested) sketch, but it obviously doesn't allow for control of the on time.
#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();
const static int out_pin = 9;

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
    tone(out_pin, pitch);
    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
    noTone(out_pin);
    digitalWrite(13, LOW);   // turn the LED off
}

void setup() {
  MIDI.setHandleNoteOn(handleNoteOn);
  MIDI.setHandleNoteOff(handleNoteOff);

  MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop() {
  // put your main code here, to run repeatedly:
  MIDI.read();
}

My question is essentially, what the best way to achieve this kind of musical pulse-width control is. The ideas I had were either
a) A large number of manual register-sets to bit-bang the required signal out at the highest frequency I can get, probably in the kHz
b) Create each pulse using a custom pulseOut function, using timer0 for microsecond delays
I'd also be open to using external analog circuitry, e.g. a voltage controlled pulse shortener.
The load here is an LED, so no special allowances need to be made for its behavior.

What Arduino board are you using?

did you see the arduino-toneac library?

An Arduino nano.
I didn't see the toneaclibrary - though not exactly capable of what I need out of the box, it's very helpful to read!

I would recommend using a hardware PWM signal generated by Timer 1, or
another 16-bit timer if you have more than one (like on the Mega). The
16 bits provide both a decent frequency range and a good time
resolution. This should provide jitter-free timings, unlike any
software-based method. This will also avoid unduly loading the CPU.
The first thing to do would be to choose the prescaler and the operating
mode. These choices will impact both the lowest available frequency and
the time resolution. The latter affects the accuracy of the
highest-pitched notes. Assuming your Arduino is clocked at 16 MHz,
some sensible choices are:

prescaler = 64, normal PWM
prescaler = 8, phase correct PWM
prescaler = 8, normal PWM

prescaler
PWM mode
time resolution
lowest freq.
lowest note

64
normal
4 µs
3.81 Hz
C−1 (MIDI 0)

8
phase correct
1 µs
15.26 Hz
B0 (MIDI 11)

8
normal
0.5 µs
30.52 Hz
B1 (MIDI 23)

For the sake of having accurate notes, I would go for the lowest time
resolution that is compatible with the music you want to play.
Once this is configured, you can control the music by writing to three
registers:

TCCR1A turns the PWM on and off
the register holding TOP (OCR1A or ICR1, depending on the mode)
controls the frequency (the pitch)
a compare match register (OCR1A or OCR1B, depending on the channel)
controls the duration of the pulses

Your program would then need to set the frequency as a function of the
requested note, then continuously adjust the pulse duration in order to
create the desired envelope while obeying the requested velocity and
ensuring the value of 160 µs is never exceeded.
The main code does not even need to be synchronized with the timer: the
PWM modes guarantee glitch-free PWM even when you change the duty cycle.
Be careful though when changing the frequency: you may get huge glitches
when increasing the frequency. It is safer to stop, clear and restart
the timer when changing notes.


text:
Arduino diagrams
I would like to document some of the experiments I have been doing with the arduino.
In many of the internet posts on Arduino projects, they have a similar diagram of the Uno or Mega with breadboards and resistors.  Some with more detail than others.  I've been looking at many of these articles to see if they mention what drawing package they are using but nobody seems to do so.
I could take one of them and just colour out the wires but I can't get the right shade of grey or green.

What diagramming tool can be used for drawing these diagrams?
Where can I get hold of a blank Arduino Mega/Uno/Nano template.

https://fritzing.org/

Found that you can also do this on https://www.tinkercad.com  Currently, it only does Uno.  This one has a built in simulator.

As Juraj commented, those kinds of pictorial diagram are often made using a program called Fritzing.
You should also try producing a more traditional and useful diagram called a schematic. Fritzing can do that at the same time. There are also free programs that are better. See KiCAD, Eagle, EasyEDA etc.
You might find online emulators like Wokwa to be usefull.

Related:
Many of the Rules and guidelines for drawing good schematics also apply to Fritzing's pictorial diagrams.


text:
DHT11's data on MAX7219 reads 0
I want print data from a DHT11 (temperature and humidity) on a MAX7219 LED display but it only shows 0. Serial monitor, on the other hand, shows both humidity and temperature which means that my circuit works just fine and there's something wrong with code.
Could anyone please point out what needs to be fixed to make it work? Thanks.

Here is the code
#include <WiFi.h>
#include <NTPClient.h>
#include <DHT.h>
#include <WiFiUdp.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_H
#define MAX_DEVICES 4
#define CLK_PIN   5
#define DATA_PIN  7
#define CS_PIN    6
MD_Parola Display = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
const char* ssid     = "6666";
const char* password = "6666";
String Time, hour, minute;
String Formatted_date;
long currentMillis = 0;
long previousMillis = 0;
int interval = 1000;
#define DHTPIN  A2         /*Signal pin for DHT11 Sensor*/
#define DHTTYPE    DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("Connecting.");
  }
  Serial.println("");
  Serial.println("WiFi connected.");
  timeClient.begin();
  timeClient.setTimeOffset(0);

  Display.begin();
  Display.setIntensity(0);
  Display.displayClear();

   dht.begin();
   Serial.println("Status\tHumidity (%)\tTemperature (C)");
}
void loop()
 {
   obtainTime();
}
void obtainTime() {
  while(!timeClient.update()) {
    timeClient.forceUpdate();
  }
  currentMillis = millis();
  if (currentMillis - previousMillis > interval)  {
previousMillis = millis();
Formatted_date = timeClient.getFormattedDate();
Serial.println(Formatted_date);
hour = Formatted_date.substring(11, 13);
minute = Formatted_date.substring(14, 16);

Time = hour + ":" + minute;
Serial.println(Time);
Display.setTextAlignment(PA_CENTER);
Display.print(Time);

delay(3000);
// The DHT11 returns at most one measurement every 3s
  float h = dht.readHumidity();
  //Read the moisture content in %.
  float t = dht.readTemperature();
  //Read the temperature in degrees Celsius

Serial.println(t);
Serial.println(h);
Display.setTextAlignment(PA_CENTER);
Display.print(t);
delay(5000);
Display.displayClear();

}

}

Variable t is a float. Try temporarily changing this: Display.print(t); to Display.print(42); to see if the displayed temperature is something other zero. Also look at the Parola library to see what data type the print() method can handle. Maybe also try a minimal Parola "Hello World" type sketch to see if a simple sketch behaves as expected.  It would be nice if you formatted your code in the IDE before posting so it would be easier to read.

Thank you. Sure, I'll give it a shot.
I tried this and it worked.
char temp_result[6];
dtostrf(t,2,1,temp_result);
Display.setTextAlignment(PA_CENTER);
Display.print(temp_result);
Not sure what "char temp_result[6]" does though.
Any idea?

Ok. So you have converted the float t to a "c string" using dtostrf() , that is to a null terminated character array, then used that in the print() method for parola and it works. The conclusion is that parola can't handle a float datatype directly. I guess that you can now write your own answer to the original question to close the issue.

Done. Thanks for your help.

It turned out that MD_Parola can't handle floats directly. I fixed the problem by converting the floats t and h into strings using dtostrf()
 float h = dht.readHumidity();
 float t = dht.readTemperature();

char temp_result[6];
dtostrf(t,2,1,temp_result);

char hum_result[6];
dtostrf(h,2,0,hum_result);
Serial.println(t);
Serial.println(h);
Display.setTextAlignment(PA_CENTER);
//Display.print(temp_result);
Display.print((String)temp_result+" "+"C");
delay(5000);
//Display.print(hum_result);
Display.print((String)hum_result+" "+"%");
delay(5000);


text:
Why the led is always on in proteus?
I am simulating a circuit with arduino, which determine if there is current at input, then turn the led on at the output. The problem is the light is always on even when the button is open at the input.

This is my code:
void setup() {
  pinMode(7, OUTPUT);
  pinMode(8, INPUT);
  digitalWrite(7, LOW);
}

void loop() {
  int on = digitalRead(8);
  digitalWrite(7, on);
}

Why does this happen and how do I solve it?
Any help would be appreciated.

What happens when you add a pulldown resistor to your input pin (a resistor like 10k from input pin to ground)

And are you trying to connect 10V to an Arduino input? Thats bad. In reality that would destroy the input pin hardware

@chrisl I get it. But in reality, does it randomly still work like in simulation or the input pin just die immediately?

At 10V I would guess: Yes it will die immediately. As I remember there are clamping diodes integrates into the pins hardware, which let the overflow voltage dissipate. They will get destroyed, though we cannot know if they fail short or not

Microcontroller inputs don't detect the presence of current. They compare a voltage to a threshold.
In reality the input pin is closest to a capacitor. You press your button and it charges that capacitor to above the threshold voltage for "HIGH". Then you release the button but that capacitor remains charged and still reading "HIGH". You need something to reduce the charge on that capacitor to below the "LOW" threshold voltage.
This is most normally done with a resistor between the GPIO pin and GND which will "bleed off" that charge and give you a LOW reading when the button is released.
This is a "pull down" resistor (you can also reverse it and have a "pull up" resistor and the button connected to GND) and is an essential part of any input that doesn't itself generate both the HIGH and LOW voltages required (any switch or button).
Also 10V on a GPIO pin will destroy your Arduino.

I have added a 10k resistor which connect ground and input pin as you and chrisl suggest and it works well. But about 10V source, why does my circuit still work, why proteus doesn't warn me about that?

@Becker It's only a simulation - an approximation. They probably just didn't think people would do that sort of thing and didn't program it to warn you.

I get it. Thanks a lot for your answer.


text:
Arduino lagging or buggy with delays and serial print?
I got a strange issue with my Arduino Leonardo (clone). It seems to be laggy or buggy, I don't know what the issue is.
I get issues when I use "long" delays.
Below sketch is working fine.
void setup() {
 Serial.begin(9600);
}

void loop() {
  delay(1000);
  Serial.println("Hello World 1000"); // added delay to line for debugging
}

When I use delay(2000) it still is fine. But when I try delay(3000) the serial monitor doesn't output anything (or just 1 line). When I lower the delay to like 2500, it gets better. But not without issues. Sometime it will just skip one iteration, see log below.
11:33:06.328 -> Hello World 2500
11:33:11.331 -> Hello World 2500
11:33:13.909 -> Hello World 2500
11:33:18.815 -> Hello World 2500
11:33:21.395 -> Hello World 2500
11:33:23.815 -> Hello World 2500
11:33:26.392 -> Hello World 2500

What might the issue be?
EDIT:

when I do 3x delay(1000) I get same (weird) results. With 2 times, it does work ok.

The logs are from the serial monitor from the Arduino IDE

I added below line in the setup, it does print the line just once.
while (!Serial) {}
Serial.println("setup()");

Important note: I think it might have to do more with the serial communication than with the Arduino itself. I tested the same things on another computer (Windows 10), and then I just get the expected results. I am using Manajaro Linux as the main machine.
When the output to the serial port is "lagging" so the printing of the line is missed/skipped, I see the RX and TX led on the Arduino light up for a while. Then when they go out, the serial monitor sometimes outputs 2 lines at once.

What happens if you do multiple delay(1000); in sequence between println()?

Is the log directly from the Serial Monitor? Or do you use any other communication channel?

Include a Serial.println("setup()"); or something similar in setup() so that the sample output makes clear whether or not setup() is being executed more than once.

Thanks for the help. I edited my post and added answers and more information.

Given the problem occurs with Manajaro Linux and not Windows 10, wouldn’t that indicate that the problem might be OS or IDE related,  not Arduino? What happens if you connect a terminal emulator to the USB port rather than the Arduino IDE (i.e., the USB port that has the Leonardo with the sketch running connected)?

@RowanP how would I do that?

Re “how would I do that?”: stty -F /dev/ttyACM0 raw 9600 && cat /dev/ttyACM0

Or use any dedicated terminal emulator like "PuTTY", available for Windows and Linux.

@EdgarBonet just tried your commands. I see output, but with the same "laggy" result as in the Arduino IDE. The RX is also blinking heavily, TX is blinking far less.

I tried your code, with 3 s delay, an Arduino Micro, an Ubuntu host, and the commands I showed. I see no laggy behavior. Maybe another process is accessing the serial port? You can check with sudo fuser -v /dev/ttyACM0

"I am using Manajaro Linux as the main machine" Had your problem with Manjaro here to my surprise. Tested different AVR cores, different terminals, same problem. Observed that RX was blinking for no reason. Problem disappeared while trying to inspect USB traffic with wireshark. Have not been able to replicate problem since. Noticed an external 3.0 hub wasn't working. System out of date. Updated, rebooted, still can't recreate the problem. Also observed that sending traffic would prompt inbound data (even with no code to read on Arduino). Add counter to code. Counts were skipped.

@timemage Good point. I don't expect RX to blink without reason. So something is/was using the same port, perhaps some misguided getty?

@thebusybee: ModemManager seems to be a common offender.

@EdgarBonet what is ModemManager? I seem to have it installed it too... Does it interfere with the serial monitor? How did you come across it?

ModemManager gets mentioned a lot in discussions about serial port problems on Linux. The Arduino IDE comes with a script called arduino-linux-setup.sh which, among other things, uninstalls ModemManager.

Another culprit for this sort of problem is Cura, however neither of this were in play during my own my prior comment. ModemManager is one of the first things to go on a Linux machine of anyone regularly using Arduino. I specially looked to see verify that Cura was not running. Modem manager attempts to identify the "modem" when the device enumerates. It does not continually attempt to send to the board. Its direct effects on the connection are limited to moments following bus enumeration.

I will test it all out and report back here. Good suggestions!

I tried uninstalled ModemManager, it messed up my system. I couldn't connect to internet anymore. WiFi and Bluetooth tray icons and applications were gone. Took me a while to fix it, since WiFi is the only way to connect with this machine. After uninstalling it though, I checked if the issue was fixed, unfortunately it was not. I also checked with fuser command. When the serial monitor of the Arduino IDE is closed, it returns nothing. When it is open it returns the following: sudo fuser -v /dev/ttyACM0 /dev/ttyACM0:        root       9775 F.... java


text:
Servo won't stop rotating
I have an Arduino Uno R3 board and after some time not in use it seems to have corrupted. My code is below, basically I want to rotate a servo 90 degrees every 12 hours but as soon as I plug it in the servo starts rotating non-stop. Have tried multiple delay steps and shortening and lengthening the write but the same effect happens.
#include <Servo.h>

Servo myservo;

void setup {
  myservo.attach(10);
}

void loop() {
  myservo.write(90);
  delay(3600000);
}

I guess that is a continuous servo. In this situation, with your code what you observe is expected: the servo runs forever at constant speed. If it was a normal servo your code would not work either, as you never change the 90 degrees value, hence the servo would stay forever in that position.

Note that your Arduino UNO is probably in perfect shape, anyway.

Not related to the servo issue, but I think your delay is 10hrs.

I suppose you are using a continuous servo otherwise you wouldn't be able to make it turn 90° more than twice (a normal servo has a varying angle of only 180°).
Now if you are using a continuous servo, you have to be aware that the value you pass to myservo.write() does not represent an angle anymore!
With a continuous servo, the value passed to myservo.write() now means a speed of rotation where, but the range of acceptable values is the same as for a normal servo, i.e. [0; 180]:

0 means max speed clockwise
90 means no motion
180 means max speed counter-clockwise

Now if you want to turn the servo exactly 90°, then you must know the max speed of the servo, and from that, compute the time during which you must let it turn:
// Start turning clockwise
myservo.write(0);
// Go on turning for the right duration
delay(TURN_TIME);
// Stop turning
myservo.write(90);

The problem here is to compute TURN_TIME. For this, you must check the datasheet of your servo.
On my own servo, a Feetech Micro 1.3kg Continuous Rotation Servo FS90R, the max speed is:

0.12s/60° when powered with 4.8V
0.10s/60° when powered with 6V

However, with the Arduino UNO, the supplied voltage should be exactly 5V, neither 4.8V, nor 6V.
If we take a linear approximation, then we can apply the following formula to find out the speed T (in s/60°):
T = (0.12 - 0.10) * (V - 4.8) / (4.8 - 6.0) + 0.12

Hence, for 5V, we can take it for granted that the max speed should be:
T = (0.12 - 0.10) * (5.0 - 4.8) / (4.8 - 6.0) + 0.12 = 0.116667

Since we need 90°, this means we must run the servo at its max speed during:
T' = T * 1.5 = 0.175s

Hence we now have the following program:
#include <Servo.h>

#define TURN_TIME 175

Servo myservo;

void setup {
    myservo.attach(10);
    // Initially the servo must be stopped
    myservo.write(90);
}

void loop() {
    // Start turning clockwise
    myservo.write(0);
    // Go on turning for the right duration
    delay(TURN_TIME);
    // Stop turning
    myservo.write(90);

    // Wait for 12h
    delay(12 * 3600 * 1000);
}

Of course, you will need some experiments to find the exact right values; you may also find out that the servo may be sensitive to noise and even when it should not move (value = 90), it does move (not fast, but still it moves).

Also note: The arduino crystal is not a reliable time source. It can be expected to lose or gain up to a minute per day, not including the offset of the actual time taken to execute the program. If you want accurate time, buy a real Time Clock (RTC) module, and set an alarm on it, which can then trigger a function on the Arduino every 12 hours.

don't know why, but mine FS90R continuous servo is stopped with servo.write(95);

That was useful.
I was getting the same rotation thing when I had servos at 90. What I did to stop that was use the detach command. Using the Particle Photon with a continuous servo attached.
bool state = LOW;

Servo servo1;
Servo servo2;// create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 90;    // variable to store the servo position

void setup()
{
  servo1.attach(D0);
  servo2.attach(D1);
  Spark.function("test", testFunction);
  servo1.attach(10);
  servo1.write(90);
  servo2.attach(10);
  servo2.write(90);
}

void loop()
{
    servo2.detach(), servo1.detach();
    delay (25);
    servo2.attach(D0), servo1.attach(D1);
    delay (25);
    servo1.write(0), servo2.write(180);
    delay (1000);
    servo2.write(180), servo1.write(0);
    delay (1000);
    //I did this to make the servo not move when it is at 90.
    servo2.detach(), servo1.detach();
    delay (25);
    servo1.write(90), servo2.write(90);
    delay (1000);
    //end
    //You must attach the servos again to make them move again.
    servo2.attach(D0), servo1.attach(D1);
    delay (25);
    //end
    servo1.write(180), servo2.write(0);
    delay (1000);
    servo2.write(180), servo1.write(100);
    delay (1000);

}

int testFunction(String args) {

    return 200; // This is checked in the web app controller for validation
}


text:
A question about Continuous Rotation Servo and Arduino
We have this project that uses a Continuous Rotation Servo and we have a slight problem controlling it. We're planning to attach a Rack Gear to the Servo to slide a stainless steel to the right, and vice versa.
The Question: Is it possible to stop the continuous rotation servo when the stainless steel hits a bump or it already made its proper position accurately?
This idea is like the Power Windows of cars.

Either add limit switches or use stepper-motors instead of a cr-servo.

You can track the servo rotation with an encoder and after reaching a specific position, you can send different instructions to execute other actions.
Other alternative is maybe you can place a limit switch at the position where you want it to stop.

I'd probably consider your suggestion. Thank you for your reply. :)

Glad I could help. Good luck.

The way that power windows detect fully open or closed is typically by measuring the motor current:  When a motor is stalled it's current increases because there is no longer any back-emf as there is when the magnetic fields are rotating.  You can measure this current and then stop when you see it increase over the running current.
This is especially useful in the context of the window example as limit switches would have to be set EXACTLY at the closed position which is hard to do and if they fail or get out of alignment can lead to burned out motors if the limit switch is set beyond the physical travel limit.  Furthermore, an obstruction will result in a burned out motor even if the limit switch is correctly set as the window could never reach its limit position.  In these two cases, a timeout would need to be included as a backup (A timeout is not a bad idea in any case!).


text:
Square wave based on falling edge of alternative pulse of upcoming RPM square wave
In my recent project, I have RPM Square wave from vehicle. Now, based on that I want square wave based on falling edge but only alternative pulse of RPM square wave.
I think below image clear more properly.

Upper yellowish square wave which I need. And below pinkish square wave is RPM square wave.
I made a code for that and it's working fine but when RPM is stable. But when RPM change rapidly then it's not working fine.
const int kPinRPM = 3;        // RPM / Digital Pin 3
const int RPMInterrupt = 1;   // RPM's interrrupt pin
byte engineCylinders = 2;         // Engine cylinders = 4;
byte engineCycles = 4;            // Engine cycle = 2
int refreshInterval = 750;        // Milliseconds between sensor updates
unsigned long previousMillis = 0;
volatile int RPMpulses = 0;
int RPM, Final_RPM;

const int kPinInj = 12;

volatile uint32_t kInjTime = 0;

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

  pinMode(kPinRPM, INPUT_PULLUP); // Enable internal pullup
  attachInterrupt(RPMInterrupt, countRPM, FALLING); //Interrupt for RPM

  pinMode(kPinInj, OUTPUT);
}

void loop()
{
  if(millis() - previousMillis > refreshInterval)
  {
    previousMillis = millis();
    RPM =  getRPM();
  }

  Serial.println(RPM);

  if((kInjTime > 0) && ((millis() - kInjTime) >= 10))
  {
    kInjTime = 0;
    digitalWrite(kPinInj, LOW);
  }
}

void countRPM()
{
  RPMpulses++;

  if(RPMpulses % 2 == 0)           // Skip alternative pulse
  {
    kInjTime = millis();
    digitalWrite(kPinInj, HIGH);
  }
}

int getRPM()
{
  Final_RPM = int(RPMpulses * (60000.0 / float(refreshInterval)) * engineCycles / engineCylinders / 2.0);
  RPMpulses = 0;
  Final_RPM = min(99999, Final_RPM);
}

After SUGGESTION, updating my codes. But it output waveform has some problem. In white circle, you can see that problem.

Rather than saying
if(RPMpulses % 2 == 0)           // Skip alternative pulse
  {
    kInjTime = millis();
    digitalWrite(kPinInj, HIGH);
  }

and later setting kPinInj in the main loop, you could act as follows:
digitalWrite(kPinInj, RPMpulses & 1); // Set or clear kPinInj
if(RPMpulses & 1)
  kInjTime = millis();  // Store alternate times

This would ensure that your trace 1 toggles properly.  If you want a shorter up-time on that trace, you could treat CHANGE interrupts rather than FALLING, and maintain RPMpulses as a number twice as big as now, ie use 120000 instead of 60000 in the RPM calculation, and could say:
digitalWrite(kPinInj, (RPMpulses & 3)==1); // Set or clear kPinInj
if((RPMpulses & 3)==1)
  kInjTime = millis();  // Store alternate fall times

Note, the floating point arithmetic in getRPM() is slow.  At a 750 ms refresh interval, that may not matter much.  But you probably can get good enough results rather more quickly using just integer arithmetic, if you parenthesize the expression somewhat as follows:
Final_RPM = ((RPMpulses * (60000UL / 2) * (engineCycles/engineCylinders)) / refreshInterval;

That is, do any remainderless divisions early; multiply all the remaining numerator terms together into a large number; then divide by the comparatively small refreshInterval, ending up with numerous significant digits without the use of floating point arithmetic, which takes many milliseconds on typical Arduino systems.
Edit 2: If your modified code still says RPMpulses = 0; within getRPM(), you may get a glitch at the end or beginning of each   refresh interval.  You may instead need to say RPMpulses = 1;, or RPMpulses &= 1;, or some such.  Also, to avoid an extra count when the latter expression is 1 instead of 0, say RPM0 = RPMpulses &= 1; and use (RPMpulses-RPM0) instead of RPMpulses in calculating Final_RPM.

Thank you. I tried out this code. But I faced some problem in Output waveform. I just posted out photo. Please see it.

@Hasan see edit 2

Ok, thank you. It is working fine now after your second suggestion. Of course, I do. Don't worry.

There are some things you shouldn't be doing within an interrupt service routine (ISR) like countRPM():

Don't call the millis() function. It depends on other interrupts which will be disabled during the execution of your ISR.
Don't call digitalWrite or any other functions
Don't use execution cycles hungry operators like % (modulo). To obtain modulo 2, just use a bit mask for the LSB.

What you should actually be doing within the ISR is just setting/resetting a flag or variable. Then, do all your stuff in the loop() function according the value of the flag or variable.

Calling millis() is OK. It won't increment inside the IRS, but it works fine in an use case like this.

As E.B. notes, calling millis() is ok – it doesn't need interrupts to report a result.   2. Although digitalWrite() is slow  – a couple of microseconds – it's ok to call it.  It's true that calling non-reentrant functions should be avoided.  3. Typically, compiler implements div or mod by any power of 2 by shifting or via bitwise AND with a mask; ie, while % may in general be "execution cycle hungry", %2 isn't.  That said, I'd use a mask as you suggest.

Hey, @jwpat7, I'm also E.B.! :)