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:
Controlling a button
I'm going to write a sketch that would light up the first LED (D1) of the training shield at the beginning, then move the LED light to the left or to the right whenever you press the S1 or S2 buttons, respectively. When the LED is already at the first (D1) or the last (D8), it should no longer move when going further to the left or right, respectively.
Looks exactly like this: https://www.youtube.com/watch?v=_KQQTdDMgOU
Here's what I made so far:
int x = 0;

void setup() {
  for(int i=11; i <= 18; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  x = digitalRead(pushButtonPin);
  if (pushButtonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

What you made so far is only turn on and off LED according to button state. I believe there's more efficient code out there, but you can try:
int x = 11;

 void setup() {
 for(int i=11; i <= 18; i++) pinMode(i, OUTPUT); //assuming the led is on pin 11-18
 }

 void turnLED(int num)
 {
     for(int i=11; i <= 18; i++)
         if (num==i) digitalWrite(i,HIGH); else
                     digitalWrite(i,LOW);
 }

 void loop() {

    if (digitalRead(buttonRight))
    {
        x++;
        if (x>18) x=18;
    }
    else if (digitalRead(buttonLeft))
    {
        x--;
        if (x<11) x=11;
    }
    turnLED(x); //turn LED on according to value of 'x'
    delay(500);
}

You also need to add software or hardware debouncing to your button or else you will get multiple false button press for a single physical press of the button.

@AndreCourchesne theoretically the 500ms delay would handle this? (though a bit long), but I don't believe the button would keep bouncing for 500ms

source: Stack Exchange

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

sort: votes


text:
Suse or Debian Linux Installation on Raspberry PI 3
Is I can install Suse or Debian Linux Installation on Raspberry PI 3. I yet to try. Based on the answer I can opt for it. Because I need in particular either of this OS for my requirement in classified project. Does this PCB design supports this OS.
Any advice or suggestions is greatly appreciated.

Flagged to close as entirely unrelated to Arduino.

I am newbie and I'm curious to know.

And we're Arduino users who don't know about Rasperry Pi. Maybe you should go and ask on the Raspberry Pi SE...? They may have a clue.

Is there a forum for Raspberry Pi [or] for that SE. I felt this is the one. So I asked over in here.

Yes - here.

Dev - This is a serious question, Why did you think this was a forum for Raspberry Pi?  Maybe there is something that can be done to stop the confusion you had from happening again.

But its about Hardware,- the Forum. I asked phenomenal, maybe Hardware bit wired so, I think it may relevant more over here and makes sense so. It can be ridden from Hold, if you hold so. Else whatever!

what does Arduino does with ARM. What is Arduino first of all. Do I need to make this inquiry as another Question.

There are many derivatives to the Arduino Uno.  Some use different processors.  The ARM based Arduinos are one of these derivatives.  That said, the ARM based Arduinos do not run an OS.  The have a boot loader and your code is what is running.  The ARM based RaspberryPis do have an OS.  And your code is just 1 of many many programs that are run in a complex time slicing paradigm controlled by the OS.  They are completely different approaches to running your code.   So much so that questions about one really do not apply to the other.

It is always best to try then post in one of the Stack Exchange groups.
This question is very general.  So the answer will also be vague as the actual porting of a Linux OS distribution to a new platform is not trivial and contains many steps.  And not all of them may have been completed to the extent to suit your needs.
Evidently you can run Debian on a Raspberry Pi.  But there are a few issues.  Look here and do the research to understand if these limitations will cause you to abandon this path.
As for Suse, evidently it is a "specially packaged version of SUSE".  So may not actually have all the features a normal Suse distribution has.  Look here to decide if it will work for you.

Suse doesn't work you mean to say.

I am not find what are features might not work in Suse over what you've sighted. Sorry for Vague sense. Have you ever tried Suse anytime as a experience, in your term.

Considering the Negative Voted, but imperative post, any feature-set could be arrived. What does Suse Lags, Will I succeed atleast with X or GNOME Windowing stuff. Refer this, http://math.stackexchange.com/questions/2099908/is-we-could-wander-on-factorial-equalities-considering-ordinals-as-discussed-in

I have not tried anything except Raspbian.    It appears to be what everyone is using.   And in the world of open source, using what everyone else has already debugged is usually the best way to go.

I am not sure why this question has not been ported to the Rraspberry Pi Stack Exchange site.

It got closed by consensus of votes before a moderator got to it, that's why. ;) Only moderators can migrate to other sites.

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


text:
Reduce current consumption on ATtiny85
I am trying to reduce current consumption on my project. Right now it is using ~1.28mAh, it should be possible to get it much lower (I am using AA batteries as the power source).
The ATtiny85 has its fuses set to run at 1MHZ, with BOD disabled.
I am using this board to mount the CPU. I desoldered the power LED and the regulator, feeding power directly from the batteries to the 5V input.
Nothing was connected to any other pins while measuring, just 5V and GND. The code was running in debug mode, so every 8 seconds it flashed a debug LED. I don't know for how much this could account.
Full code:
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>

#define DEBUG (true)
#define INT_PIN (0)
#define OUT_PIN (2)
#define LED_PIN (1)

/***************************************************
 *  Name:        ISR(WDT_vect)
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Watchdog Interrupt Service. This
 *               is executed when watchdog timed out.
 *
 ***************************************************/
EMPTY_INTERRUPT(WDT_vect);
EMPTY_INTERRUPT(PCINT0_vect);

/***************************************************
 *  Name:        enterSleep
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Enters the arduino into sleep mode.
 *
 ***************************************************/
void enterSleep() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_cpu();
  sleep_disable(); /* First thing to do is disable sleep. */

  #if DEBUG
    digitalWrite(LED_PIN, HIGH);
    for (uint16_t dbg = 0; dbg < 65535; dbg++);
    digitalWrite(LED_PIN, LOW);
  #endif
}

/***************************************************
 *  Name:        setup
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Setup for the serial comms and the
 *                Watch dog timeout.
 *
 ***************************************************/
void setup() {
  pinMode(INT_PIN,INPUT);
  pinMode(OUT_PIN,OUTPUT);
  pinMode(LED_PIN,OUTPUT);
  ADCSRA &= ~_BV(ADEN); // ADC off
  power_all_disable();
}

/***************************************************
 *  Name:        enterSleep
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Main application loop.
 *
 ***************************************************/
void loop() {
  digitalWrite(OUT_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  /*** Setup the WDT ***/
  wdt_reset();
  /* In order to change WDE or the prescaler, we need to
   * set WDCE (This will allow updates for 4 clock cycles).
   * WDTCR on ATTINY85 / WDTCSR on ATMEGA
   */
  WDTCR |= (1<<WDCE) | (1<<WDE);
  /* set new watchdog timeout prescaler value */
  WDTCR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */
  /* Enable the WD interrupt (note no reset). */
  WDTCR |= _BV(WDIE);
  // sleep for 8 seconds x 43200 = 96 hours = 4 days
  for (uint16_t i = 0; i < 43200; i++)
    enterSleep();
  wdt_reset();
  wdt_disable();
  GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
  PCMSK |= _BV(PCINT0); // Use PB0 as interrupt pin
  enterSleep();

  #if DEBUG
    digitalWrite(LED_PIN, HIGH);
  #else
    digitalWrite(OUT_PIN, HIGH);
  #endif
  enterSleep();
  PCMSK &= ~_BV(PCINT0); // Turn off PB0 as interrupt pin
}

I forgot something important: when measuring I wasn't using batteries as the power source, but an FTDI serial USB cable like this link, routing 5V to a breadboard where I put my multimeter. Was I measuring the consumption of the FTDI adapter too?

A sleeping ATTINY uses only microamps, so something else is pulling your power. You might want to enable the pull-up on the INT_PIN - floating pins can waste some power when they drift between high and low voltages. You also want to do power measurements carefully with nothing attached to circuit (like you ftdi). Power can easily flow both into and out of any pin on the chip and mess up your measurements.

@bigjosh as far as I know floating pins doesn't matter in powerdown sleepmode.

I'd remove the attiny from that board, and place it directly into a breadboard. Try and simplify thing, and disabling the watchdog timer for now. 1.28mAh; I assume that h at the end is just a typo. Are you sure your multimeter is accurate in this low range?

Why is it waking every 8 seconds when (according to the comments) you expect the the loop() function's for() loop to renew sleeps for 4 days before continuing?

@JRobert: AFAIK that's how the watchdog timer works, you can only sleep for up to 8 seconds. So if I want to sleep for more than 8 seconds I have to use this for loop.

@Gerben: I also suspected that board, thanks for your suggestions, I'll try them out. Also, good call on my multimeter, it's likely not very accurate as it was very cheap (the model is DT-830D). mAh should be mA ofcourse :)

@JRobert If an input pin has pin change interrupt enabled, the is the input buffers are not disabled during sleep. 10.2.5 Digital Input Enable and Sleep Modes As shown in Figure 10-2, the digital input signal can be clamped to ground at the input of the schmitt-trigger. The signal denoted SLEEP in the figure, is set by the MCU Sleep Controller in Power-down mode to avoid high power consumption if some input signals are left floating, or have an analog signal level close to VCC/2. SLEEP is overridden for port pins enabled as external interrupt pins.

@j'ordos: Yes, that is correct. My point is that the comments indicate your total for() loop should take 4 days, yet you're seeing activity every 8 seconds (once per WDT interrupt). If, as the comments indicate, every 8 sec is not what you expected to happen, that is the place I would be looking for a bug or a disconnect in my understanding. :)

Today I measured again without the development board. Just the CPU, same setup otherwise (original code, using the FTDI cable as power source) and I got a reading of about 6-8µA. I guess that answers it! Thanks everyone for your help!

Since you have answered your own question in a positive way, you should accept your own answer. :)


text:
Is there any way to check with Arduino UNO if a sensor is connected and ready to be read?
I would like to check the status of the sensors with Arduino UNO. For example, when I turn on the robot, I would like to check if all the sensors are connected and ready to be read or not. Maybe one sensor is unplugged and I want to detect this situation.
I read something about pull up resistors, but I didn't find any clear example of my problem. Also, I don't have any idea how to connect the resistor, how to calculate the resistor needed, as well as how to use the pull up resistor for digital and analog sensors.
Any schema, explanations and example would be very helpful!

Depends what kind of sensor. There is a a plain analogue pin connection, digital connection via spi or i2c....
Be a bit more specific.

the i2c scan sketch comes to mind, at least for that bus. you don't have to run it as a whole sketch; the code within shows how to iterate the devices on the bus, which can be called from a startup routine or whatnot...

Basically pull-up resistor pulls up the line, when nobody/nothing is doing otherwise (for example wire unconnected, or connected to INPUT, or to I2C bus, which is not doing something right now ...). If some device (or Arduino) sets the wire to LOW (0V, GND, ground), the it overrules the resistor and the wire is LOW.
So the value of the resistor must be high enought to anable any attached device to draw the wire LOW. So if you know, how much of current can a device sink and what is considered LOW value on input, then you can compute the minimal value of the resistor from Ohm law (and the Vcc, where the resistor is connected). If you do not want calculate anything, just put 10KOhm between the wire and Vcc and it would probabelly work just fine.

About detecting sensor - you have to know, what sensor and where is supposed to be attached (as you construct the robot). So you just send any command to the sensor (probabelly to read a value) and see, if you get answer and the answer make a sense (eg. temperature is like 0-100 Celcius, or so). If it works OK, then the sensor is connected and can be used, otherwise you should stop the robot, light big red light and wait for user to repair what is broken. Thing also about the type of sensor, if it needs some time to "boot up" and it it needs some time to "seatle the value and answer" to provide that time before testing (like with delay()).

The pull-up resistors fits there in the way, that they are connected to Arduino, so if there is no connection to sensor, then the unconnected pin is not "floating" (and possibly return any random or not random value), but is weakly drawn up ti HIGH, so if the connetor is broken/unattached, then all reads are just plain HIGH, no communication from sensor (or any noise to be messing with the detection). So you can detect "no answer" status and after a while (when sensor really, really should answer, but did not) flash that big red light.


text:
Why is SD card failing to begin?
I recently bought a micro SD storage shield for my arduino project, this is the link. My final goal is to log information every 100 ms about the temperature and pressure of my device using another one of my sensors. However, I started by testing out the SD card through the SdInfo class that comes as an example with the SdFat library. This is the outcome (through the Serial monitor):
SdFat version: 20160719

Assuming the SD is the only SPI device.
Edit DISABLE_CHIP_SELECT to disable another device.

Assuming the SD chip select pin is: 10
Edit SD_CHIP_SELECT to change the SD chip select pin.

type any character to start

init time: 748 ms

Card type: SDHC

Manufacturer ID: 0X28
OEM ID: BE
Product: 68BHO
Version: 0.8
Serial number: 0XD50B3A66
Manufacturing date: 11/2010

cardSize: 32026.66 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true
OCR: 0XC0FF8000

SD Partition Table
part,boot,type,start,length
1,0X0,0XC,8192,62543872
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0

Volume is FAT32
blocksPerCluster: 64
clusterCount: 976992
freeClusters: 976905
freeSpace: 32011.22 MB (MB = 1,000,000 bytes)
fatStartBlock: 9310
fatCount: 2
blocksPerFat: 7633
rootDirStart: 2
dataStartBlock: 24576

type any character to start

cardBegin failed
SD errorCode: 0XA
SD errorData: 0X5

This is the code of the class SdInfo:
/*
 * This program attempts to initialize an SD card and analyze its structure.
 */
#include <SPI.h>
#include "SdFat.h"
/*
 * SD chip select pin.  Common values are:
 *
 * Arduino Ethernet shield, pin 4.
 * SparkFun SD shield, pin 8.
 * Adafruit SD shields and modules, pin 10.
 * Default SD chip select is the SPI SS pin.
 */
const uint8_t SD_CHIP_SELECT = SS;
/*
 * Set DISABLE_CHIP_SELECT to disable a second SPI device.
 * For example, with the Ethernet shield, set DISABLE_CHIP_SELECT
 * to 10 to disable the Ethernet controller.
 */
const int8_t DISABLE_CHIP_SELECT = -1;
SdFat sd;

// serial output steam
ArduinoOutStream cout(Serial);

// global for card size
uint32_t cardSize;

// global for card erase size
uint32_t eraseSize;
//------------------------------------------------------------------------------
// store error strings in flash
#define sdErrorMsg(msg) sdErrorMsg_F(F(msg));
void sdErrorMsg_F(const __FlashStringHelper* str) {
  cout << str << endl;
  if (sd.card()->errorCode()) {
    cout << F("SD errorCode: ");
    cout << hex << int(sd.card()->errorCode()) << endl;
    cout << F("SD errorData: ");
    cout << int(sd.card()->errorData()) << dec << endl;
  }
}
//------------------------------------------------------------------------------
uint8_t cidDmp() {
  cid_t cid;
  if (!sd.card()->readCID(&cid)) {
    sdErrorMsg("readCID failed");
    return false;
  }
  cout << F("\nManufacturer ID: ");
  cout << hex << int(cid.mid) << dec << endl;
  cout << F("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl;
  cout << F("Product: ");
  for (uint8_t i = 0; i < 5; i++) {
    cout << cid.pnm[i];
  }
  cout << F("\nVersion: ");
  cout << int(cid.prv_n) << '.' << int(cid.prv_m) << endl;
  cout << F("Serial number: ") << hex << cid.psn << dec << endl;
  cout << F("Manufacturing date: ");
  cout << int(cid.mdt_month) << '/';
  cout << (2000 + cid.mdt_year_low + 10 * cid.mdt_year_high) << endl;
  cout << endl;
  return true;
}
//------------------------------------------------------------------------------
uint8_t csdDmp() {
  csd_t csd;
  uint8_t eraseSingleBlock;
  if (!sd.card()->readCSD(&csd)) {
    sdErrorMsg("readCSD failed");
    return false;
  }
  if (csd.v1.csd_ver == 0) {
    eraseSingleBlock = csd.v1.erase_blk_en;
    eraseSize = (csd.v1.sector_size_high << 1) | csd.v1.sector_size_low;
  } else if (csd.v2.csd_ver == 1) {
    eraseSingleBlock = csd.v2.erase_blk_en;
    eraseSize = (csd.v2.sector_size_high << 1) | csd.v2.sector_size_low;
  } else {
    cout << F("csd version error\n");
    return false;
  }
  eraseSize++;
  cout << F("cardSize: ") << 0.000512*cardSize;
  cout << F(" MB (MB = 1,000,000 bytes)\n");

  cout << F("flashEraseSize: ") << int(eraseSize) << F(" blocks\n");
  cout << F("eraseSingleBlock: ");
  if (eraseSingleBlock) {
    cout << F("true\n");
  } else {
    cout << F("false\n");
  }
  return true;
}
//------------------------------------------------------------------------------
// print partition table
uint8_t partDmp() {
  cache_t *p = sd.vol()->cacheClear();
  if (!p) {
    sdErrorMsg("cacheClear failed");
    return false;
  }
  if (!sd.card()->readBlock(0, p->data)) {
    sdErrorMsg("read MBR failed");
    return false;
  }
  for (uint8_t ip = 1; ip < 5; ip++) {
    part_t *pt = &p->mbr.part[ip - 1];
    if ((pt->boot & 0X7F) != 0 || pt->firstSector > cardSize) {
      cout << F("\nNo MBR. Assuming Super Floppy format.\n");
      return true;
    }
  }
  cout << F("\nSD Partition Table\n");
  cout << F("part,boot,type,start,length\n");
  for (uint8_t ip = 1; ip < 5; ip++) {
    part_t *pt = &p->mbr.part[ip - 1];
    cout << int(ip) << ',' << hex << int(pt->boot) << ',' << int(pt->type);
    cout << dec << ',' << pt->firstSector <<',' << pt->totalSectors << endl;
  }
  return true;
}
//------------------------------------------------------------------------------
void volDmp() {
  cout << F("\nVolume is FAT") << int(sd.vol()->fatType()) << endl;
  cout << F("blocksPerCluster: ") << int(sd.vol()->blocksPerCluster()) << endl;
  cout << F("clusterCount: ") << sd.vol()->clusterCount() << endl;
  cout << F("freeClusters: ");
  uint32_t volFree = sd.vol()->freeClusterCount();
  cout <<  volFree << endl;
  float fs = 0.000512*volFree*sd.vol()->blocksPerCluster();
  cout << F("freeSpace: ") << fs << F(" MB (MB = 1,000,000 bytes)\n");
  cout << F("fatStartBlock: ") << sd.vol()->fatStartBlock() << endl;
  cout << F("fatCount: ") << int(sd.vol()->fatCount()) << endl;
  cout << F("blocksPerFat: ") << sd.vol()->blocksPerFat() << endl;
  cout << F("rootDirStart: ") << sd.vol()->rootDirStart() << endl;
  cout << F("dataStartBlock: ") << sd.vol()->dataStartBlock() << endl;
  if (sd.vol()->dataStartBlock() % eraseSize) {
    cout << F("Data area is not aligned on flash erase boundaries!\n");
    cout << F("Download and use formatter from www.sdcard.org!\n");
  }
}
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);

  // Wait for USB Serial
  while (!Serial) {
    SysCall::yield();
  }

  // use uppercase in hex and use 0X base prefix
  cout << uppercase << showbase << endl;

  // F stores strings in flash to save RAM
  cout << F("SdFat version: ") << SD_FAT_VERSION << endl;
  if (DISABLE_CHIP_SELECT < 0) {
    cout << F(
           "\nAssuming the SD is the only SPI device.\n"
           "Edit DISABLE_CHIP_SELECT to disable another device.\n");
  } else {
    cout << F("\nDisabling SPI device on pin ");
    cout << int(DISABLE_CHIP_SELECT) << endl;
    pinMode(DISABLE_CHIP_SELECT, OUTPUT);
    digitalWrite(DISABLE_CHIP_SELECT, HIGH);
  }
  cout << F("\nAssuming the SD chip select pin is: ") <<int(SD_CHIP_SELECT);
  cout << F("\nEdit SD_CHIP_SELECT to change the SD chip select pin.\n");
}
//------------------------------------------------------------------------------
void loop() {
  // Read any existing Serial data.
  do {
    delay(10);
  } while (Serial.available() && Serial.read() >= 0);

  // F stores strings in flash to save RAM
  cout << F("\ntype any character to start\n");
  while (!Serial.available()) {
    SysCall::yield();
  }

  uint32_t t = millis();
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.cardBegin(SD_CHIP_SELECT, SPI_HALF_SPEED)) {
    sdErrorMsg("\ncardBegin failed");
    return;
  }
  t = millis() - t;

  cardSize = sd.card()->cardSize();
  if (cardSize == 0) {
    sdErrorMsg("cardSize failed");
    return;
  }
  cout << F("\ninit time: ") << t << " ms" << endl;
  cout << F("\nCard type: ");
  switch (sd.card()->type()) {
  case SD_CARD_TYPE_SD1:
    cout << F("SD1\n");
    break;

  case SD_CARD_TYPE_SD2:
    cout << F("SD2\n");
    break;

  case SD_CARD_TYPE_SDHC:
    if (cardSize < 70000000) {
      cout << F("SDHC\n");
    } else {
      cout << F("SDXC\n");
    }
    break;

  default:
    cout << F("Unknown\n");
  }
  if (!cidDmp()) {
    return;
  }
  if (!csdDmp()) {
    return;
  }
  uint32_t ocr;
  if (!sd.card()->readOCR(&ocr)) {
    sdErrorMsg("\nreadOCR failed");
    return;
  }
  cout << F("OCR: ") << hex << ocr << dec << endl;
  if (!partDmp()) {
    return;
  }
  if (!sd.fsBegin()) {
    sdErrorMsg("\nFile System initialization failed.\n");
    return;
  }
  volDmp();
}

I have noticed that the SD card is detected only upon start up, after that it all goes to errors. I had the same situation using the default SdInfo class from the built-in Arduino examples, sometimes it would register the card, sometimes it wouldn't. Why does this happen and how can I ensure it always reads the card?
I have already read this question and ensured my wiring is proper and I have also formatted my card using the software and SdCard.org, it is a Fat32 format.
This is my setup:

and

That's not the code that prints those messages.

@slash-dev my mistake, updated the post

A guess, so this is only a comment, not an answer:  When formatting an SDCard, recent versions of Windows stopped putting partition information onto SDCards.  You can override this weird behavior if you want.  Missing partition information might cause some SDCard drivers to fail.  Just something to think about.

SdInfo is an example, but I hope you know there's no reason to call sd.begin  to re-initialize the SD library.  The example is really intended to scan several different cards, not the same card.
sd.begin is normally something you would do once, in setup, even if something else is using SPI (e.g., Ethernet).  You probably won't get this error in your "real" sketch.
But to answer your question:
I see that your card takes a long time to initialize (almost a full second).  The error code says that the card does not re-initialize within 2 seconds.  I had a similar problem, and the solution was to edit the SD library and slow down how quickly it asked the card, "Are you initialized yet?"
Error code 0x0A is SD_CARD_ERROR_ACMD41, so perhaps you can use the same technique in this loop, line 171 of SdSpiCard.cpp:
  // initialize card and send host supports SDHC if SD2
  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;

  while (cardAcmd(ACMD41, arg) != R1_READY_STATE) {
    // check for timeout
    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
      error(SD_CARD_ERROR_ACMD41);
      goto fail;
    }
    delay( 150 ); // <-- wait a little
  }

Update
There is a related question and answer here.  Calling sd.begin twice is actually an open issue in the library.

I only initialize the card once at "sd.cardBegin(SD_CHIP_SELECT, SPI_HALF_SPEED)", and in your code, what does cardAcmd() method mean?

loop gets called over and over. It pauses to wait for a character, then continues.  When it gets to the end of the test, it returns.  Then loop gets called again. That's why its called "loop".

Ah okay, so everytime I run the loop (aka. every time I type a character), it is trying to initialize a card that has already been initialized. I don't really want to copy paste your code, since I don't understand what the cardAcmd() method does and why you have arg variable. However, wouldn't a good alternative be just initializing the card during setup?

Hmm... I might have suggested that in the first two paragraphs. :D  No need to modify the SdFat library! Be sure to press that green triangle (Accept) if that works for you.


text:
How to get each byte in byte array out and be able to work with them on their own?
I am currently sending data via my bluetooth and to it I send with me 4 different values looking like this:
byte[] myByte = {"HelloOne", "HelloTwo", "HelloThree", "HelloFour"};
WriteAsync(myByte);

And now I am looking for a way to store all these Hello's in different values.
What I have started with is something like this:
if (Bluetooth.available())
{
 while (true)
 {
   delay (50);
   char c = Bluetooth.read();
   readString += c;

   if (readString.length() >0) {

    if (readString[0] == "HelloOne")
    {
       Serial.println ("Hello One has been sent!");
    }

    if (readString[1] == "HelloTwo")
    {
       Serial.println ("Hello Two has been sent!");
    }

    if (readString[2] == "HelloThree")
    {
       Serial.println ("Hello Three has been sent!");
    }

    if (readString[3] == "HelloFour")
    {
       Serial.println ("Hello Four has been sent!");
    }

   }

 }

}

And I have not actually been able to debugg (not currently at home but eager to get to fix this problem asap) so there is a slim chance that my current code might be working? Very unlikely though.
So my question is, what is the correct way to get each value out in a byte array that is being sent with bluetooth to arduino?

No, not a chance of that working, I am afraid. FOr a start you need a 2D array not a 1D array, since you can only store 1 byte in a byte variable, and you want to store 4 groups of multiple bytes. You should read up on using C strings. https://en.wikibooks.org/wiki/C_Programming/Strings

Ok will take a look at that and see if i understand! I am a bit new to c++ as you can probably tell :) Thanks a lot for the link

Is it possible to do a solution to chop up the byte[]? Because I know how much chars that each byte in the array contains.

Sorry if this sound patronising, its not meant to, I'm just trying to cover all aspects.
byte[] myByte = {"HelloOne", "HelloTwo", "HelloThree", "HelloFour"};
WriteAsync(myByte);

You are assigning 4 strings to the array mByte.  A string (lets ignore the Arduino type string for now) is a char* or a char[], so:
char hello1[] = "HelloOne";
char hello2[] = "HelloTwo";
char hello3[] = "HelloThree";
char hello4[] = "HelloFour";

(You don't need to do this in the code, how you have done it is fine, it just shows what you are really saying)
In English mByte should be an array of strings which in code is
char* mByte[] = {"HelloOne", "HelloTwo", "HelloThree", "HelloFour"};

You could do it as
char mByte[][] = {"HelloOne", "HelloTwo", "HelloThree", "HelloFour"};//ERROR

But this won't compile, because the inner array (the text) is different length and the compiler doesn't like that.
Assuming that writeAsync takes a byte as a parameter then the code to write the data becomes this:
for (int stringCounter = 0; stringCounter < 4; ++stringCounter)
{
    // get a pointer to the first element of the string
    // & means get the address (so the value can be set to a pointer)
    // (byte*) means cast (change) the value into a byte pointer.
    byte* currentLetter = (byte*)(&mByte[stringCounter][0];)
    // currentLetter != NULL means the pointer is not equal to NULL, because looking at a null pointer will crash the code.
    // *currentLetter != NULL means the thing pointed to by currentLetter is not the end of the string.
    while (currentLength != NULL || *currentLength != NULL)
    {
        // Write the thing pointed to by the pointer to the function.
        writeAsych(*currentLetter);
        currentLetter++;  // Move on the pointer
    }
}

Sorry I can't compile that at the moment, but it looks about write.  I hope it helps you understand it.

Hey thanks a lot for the answer, Matt! Will take a look in a few hours :) Thanks

To much stuff to take care off today. Trying it tomorrow


text:
Following on ESP8266 Board pins, how do they map on the motor shield?
Here is the answer: All pins corresponding to the G row are connected to ground. All Pins corresponding to the V row are connected to NodeMCU's 3V3 pin.
D row pins tagged from 0 to 8 correspond to NodeMCU's D1-D8 pins. D row pins tagged with SD2, SD3 corresponds to NodeMCU's SD2, SD3 pin
UTART/SPI section:
Tags corresponding to the pins are self explanatory.
Near the white-colored power switch we have a pin called "AD". I couldn't figure how this motor shield's "AD" pin is interfaced to NodeMCU. Do you have any idea?
Following on Basic Question - ESP8266 Board Pins, I can't seem to map the pins on its motor shield to software (the ones named UART/SPI, the GPIOs and the Analog Inputs). See the third image, with a NodeMCU installed.

The GPIOs seem to conflict with the motors on Arduino, and I have no idea what to do here. Documentation is pretty much useless.

This question is about a ESP8266 and this is the Arduino SE forum, you might try the Electronics SE forum, there are more ESP8266 users over there so you will get a better/quicker answer.  Personally I would buzz them back to the socket for the NodeMCU and then use them from there

Hello @Matt , thanks for the answer, but the question is actually about the code, and how to map the code to the physical pins, that's why I posted it here. Sorry if it was the wrong place!

Which forum it should be depends if you are programing the ESP via the Arduino IDE or in LUA.  The same still hold true though, you need to know what pins the software needs to address, so you need to find out what pins on the board connect to your ESP.  Then you just need to use the correct constant.  So if GPIO_0  (Yellow box) connects to D0 on your breakout board then your code needs to refer to GPIO-16, Obs :)
Have you seen this before?https://pradeepsinghblog.files.wordpress.com/2016/04/nodemcu_pins.png?w=616

BTW Majenko is saying the same thing, hint hint.

You see the pins marked PWMA, PWMB, DA and DB? Those are the pins that control the motors (PWMx is the speed, Dx is the direction). Whatever pins on your ESP8266 board plug into those holes are the pins you need to use in your code. How those pins map to names and numbers in the Arduino API depends entirely on what the board is you're plugging in and what the author of the board definition files was thinking at the time.
In short, look at your board (which we cannot see) and see what GPIO pins are in the same location as the pins I pointed out. Then control those pins in your software.

thanks for your answer. As specified on the question, the board is a ESP8266, the NodeMCU. Actually, I was asking about the pins marked as SD2, SD3, and 0 to 8, with rows marked D, G and V. The ones that control the motors I managed to use.

@AlexandreStrube Then read the manual for the NodeMCU? That will tell you which pins on the ESP8266 module those pins (which are clearly labelled the same on the NodeMCU) are connected to.

@AlexandreStrube - You should have SD0 to SD3 on your NodeMCU (On the analog pin side) - They are normally controlled in the software by SDD0 to SDD3.  The 0 to 8 pins, well you have pins marked D0 to D8 and I am going to guess the on your motor shield they are connected to 0D to 8D, in software they are controlled by GPIO1 to GPIO16 - see the link in my comment above.  You can prove this by writing an app the lights an LED and toggling each of the pins high in sequence, or you could use a multimeter and buzz it out.  Once you know the physical connections working out the s/w should be easy.


text:
Typedef Function Pointer Invoking Issue
I'm having an issue trying to use a normal non-member function of my main sketch file as a callback.  I can't get the function pointer to invoke from a function other than it was saved.  More info below;
MotorEncoder.h
typedef void (*cb)(int16_t,int16_t);
class MotorEncoder
  ...
  private:
    cb _motor_callback;

Program.ino
cb encoder_cb = NULL;
...
encoder_cb = function_that_accepts_2_int16
DC_Encoder_1.move(motor_pos, speed, motor_id, encoder_cb);

EDIT: I want to edit the description as to not confuse anyone.  The code with the callbacks above is all correct.  The issue was I was working with open-source software and another developer was setting the selected serial-port connection back to the bluetooth channel in-correctly.  The callback was executed, I was connected to the ATMega2560 via serial connection to a raspberry pi and was looking for the callback to show there, not monitoring bluetooth so I didn't see any data come across.  Document your code.

You need to post code, not describe it. Please read How do I ask a good question?. Please post a Minimal, Complete, and Verifiable example.

I can't get the function pointer to invoke from a function other than it was saved. - I don't understand that sentence.

I'll mock up a simple example when I have time later tonight / this week.  But just to try and explain when I say that I mean I can use the function pointer inside of the "move" function and see it being called in my Program.ino file.  I recieve the function pointer and can immediately use it to call back into Program.ino
Program.ino calls this call later inside of it's loop function, say to function: "Function1".  "Function1" checks some variable and if true then attempts the callback but I don't see any code execute back in my Program.ino file.

This answer contains a few debugging guidelines, as I don't know what the problem is and don't see how one could tell without a good deal more of information.
I suggest creating a Minimal, Complete, and Verifiable example (MCaVe) of your code, not just snippets, so that other people can compile and run the code, thus being able to observe what happens in more detail and perhaps with added debugging output.
I'm presuming your callback is triggered as a consequence of an interrupt occurring.  I suggest you write the MCaVe to depend on a pin-change interrupt, rather than a motor-controller interrupt, to allow testing on a system consisting of no more than an Arduino with a button, a serial interface, and perhaps a few LED indicators.  Pressing the button would change pin voltage and cause an interrupt; your ISR would turn on an LED to signal it handled the interrupt, then trigger the callback.  The callback routine would turn on another LED as its signal.  The main loop would read the pin register bits for the two LEDs, record and report the times they came on, and turn them off after a second or two.  If you get a simple setup like this to work, the technique probably would carry over to your motor-controller case; or if not, probably being a smaller program and setup should be easier to debug and figure out why not.

I'll give that a go, and post a simple example back here if I'm not successful.   I am using an interrupt but it simply sets a volatile variable.  The motor class is then called from the Program.ino loop function, checks the variables and should perform the callback if needed.
I was trying to fix a larger firmware system for a group of people.  I'll mock something up more simple first and see if the problem exists,

@BruceBannor, ok; and I'd recommend posting the simple example, successful or not, as it will allow others to look for problems or improvements. +1

I finally had some time today to look at everything again, and I wanted to provide anyone who stumbles on this an update.  I'm going to mark this as the accepted answer.  Quick context; I'm working on an open-source firmware for the MakeBlock MegaPi, fixing a bunch of the calls and api's that I found broken for others in the community.
Through some debugging and using the serial monitor I found where they were always setting the serial-port back to the bluetooth connection.  I'll edit my answer as I'll run out of characters here.  The advice here is great for any general issue though.


text:
Fan dropping voltage?
I have students using an arduino to control a fan.  We have multiple types of fans. We want to turn the fan off/on with digital HIGH.  When the 5V fan is plugged into 5V and ground, it runs.  When I ground it and attached the power side to a pin set to HIGH the voltage drops down to 2.2V??? When the fan is not plugged into the pin there is 5V.  Why would the power drop when the fan is plugged in?

Most digital pins on Arduinos are qualified to handle up to 25 mA typically and 40 mA at most.  If more current than that is drawn or sunk, the pin voltage will drop or rise, out of specification.  This is due to resistance in the pin drivers, and by Ohm's law, voltage equal to current times resistance will develop.  That “lost” power (voltage times current) is converted to heat within the microcontroller, and can damage it.
The fan motors probably draw rather more than 25 mA; they probably require a few hundred mA.  You can add transistors or motor controllers between the Arduinos and the fans to deal with such current loads.

Absolute Maximum Current per Pin is 40mA (in Arduino Uno) so when you connect the fan with the I/O pins at that time the fan may draw more current from the pin and because of this the voltage level of the pin may drop down. Because Fan or Motor want more current then the capacity of Arduino pins capacity so if you want to On/Start the Fan/Motor then you have to connect Fan/Motor Driver between the Arduino Pin and Fan/Motor. And you have to provide external power source to the motor driver circuit.
For your reference:


text:
UART communication issue on Arduino Mega
I am using an MH-Z19 CO2 sensor with an Arduino Mega using UART. As per the specifications of this sensor, after we send a command, we expect the response in a particular 9 byte format (with starting bytes as 0xFF and 0x86).
byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
byte response[9];
Serial.flush();
Serial.write(cmd,9);
while (Serial.available()<9) {}
for(int n=0; n<9; n++) {
  response[n] = Serial.read();
}
if (response[0] != 0xFF) {
  //Error
  predictCo2 = 0;
} else if (response[1] != 0x86) {
  //Error
  predictCo2 = 1;
} else {
  predictCo2=((response[2]*256)+response[3]);
}

I wait till all the 9 bytes are filled in to read the values.
The problem here is that, when I turn the board ON, most of the times the response isn't in the required format (starting bytes aren't 0xFF or 0x86).
But, if I press the Arduino reset button, it starts reading values in proper format straight away.
I'm wondering why this is happening. Why is the UART response not in the proper format immediately after I turn on the Arduino, and I have to explicitly do a reset? Is the reset button clearing the serial stream? How can this be achieved through software?
I included serial.flush() before sending the command, but that didn't help either.

Sounds like a startup delay needed. See https://revspace.nl/MHZ19#Log_of_MH-Z19_response_at_startup.

Serial.flush() only empties the output buffer, so that won't achieve anything. Reading exactly 9 bytes and hoping they match the input stream is not very effective, as you found. If you are out of sync with the incoming bytes, you will stay out of sync.
It would be better to keep reading (single bytes) until you get 0xFF or 0x86 and then read the rest.


text:
Arduino and GPS module Neo 6m
I have an Arduino Leonardo and a GPS module "NEO 6M"
Pinout:
PPS->free
rxd->11
txd->10
gnd->gnd
vcc->5v

I'm running this code:
#include "SoftwareSerial.h"
SoftwareSerial gps(10,11);
void setup(){
  Serial.begin(9600);
  gps.begin(9600);
}

void loop(){
  while (gps.available())
    Serial.write(gps.read());
}

In serial monitor I'm getting random characters like this

Where am I going wrong?
I tried the same with an Arduino Mega but have the same result.

Solved: GPS module was broken. Now I use another GPS module, same model. Sorry for my English.

How did you ascertain that the module was broken? Did you try it with a different GPS module and it then worked? Could you edit and expand your answer a little, as it could be useful for someone else who has the same issue...

i used another GPS module and resolve all my problem :) sorry for late response

authors: Cake_Seller Слава Україні


text:
Powering up LED strip - How many amps?
I want my Arduino to drive a LED strip.
The LED strip in particular is the 3528 non-waterproof type.
To power this up, I need a 12V power supply.
My LED strip is going to be 5 meters.
Now my questions are:

Is it important on how many amps, my powers supply will feed? One guy did it with 12V, 5A power supply. Considering the length (5m), is a particular amperage value necessary?
Can I power up the Arduino Nano with the power from the power supply? Voltage wise, I am clear, since the nano can handle 12 volts... What I am scared of is the amperage... Considering that I need a particular value of amps to power up my LED strip, can the nano handle this many amps? Is there a limit to how many amps the power supply line that I will feed my Arduino has to be?

Usually strips have not individual LEDs, but are composed of a lot of "pieces" in parallel, and each piece is composed by three leds in series along with a resistor.
Usually the strips are composed by 60 leds/m (i.e. pieces of 5cm), but sometimes also 120 leds/m or 30 leds/m. Let's assume it is the 60 leds/m version (you can check the length of the piece you can cut - which should be 5 cm - and that it contains 3 leds).
This means that in 5m there are 100 pieces. Now, usually the 3528 leds absorb 20mA of current for each segment (the 5050 version should be rated at 60). This means that the whole led strip should absorb 2A @ 12V.
Now the power supply. 2A is the nominal current the whole strips should absorb. Add about 200mA for the nano, and increase a bit the current requirement not to stress the power supply: you get a 12V 3A power supply at least (note that, while 12V should remain the same, you can take any current greater than this value - if for instance you have a 12V 5A power supply it is perfectly fine).
Now, the nano. It surely can't handle the 2A current. This means that you can power the arduino nano from the 12V. BUT beware: you should connect the 12V power to the VIN input (so the onboard regulator lowers it to 5V). Then you can't power the LEDs directly from the nano, but you need a transistor to decouple them. You can take any nMOS with a drain current greater than 3A or an NPN with collector current >3A and build the appropriate curcuit to drive them, then connect the + terminal of the strip to the +12V wire, the transistor source (or emitter) to the ground wire and the gate (base) should be driven by the nano.

Thank you so much! Out of ignorance, i didn't mention that these are UV LEDs for PCB production. So each led, has not three leds inside, that means even less power consumption! Something like this: http://www.ebay.com/itm/UV-Night-Fishing-Lights-Ultraviolet-LED-Blacklight-3528-5050-SMD-Boat-Strip-Lamp-/291998937499?var=&hash=item43fc7e319b:m:mM3H6Aq5GewFdtLfYOWNaDA

@user1584421 The 5050 version of LED has three leds inside each package, that  is why the 5050 is rated at 60mA and the 3528 at 20mA. If you look at the photos you will see that they are different. Usually the color does not matter a lot, since the limiting resistors are trimmed to get 20mA out of each segment. As you can also read from the description, the input should be "12V 2-3 A for 5meters 3528 300LED light strip", which is what I told you (2A is the minimum, but use a bigger one).

One more thing: when I built my bromograph they discouraged me from using LEDs, because tubes are more homogeneous. With 5m of LEDs you can glue them very close, so probably you will get a nice exposure also with leds, but try to glue them very close, make a "zig zag" pattern and place the PCB a bit far, so the light can spread evenly..

Thanks a lot! On a slightly unrelated note, given this setup, and with a 2.5A power supply, how much the exposure time you think should be for a PCB?

@user1584421 Probably you are asking the wrong person, because I was never able to obtain a truly good PCB this way ;) anyway I know that exposire time varies with a LOT of factors, including primarily the photosensitive film you are using, its "freshness", the developer concentration and type, even the climatic conditions (even if these should have a little impact). What I suggest is to make a "trial" piece, with some small traces and gaps, cover almost all the board and start it. Then after 10 seconds uncover the board some more, in order to have different exposures in the board. continue...

... for instance this page has the methodology I used (it's in italian, but there is a video and at about 10 minutes it shows how he used the template). Download the "Test bromografo 1" template and use it. Once you know the approximate (+/- 10s) time, well, that is your exposure time...

1) Is it important on how many amps, my powers supply will feed?

Yes.  You need the PSU to be able to supply as much current as you will need for everything you are powering form it.
You don't say how many LEDs will be on this strip (only the length of the strip) and I am not sure how much current/power a single one consumes, but for illustration let's imagine there are 100 LEDs on your strip and each one takes 0.8W.
100 LEDs x 0.8W per LED = 80W.
P = VI, where P=Power, V=voltage, I=current.
So I = P/V = 80 / 12 = 6.66A -- call it 7A.
The amount taken by the Nano will be small in comparison - if you said 0.5A you'd be safe.
So with these figures you'd need a 7.5A PSU.

Considering that i need a particular value of amps to power up my LED strip, can the nano handle this many amps?

You can power the Arduino from the same power supply, yes.  The Arduino will draw whatever current it needs.  (Think of it this way: mains sockets are 13A - a desk lamp won't draw 13A.)  What matters is that the supply can supply at least enough current, and that the voltage is correct.
As mentioned in the comments, you can't drive 3528s directly from the Nano - but you don't ask about that so presume you either know how to do it, or will ask another question.

Because there are three LEDs in series, you cannot drive these LEDs from a 5V supply. The LED strips say "+12V" on them to mark the anode and that's the maximum voltage we suggest. We've found that if you're ok with them being a little dimmer, even 9VDC works very well.
Each segment of 3 LEDs draws approximately 20 milliAmperes from a 12V supply, per string of LEDs. So for each segment, there is a maximum 20mA draw from the red LEDs, 20mA draw from the green and 20mA from the blue. If you have the LED strip on full white (all LEDs lit) that would be 60mA per segment.
To find the total maximum current draw per meter, we would multiply 60mA x 10 (ten segments per meter for the 30/LED per meter strip) = 0.6 Amps per meter OR 60mA x 20 (twenty segments per meter for the 60/LED per meter strip) = 1.2 Amps per meter. Again, that's assuming you would have all the LEDs on at once and that you are powering it from 12V. If you're going to be PWM-fading between colors, maybe 1/2 of that is what you'll be drawing. Still, you do need to have a fairly decent power supply to run this strip, all those LEDs add up!


text:
max7219 chained display showing mirrored text
I'm using a max7219 like this one max7219. When I first tested my circuit, I used an 8x8 display and the code worked just fine. Now, after I modified the code with the one that can be found online at arduino code and changed the display with the chained one, the text appears to be mirrored on the matrix display.
.
Below, I'll attach part of the code. Please help me find the problem.
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// Define the number of devices we have in the chain and the hardware interface

#define MAX_DEVICES 4
#define CLK_PIN     13
#define DATA_PIN    11
#define CS_PIN      10

// Hardware SPI connection
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

void setup(void)
{
  P.begin();
  P.displayText("Hello", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}

void loop(void)
{
  P.displayAnimate();
}

Changing the incorrect line to #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
did the trick. It took time to find, but thanks a million!!!

In my case I had to change to #define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW

Since version 3.0 MD_MAX72xx.h no longer supports that definition. Now the hardware type is defined as a parameter on creation (in the "Example" file you are using - not in MD_MAX72xx.h)
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
...
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

Note that I've changed the hardware type from PAROLA_HW to FC_16.

Check the configuration in MD_MAX72xx.h file and ensure you have the right module selected.
For example there is a define
#define USE_PAROLA_HW   0

if your hardware is this item then turn off the other hardware settings and turn this one on so it reads as follows:
#define USE_PAROLA_HW   1

there many other settings if it is not there then you will have to experiment until you find the correct one.

In library, change #define USE_GENERIC_HW 0  to #define USE_GENERIC_HW 1 is the solution.

In latest version of #include <MD_Parola.h>, #include <MD_MAX72xx.h> you have to define the following and characters will display correctly.
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW

Isn't that what @Den1al said in their answer?

authors: عازفة الإحساس

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


text:
Analog output doesn't work for just 2 LEDs [Arduino Mega]
I am having a problem with an Arduino Mega 2560.
Everything works fine, the ultrasonic sensors work fine, and the other LEDs work fine. Although there is 2 LEDs who do not work right and when I do analogWrite(), they actually do digitalWrite(). I have tried to attach these two LEDs to a potentiometer (potentiometer works fine, values are tested) but it always does digitalWrite() not analogWrite().
I have tested the LEDs and potentiometer on an Arduino Uno in PWM pins and analog pin and yes it does work very well.
Please mind that these LEDs are attached to analog pins. Why is this? Because I do not have anymore PWM pins available to use and so I have to use analog pins. No way I can rearrange this.
Here is part of the code (only part otherwise it's too long, most of my pins are taken):
//Leds//

int led = A4;
int ledUV = A3;

//Potentiometer//

int potReading;
int potPin = A2;
int lightDim;

void setup(){

    Serial.begin(9600);

    pinMode(led, OUTPUT);
    pinMode(ledUV, OUTPUT);

    pinMode(potPin, INPUT);

}

void loop(){

    potReading = analogRead(potPin);
    lightDim = (255./1023.)*potReading;

    analogWrite(led, lightDim);
//  analogWrite(ledUV, lightDim);
//  Serial.println("pot: ");
//  Serial.println(potReading);
//  Serial.println(" ");
    Serial.println("dim: ");
    Serial.println(lightDim);
//  analogWrite(led, 255);
//  analogWrite(ledUV, 255);

}

< Why is this? "this" being what?

Reference: analogWrite()
The pins 2 - 13 and 44 - 46 are the PWM pins for analogWrite().
That means you have 15 PWM pins. Did you use them all?
You could add a module with more PWM outputs. Search for: Arduino 16 channel PWM
The Arduino Mega does not have analog outputs, only digital PWM outputs.

Thank you so much man it did work! I did not knew about 44-46!

Analog pins an only read analog values, not write them.
analogWrite() is a deceptive name. It should really be PWMWrite() since all it does is PWM. And that, of course, needs PWM pins.

This is a good answer too, but arduino uno analog pins have anolog output, as this procedure and code worked on a uno.

No they don't. There is no analog output on any atmega chips. Whatever you did before it certainly wasn't analog output.

Do you want me to post a video?

I'd love to see that, yes. As well as the code that is doing it.


text:
Flash an ESC Through Serial USB without Arduino Interrupting the Signal
So I have four Electronic Speed Controllers (ESC's), each connected to a motor. I am building a drone with an Arduino UNO board as my flight controller. For convenience, I have soldered the signal wires on each of the four ESC's onto the bottom of the Arduino where the Arduino's pin headers are soldered on. The serial ground pins on the ESC's are soldered to the ground pins on the Arduino.
The ESC's I am using can be found here.
In order to change settings on my ESC's, I am trying to use this Turnigy USB linker to connected to the BLHeli software on my computer.
The linker has a signal and a ground wire for Serial Communication, as well as a positive wire (I think this is just to fit the connector on ESC's with a BEC, but mine are OPTO, and have none). To connect the USB Linker to an ESC, I should be able to plug it into appropriate female pin headers on the Arduino using some breadboard-type jumper cables.
At least that's what I thought...
Whenever I try to connect to an ESC with the BLHeli software, I get a message:
Please Connect ESC and power up or cycle power.
Earlier, I was able to make the connection and change the settings on my ESC's when they weren't connected to the Arduino board, but now that they are soldered and hot-glued on there, they won't work. So the question is: What is the Arduino doing to the Serial connection, and how can I fix it without desoldering my ESC's whenever I need to change some settings?
Now before you ask:

Yes, the ESC is powered up and connected to a motor. It gives me a happy beeping sound.
Yes, I definitely have the signal and ground wires connected correctly. I have been trying to figure this out for days, and have even tried switching them.
The Arduino is turned off when I try to connect an ESC to the USB Linker.
Only one ESC is powered on at a time.

Maybe the Arduino has some kind of protection circuit for the IC that is messing up the signal, or maybe the ESC's have something similar that's messing it up too, because some of the ground wires are connected together. I'm going to have a very difficult time figuring this out myself, so hopefully someone out there has an idea of what's going on.
Thanks for any help you have to offer.
-- Ember

Hey,
Russell, already gave some good advice. I just want to add that, as far as I understand you are able to control the ESC from your Arduino, so why make your life more complicated with this programmer thing. I got some of ESC's from Robbe and didn't want to buy a programmer.
You can quickly write a program that allows you to program the ESC with your Arduino. For example a short program with severals commands you write serially. That gives you also much more control over your thing, what can be useful when testing.

That would be nice, but I couldn't find any information on what type of commands to send the esc through serial. I might be able to write a program that mimics programming the esc through the transmitter, but that seems like a lot of work. I think what I'll do is order some jst xh 2-pin connectors and solder those to the arduino and the esc. That way I can take it all apart and program the esc's whenever I need to.

It's really not look here: https://hobbyking.com/media/file/708075066X189350X31.pdf
Go to "program example" there is exactly written how it's done. You only need commands for top and bottom position, I guess you have that already, otherwise how would you drive drone ;) But it's on you..good luck what ever you try :D

As far as I can tell, it is not possible to program a Turnigy Multistar ESC while it is connected in parallel to any pins on an Arduino. Whether the Arduino is off, or the pins are set to input, output, HIGH, or LOW, the signal is disrupted somehow.
Solution: Don't do what I did and solder the ESC's to your Arduino unless you want to de-solder them to change settings. Sticking some wires into the Arduino's pin headers will not make a strong connection, so I would recommend soldering some sort of strong JST connectors to the pins on the Arduino.
Hope this all helped, and good luck,
-- Ember

I can offer general advice without reference to specific implementations.
By driving the Arduino pins when it is powered off you are potentially exceeding it's maximum rated specifications for voltage on any ping, and possibly for current into a pin, and you risk damaging it.
When the Arduino is powered down its Vdd pin and power supply rail will be at about 0.0 volts and will be loaded to ground by power supply capacitors and various other items connected to Vdd - including the OUTPUT of the Vdd voltage regulator in many cases.
Each Arduino pin is connected to the Vdd rail by a body / protection diode. To drive the pin high you must also raise Vdd to high-1 diode drop and must drive the Vdd rail load from your signal line via the body diode.
If your programmer has the ability to do this there is a reasonable chance that you may damage the body diode. For extra points, a very capable signal input MIGHT damage the Arduino's voltage regulator and possibly other on board devices - but I'd think that to be unlikely.
The technically best solution is to disconnect the Arduino's relevant pins when programming. As you obviously would rather not do that, then ...
Probable solution: If you power on the Arduino and run a program which ensures that the relevant pins are set to input mode then it should work as required. IF the Arduino default program sets the relevant pins to inputs then just powering it on should suffice, but odds are that the serial port pins are not both configured as inputs.
If the Arduino has a USB to serial port IC or other devices connected to the pins in question then you will need to also ensure that they do not load the pin excessively and that they will not be damaged by programming signals. eg if you were trying to drive the Arduinos serial RX_in pin which was connected to the TX_out pin of a USB-Serial IC then the programmer would be attempting to drive the USB-serial output pin and this must be dealt with in some way.
Checklist:

Is there something else connected to this pin.

If so

What state is it in during ESC programming
Will it be damaged by programming
Will it affect programming.
What action is thus needed.

Thanks for the reply! I uploaded code to my arduino that did nothing except set the esc pins to inputs. This seemed to do something, because I got some weird beeping coming from the esc when I tried to connect. The esc still can't connect though...


text:
ESP8266 as WiFi monitor
I'm about to buy two ESP8266 modules. I want them to use as an auto deauth device. The first module will monitor my WiFi router's packet transmission. If a certain device receive loads of packets from my router (which hogs my network) the second module will deauth that device or flood "forged" packets. There will be a threshold so a simple web browsing will not trigger the deauth process from the second module. Btw. My router doesn't support traffic shaping & QoS. Only a different kind of QoS (DHCP & IPP/TOS) which is useless because my ISP doesn't support it.

So to disable a device that hogs your connection, you start flooding the connection to that device? That doesn't really sound like the way to go.

You may try to flash openWRT on a router and/or make a second access point for guests that has max up/down.

@Paul It's an ADSL/WiFi router combo. It's a new-ish hardware but every custom firmware are not available for this device but the other version (without ADSL) is supported.

You're going to face significant challenges with this.
The ESP Arduino API doesn't let you run in promiscuous mode (which you'd need in order to see other people's traffic), and the APIs are all set up for you to create nice well-behaved traffic, not spoofed packets.
I strongly suspect the hardware can do it, but you're going to be making significant changes to the IP stack.  The code is all open, so you're free to dig in and see what you can do (I've done a similar thing myself, as I needed some lower-level information than was made available in the API).
So feasibility is determine by your skill level (C, C++ and IP stack and protocols) and available time.
Something like a Raspberry Pi Zero and a suitable USB wifi dongle would probably be a quicker path at similar cost, as there are Linux tools to do a lot of this stuff.


text:
5V power supply negative terminal connection
I am currently developing some basic led board using Arduino Uno R3. Basically,
the LEDs are connected in parallel so that 5V DC supply can light up about 3 LED. Each LED has its resistor and its connected to 3 Arduino digital pin where I ground it by using digitalWrite(pins, LOW). Each ground on the schematic is the Arduino digitalWrite(LOW). My question is where should the negative of the 5V should be connected?
Also, if I wanted to measure the voltage of the LED, where should I connect my probe so that analogRead() can read the voltage?
Thanks and sorry if my explanation is not correct since it's my first time using this site.

simulate this circuit – Schematic created using CircuitLab

The Arduino common, normally referred to as ground, although it is usually only accidentally grounded through external connection. In general ALL connections should have a common "ground".
You can not measure voltage across the LED given the circuit you have listed. (You could read the voltage at both ends and subtract.)
If you swap the LED and resistor you can get an approximation of the LED voltage (actually LED + Arduino pin) from the junction of LED and resistor.

Thank you. What if I have a dual power supply 5V and 12V, lets say D3 needs 12V to work, and the others need 5V to work, should both the power supply's negative port be connected to Arduino GND as well?

@Jason Your comment is imprecise. All electrical circuits need some reference connection. If it is a "dual power supply" it presumable has a common. If you have 2 independent power supplies they both need a reference connection - this is conventionally 0V, but any reference is acceptable. If you really intend using 12V, you should rethink your circuit, and NOT connect directly to the Arduino. I really don't see why you would want 1, let alone 2, external supplies to switch a few LEDS. The Arduino can only switch 40mA max (20mA recommended) without extra circuitry.

@Milliways, the  “it is usually only accidentally grounded through external connection” part seems false.

@jwpat7 If you power with most switch-mode power supplies (such as the plug packs used as phone chargers)  which are double insulated, the Arduino will be floating WRT ground, unless you connect to a grounded device.


text:
Stepper motor is not working according to code
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 480  //2048
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
int Steps2Take;
int dirpin=8;
int steppin=9;
int buttonApin=2;
int buttonBpin=3;

void setup() {
  pinMode(dirpin,OUTPUT);
  pinMode(steppin,OUTPUT);
  pinMode(buttonApin,INPUT);
  pinMode(buttonBpin,INPUT);
}

void loop() {
  int valA=digitalRead(buttonApin);
  int valB=digitalRead(buttonBpin);
  if(valA==HIGH) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(40000);
    delay(1000);
  }
  if(valB==HIGH) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(-40000);
    delay(1000);
  }
  if((valA==LOW)&&(valB==LOW)) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(0);
  }
}

Here I have written this code to rotate stepper motor. When the input on digital pin 2 becomes high, then the motor should rotate clockwise. When the digital pin 3 becomes high, it should rotate in a different direction. When the input on both pins is low, the motor should not move.
But with this code the motor is moving continuously even if you apply high input to digital pins.
Please suggest how to fix this problem. For input signal I am taking signal from relays: if relay is in on condition, it should give a high signal and vice versa.

I think its better to use count function .. you need to test yor stepepr motor first ..here the code to test .. i hope its will help :)
#define IN1  50
#define IN2  51
#define IN3  52
#define IN4  53
int Steps = 4096; //4096(full rotation 360 degree )
int cstep = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

 Serial.println("Enter character for control option:");
 Serial.println("h : anticlockwise");
 Serial.println("i : clockwise");
 }

 void loop()
{

   if (Serial.available()>0)
   switch(Serial.read())
 {
   case 'h':
   Serial.println("anticlockwise");
   for(int x=0;x<Steps;x++)
{

     step1();
     delayMicroseconds(1000);
}
  break;

   case 'i':
   Serial.println("clockwise");
     for(int x=0;x<Steps;x++)
   {

       step2();
       delayMicroseconds(900);
   }

   //delay(1000);
    break;

  }

  }

   void step1()
  {
    //stepp
    switch(cstep)
 {
   case 0:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, HIGH);
 break;
 case 1:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, HIGH);
 break;
 case 2:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, LOW);
 break;
 case 3:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, HIGH);
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, LOW);
 break;
 case 4:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, HIGH);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 break;
 case 5:
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, HIGH);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 break;
 case 6:
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 break;
 case 7:
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, HIGH);
 break;
 default:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 break;
 }

 cstep=cstep+1;
 if(cstep==8)
  {cstep=0;}
 }

  void step2()
{
//stepp
switch(cstep)
{
 case 0:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, HIGH);
 break;
 case 1:
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, HIGH);
 break;
 case 2:
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 break;
 case 3:
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, HIGH);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 break;
 case 4:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, HIGH);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 break;
 case 5:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, HIGH);
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, LOW);
 break;
 case 6:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, LOW);
 break;
 case 7:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, HIGH);
 break;
 default:
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 break;

 }

  cstep=cstep+1;
 if(cstep==8)
 {
  cstep=0;
  //Serial.println("habis");

  }
 }

Please, expand your answer to explain what your doing and why. Teach the man how to fish.

copy the code that i was give .. change the pin of stepper motor to your own pin .. then upload to the arduino board and see waht happend at serial monitor

Disclaimer: I've never used this library.  The following is my thoughts from looking at the code.
This example seems to do basically what you want.  It doesn't seem to be necessary to do any digitalWrites yourself - you just need to call call .step(x).
There also doesn't seem to be any need to anything in the "do nothing" case - you don't need to tell it not to step, as far as I can see.
I couldn't work out why you were stepping 40000 steps at a time.  I've changed it to 1.  You can change it back if I missed something.
Also note I've used else if so that if both inputs are high, the motor doesn't go forward AND backwards.  Maybe that's the behaviour you want, and if not, again, you can change it.
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
int buttonApin=2;
int buttonBpin=3;

void setup()
{
    pinMode(buttonApin,INPUT);
    pinMode(buttonBpin,INPUT);
}

void loop()
{
    int valA=digitalRead(buttonApin);
    int valB=digitalRead(buttonBpin);
    if(valA==HIGH)
    {
        small_stepper.step(1);
        delay(1000);
    }
    else if(valB==HIGH)
    {
        small_stepper.step(-1);
        delay(1000);
    }
}

Does the relay actually connect the pin to ground when it is off?  Or does it leave the input floating?  If it leaves it floating then you should use a pull-down resistor to make sure the pin actually sees ground and not stray interference.
If you can rewire the relays you can use an active low configuration and save the resistor since the Arduino has built-in pullup resistors.


text:
Disable SCK temporarily to save power
for logging of environmental data, I am using a MicroSD card adapter (no brand name, eBay, China) and a 4GB Intenso SD card. I want to read data and write it to the SD card once every 10 minutes. Power consumption needs to be as low as possible.
Between the measurement points, I switch off the power supply to my sensor and SD card adapter using an NPN transistor (BC547B, 2N3904, 2SC945) and put my controller to sleep using jeelib. Everything works fine!
But I realized, that even during sleep, still 1mA of current is drawn. This disappears, when I remove the SCK connection between the Arduino and the SD controller. Doesn't sound like a lot, but for my purposes, it's a major concern (when SCK is removed, I'm around 6µA during sleep).
Is it possible to switch the SCK signal off during sleep to save that last bit of power?
In case it matters, I am using the SdFat library to write to SD. Initialization is done before each write. I figured, this would be necessary because of the poweroff of 10 minutes. Here's the function:
#include <SdFat.h>
const int chipSelect = 10;
String outfilename = "Bienen.log";

[...]
int writeToFile(String outfilename, String writestring) {

  SdFat SD;
  if (!SD.begin(chipSelect)) {
#ifdef DEBUG
    Serial.println("Card failed, or not present");
    error_signal();
#endif
  } else {
#ifdef DEBUG
    Serial.println("card initialized.");
#endif
  }

File outfile = SD.open(outfilename.c_str(), FILE_WRITE);
#ifdef DEBUG
  Serial.println(outfile);
#endif
  if (outfile) {
    outfile.println(writestring);
    outfile.close();
#ifdef DEBUG
    Serial.println("Wrote successfully.");
    ok_signal();
#endif
    return 0;
  } else {
#ifdef DEBUG
    Serial.println("Writing failed.");
    error_signal();
#endif
    return 1;
  }
}

ok_signal() and error_signal() are merely functions to flash an LED.
EDIT:
Thanks for your reply! I tried the code snippets
SPCR &= ~_BV(SPE)

and
SPCR |= _BV(SPE)

at the appropriate places, although I did not understand them. There was, however, no change in power consumption - SCK still seems to run.
I could not adapt the physical changes detailed in the suggested wordpress article, as the adapter there is quite different from my microSD adapter, and I know too little about hardware to adapt the author's suggestions. It looks and sounds quite promising though ...
Thanks for your time! Any help is greatly appreciated!

You'll have to disable SPI (SPCR &= ~_BV(SPE)), and set the pin to LOW. Then when writing, re-enable SPI (SPCR |= _BV(SPE)).

Also see these posts: https://edwardmallon.wordpress.com/2016/10/27/diy-arduino-promini-data-logger-2016-build-update/ (Section named "The SD Card Adapter"), and https://edwardmallon.wordpress.com/2014/09/22/high-sleep-current-problem-solved/ for a lot of useful low-power information.

Re-visiting the issue, I have found a simple answer:
I set the SPI pins as outputs and inputs respectively:
const int chipSelect = 10;
const int MOSIPin = 11;
const int MISOPin = 12;
const int SCKPin = 13;

and
  pinMode(chipSelect, OUTPUT);
  pinMode(MOSIPin, OUTPUT);
  pinMode(MISOPin, INPUT);
  pinMode(SCKPin, OUTPUT);

Now, before I power down my machine, I do the following:
  SPI.end();
  digitalWrite(SCKPin, HIGH);
  digitalWrite(chipSelect, HIGH);
  digitalWrite(MOSIPin, HIGH);

Now, the drawn current drops from 1mA to roughly 0,02mA, which is satisfactoy for me!
Thanks for reading!


text:
Arduino to ESP8266 (SoftwareSerial) communication, does not receive full data
I have an Arduino Uno and an ESP8266, connected over serial through ESP8266 pin GPIO_2 (which is set as RX over espsoftwareserial) and 11 on Uno (which is set as TX over SoftwareSerial). I am trying to send data in this format:
<0.000000:0.000000:0.000000:0.000000:0.000000:0.000000:24.50:24.50:1.49>
It is < char then number with six floats, separator :, and again... 9 times
I am using:

espsoftwareserial library
Original SoftwareSerial library

Arduino UNO code:
SoftwareSerial ARD_ESP(10, 11); // RX, TX

totalVolume[0] = 0.000000;
totalVolume[1] = 0.000000;
totalVolume[2] = 0.000000;
flowRate[0] = 0.000000;
flowRate[1] = 0.000000;
flowRate[2] = 0.000000;
float temperature_cold_value = 24.50;
float temperature_hot_value = 24.50;
float propane_gas_value = 1.49;

void setup()
{
   ARD_ESP.begin(57600);
   Serial.begin(9600);
}
void loop()
{
if (millis() - previousMillis_esp_post > 5000 && run_state_metering == 1)
     {
          ARD_ESP.print("<");
          ARD_ESP.print(totalVolume[0],6);
          ARD_ESP.print(":");
          ARD_ESP.print(totalVolume[1],6);
          ARD_ESP.print(":");
          ARD_ESP.print(totalVolume[2],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[0],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[1],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[2],6);
          ARD_ESP.print(":");
          ARD_ESP.print(temperature_cold_value,2);
          ARD_ESP.print(":");
          ARD_ESP.print(temperature_hot_value,2);
          ARD_ESP.print(":");
          ARD_ESP.print(propane_gas_value,2);
          ARD_ESP.print(">");

          Serial.print("<");
          Serial.print(totalVolume[0],6);
          Serial.print(":");
          Serial.print(totalVolume[1],6);
          Serial.print(":");
          Serial.print(totalVolume[2],6);
          Serial.print(":");
          Serial.print(flowRate[0],6);
          Serial.print(":");
          Serial.print(flowRate[1],6);
          Serial.print(":");
          Serial.print(flowRate[2],6);
          Serial.print(":");
          Serial.print(temperature_cold_value,2);
          Serial.print(":");
          Serial.print(temperature_hot_value,2);
          Serial.print(":");
          Serial.print(propane_gas_value,2);
          Serial.print(">");
          Serial.print("");

          previousMillis_esp_post = millis();
     }

ESP8266 code: (it's programmed with Arduino IDE)
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <string.h>

SoftwareSerial ARD_ESP(2, SW_SERIAL_UNUSED_PIN);

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;

String sensor_1_total_volume;
String sensor_2_total_volume;
String sensor_1_flow_rate;
String sensor_2_flow_rate;
String temperature_cold_value;
String temperature_hot_value;
String propane_butane_gas_value;
String mereni_token = "xxxxx";

void setup() {

  Serial.begin(115200);
  ARD_ESP.begin(57600);
  delay(10);
}

void loop() {

  recvWithStartEndMarkers();
  showNewData();

  sensor_1_total_volume = getValue(receivedChars, ':', 0);
  sensor_2_total_volume = getValue(receivedChars, ':', 1);
  sensor_1_flow_rate = getValue(receivedChars, ':', 2);
  sensor_2_flow_rate = getValue(receivedChars, ':', 3);
  temperature_cold_value = getValue(receivedChars, ':', 4);
  temperature_hot_value = getValue(receivedChars, ':', 5);
  propane_butane_gas_value = getValue(receivedChars, ':', 6);

}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (ARD_ESP.available() > 0 && newData == false) {
        rc = ARD_ESP.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This arrived: (unparsed)");
        Serial.println(receivedChars);
        Serial.println("DATA sensors: (parsed)");
        Serial.println(sensor_1_total_volume);
        Serial.println(sensor_2_total_volume);
        Serial.println(sensor_1_flow_rate);
        Serial.println(sensor_2_flow_rate);
        Serial.println(temperature_cold_value);
        Serial.println(temperature_hot_value);
        Serial.println(propane_butane_gas_value);
        Serial.println(mereni_token);
        newData = false;
    }
}

String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

It works fine, but ESP receive only three values, another 6 does not.
I have tried to change bitrate to 57600, but thats not help.
I think that there is a problem with speed or waiting for full data.
Can you help me ? Many Thanks.
Here is the output from ESP:
This arrived: (unparsed)0.000000:0.000000:0.000000:0.00
DATA sensors: (parsed)
0.000000
0.000000
0.000000
0.004

xxxx

Could you reduce these pages of code to a minimal, complete, verifiable example [http://stackoverflow.com/help/mcve] please, and edit your question to include it. You might even find that doing so fixes your problem.

Its Done. Maybe now someone could help.

I meant get rid of all the many Serial.println()s and replace with a single test string. Send only that string.  Write a minimal example for the receiving device to receive and print only that line. Show how the expected and actual received data differ.

You should be able to write a little 10-line program for sender and another for receiver, and demonstrate the problem very concisely. It'll help us, and it'll help you :-)

You are sending number+'.'+6 float +separator = 9 char at least.
You are sending 9x this, 81 char at least. Plus '<>' and maybe some more chars...
And you store it in 32 char long buffer. Somehow it does not fit all inside, who knows why?  :(
As you can see, you got like 32 chars only of the full transmission. Try to set numChars to something like 100 and try again. See, if it is better.
(Also I would use pattern
      ARD_ESP.print("<");
      Serial.print("<");
      ARD_ESP.print(totalVolume[0],6);
      Serial.print(totalVolume[0],6);
      ARD_ESP.print(":");
      Serial.print(":");

to leave the ESP more time to process stored data, but it is probabelly not problem now)

Thank you so much. I am such an idiot. I wrote a program and forget on setting numChars to corresponding value.

I am trying to use this for my purposes with just two strings.  I was hoping to use it with an ESP8266-01 with only eight pins.  Do you think it would work  what pins should I plug into  on the ESP if I use TX (2) and RX(3) on the Arduino UNO.  Thanks

Sorry, I do not have ESP or much knowledge about it. I just counted characters and read the size of buffer and see, there is at least one big problem (regardless platform) which I can simply see. Happened this was all, what was needed to fix it.


text:
Minimal ATmega328p Ethernet Configuration
What would be minimal schematic for ATMega328P in order to have communication over ethernet? So I'm not asking about attaching existing shields to existing Arduino board, but just for bare minimum of ATMega328P and ethernet on one board, so basically like minimal version of Arduino Yun.

Start with the schematic of the Arduino-Ethernet and start removing things you don't need.

This is schematic of ethernet shield? I noticed that there's already ATMega328-20MU on it, so this is basically independent module?

It's the Arduino Ethernet. Its basically an Arduino Uno with Ethernet build in.


text:
Convert LIRC config file to Arduino IR remote command
I have a LED 24 button remote with a few broken buttons and I want to simulate all the buttons with an esp8266 using an IR remote library.
I would like to know if someone can help me translate the LIRC config file with all the functional buttons to an ESP lib command.
I have 2 lircd.conf files of the same remote (everything worked on a raspberry) and I'm using the same circuit on an ESP8266 (wemos d1 mini pin D5 and D6).
lircd.conf 1
begin remote

  name  lumina
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       8860  4530
  one           508  1724
  zero          508   607
  ptrail        508
  repeat       8863  2301
  pre_data_bits   16
  pre_data       0xFF
  gap          107224
  toggle_bit_mask 0x0

      begin codes
          PWR_ON                   0xB04F
          PWR_OFF                  0xF807
          LI_LOW                   0xB847
          LI_HI                    0x906F
          R                        0x9867
          G                        0xD827
          B                        0x8877
          W                        0xA857
          R1                       0xE817
          R2                       0x02FD
          B4                       0xF00F
          G1                       0x48B7
          B1                       0x6897
          FLASH                    0xB24D
          STROBE                   0x00FF
          FADE                     0x58A7
          SMOOTH                   0x30CF
          G2                       0x32CD
          R3                       0x50AF
          R4                       0x38C7
          G3                       0x7887
          G4                       0x28D7
          B2                       0x20DF
          B3                       0x708F
      end codes

end remote

lircd.conf 2
begin remote

  name  lumina
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       8861  4525
  one           515  1718
  zero          515   600
  ptrail        516
  repeat       8865  2291
  pre_data_bits   16
  pre_data       0xFF
  gap          107235
  toggle_bit_mask 0x0

      begin codes
          B1                       0x6897
          PWR_ON                   0xB04F
          PWR_OFF                  0xF807
          LI_LOW                   0xB847
          LI_HI                    0x906F
          R                        0x9867
          G                        0xD827
          B                        0x8877
          W                        0xA857
          R1                       0x9867
      end codes

end remote

Output from a few buttons read from the esp using the IRremoteESP8266 library .
F0C41643
4039382595
Unknown encoding: F0C41643 (32 bits)
Raw (68): 8850 -4550 550 -650 550 -650 550 -650 500 -650 550 -600 550 -650 550 -650 550 -600 550 -1750 550 -1750 500 -1750 500 -1750 550 -1750 500 -1750 550 -1750 550 -1750 500 -1750 500 -650 500 -1750 550 -1750 550 -650 550 -650 500 -650 550 -650 550 -650 550 -1750 550 -650 500 -600 550 -1750 500 -1750 550 -1750 550 -1750 500
------------------

A3C8EDDB
2747854299
Unknown encoding: A3C8EDDB (32 bits)
Raw (68): 8900 -4550 550 -650 550 -600 550 -650 550 -650 550 -600 550 -650 550 -600 550 -600 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -650 550 -1750 550 -650 550 -1750 550 -650 550 -600 550 -600 550 -650 550 -1750 550 -650 550 -1750 550 -650 550 -1750 550 -1750 550 -1750 550
------------------

86B0E697
2259740311
Unknown encoding: 86B0E697 (32 bits)
Raw (68): 8900 -4550 550 -600 550 -650 550 -650 550 -600 550 -600 550 -650 550 -600 550 -600 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -600 550 -1750 550 -1750 550 -600 550 -600 550 -650 550 -650 550 -600 550 -1750 550 -600 550 -650 550 -1750 550 -1750 550 -1750 550
------------------

A3C8EDDB
2747854299
Unknown encoding: A3C8EDDB (32 bits)
Raw (68): 8900 -4550 550 -650 550 -600 550 -650 550 -600 550 -650 500 -650 550 -600 550 -650 550 -1750 550 -1750 500 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -1750 550 -650 550 -1750 550 -650 550 -1750 550 -650 550 -600 550 -650 500 -650 550 -1750 550 -650 500 -1750 550 -650 550 -1750 550 -1750 550 -1750 500

Looks like is just plain NEC IR protocol. So use something like irsend.sendNEC(0xB04F, 16) for POWER_ON.

did with a few of those values, tried 16 and 32 for the second value