text:
Problem uploading to board error, but I've selected the port and the board type?
I am having an issue when I try to upload a program to the board. I am working on a Simon Says game, and when I first started uploading, my computer handled it fine. Everything worked properly.
However, now I have added 3 LEDs for the colors and 3 buttons. I wrote a program for them to start the game, and then went to test it. That's when my Arduino would beep 3 times and then 75% of the time my computer would give me this error:

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

25% of the other time I get this:

An error occurred while uploading the sketch

It seems as though my project is getting too complicated for the Arduino to handle maybe? This is my code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int s = 13; // Speaker
int r = 6;  // Red LED
int y = 5;  // Yellow LED
int g = 4;  // Green LED
int b1 = 3; // Red button
int b2 = 2; // Yellow button
int b3 = 1; // Green button - I don't know if pin 1 works.

void setup() {
  lcd.begin(16, 2);
  pinMode(s, OUTPUT);
  pinMode(r, OUTPUT);
  pinMode(y, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(b1, INPUT);
  pinMode(b2, INPUT);
  // pinMode(b3, INPUT); Does pin 1 work?
}

void loop() {
  lcd.print("Press any button");
  lcd.setCursor(4, 1);
  lcd.print("to play!");
  while (true) {
    if (digitalRead(b1) == HIGH) {
      break;
    }
    delay(50);
  }
  lcd.clear();
  delay(1000);
  lcd.setCursor(1, 0);
  lcd.print("Simon's turn!");
  delay(1000);
  while (true) {
    // For now, I don't want to loop. I will finish the program when this     problem is resolved.
    delay(50);
  }
}

Does anyone know the solution to this problem?

What precisely is wired to pin 1?

Pin 1 goes to the button which goes with the green LED. It can tell when the button is pressed. I didn't know if that was the problem, but when I commented it out, the upload still had an error (not in the code).

Anything besides the button? Any pullup or pulldown resistor?  If you disconnect everything from pin 1 does it start working again?

Let me try that.

Okay, I removed everything from pin 1, tried to upload again. Unfortunately, still an error. Also, there is nothing else other than the button.
Edit
There is a potentiometer, but it doesn't even connect to pin 1. It is for the LCD display adjustment.

Arduino play around from time to time. Which one do you use.
Unplug it and plug it back in. If Pin D0 and D1 are occupied, you may have problems with uploading.

I use the Uno. I have unplugged and plugged back in, that didn't affect anything. Pin D0 and D1 are not occupied. Any more suggestions?

Something is blocking the port. It is not a compiler error.

Can you upload other scripts. Or is it only happen on this one?

It only happens with this one, which is strange. I've started a new file and it works fine.

Hi Ben. Sorry. I was a little bit busy. I am glad you resolve your problem by creating a new file. I work in IT Support. I also like to know why something is causing the problems. I may have a look at it at some point. Sorry. Just very busy now, with my Arduino projects. I may come across a similar problem and then I will post the answer here.

Remove anything that is connected to the Tx and Rx pin(communication pins)
And try uploading the code and it might possibly work


text:
How to regulate a led on-board?
There is blink project consisting 3 sections:
1 - regulation of the led brightness using a potentiometer
2 - whenever: the button is pressed - the led is on
-   the button is released - the led is off
3 - change state of a led statically
The question is that:
May I make this project on-board?
I am curious that, if I will try making this project on-board (Arduino UNO) will the Arduino damaged?

When the button is released, the led is off, but at the same time the brightness is regulated with a potentiometer. Those two things can not be done at the same time.

"making this project on-board"? what do you understand by that?

@Juraj Using just Arduino UNO board, not using extra breadboard and led. There are 11 leds like: ON, R17, R6, AX,.. and so on. As I unerstood on-board project is done just using these leds. If I am wrong, would be so glad to learn what on-board and off-board means? )))

so it should be "making this project by using on-board LED"? button or pot should not be on-board

only on-board LED controllable from the sketch is LED on pin 13. and it is not dimmable as you can read in the Answer by Kevin

there are only 4 LEDs on Uno R3. RX, TX for Serial lines, power and L on pin 13

@Juraj So we can connect a potentiometer and button to regulate the led(pin 13), right?

NO, it is not dimmable. you can turn it on and off with a button. (and the button is not on board)

If you really want to dimm the onboard LED, you can bitbang the PWM signal by setting the state of pin 13 directly in your code (changing rapidly between high and low, with a variable ratio of high to low time). But this means, that you will not be able to do much else.

@chrisl,  the LED on D13 can be dimmed using standard blink without delay coding.  Turn it on, monitor the time going by, when enough has passed then turn off the LED. Do that at a "fast enough" rate, say every 5mS, and it appear to be dimmed. For brighter, have more on-time than off-time. For dimmer, have more off-time than on-time.  The code can lots of other stuff while waiting for the time to pass for the next transition. This is basically bit-banged PWM as mentioned elsewhere.

@chrisl, good idea. I hope marvB will come back and read it. (including the end :-) )

Pin 13, which is the on-board LED, is not a pwm pin. So you cannot Control the brightness of that LED on-board. You will have to use another LED and a PWM pin.

source: Stack Exchange

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

sort: votes


text:
Serial communication between python and Arduino nano BLE sense 33 for running six DC motor
I am controlling six DC motors by varying their voltage. I have figured out the voltage required for each motor in python; now it's time to send this voltage through Arduino Nano BLE Sense 33 to run the six DC motors via serial communication.
Can anyone help me to figure out its solution?
Python Code:

from time import sleep
import serial
import struct
ser = serial.Serial('COM7', 9600)

while True:
     ser.write(struct.pack('BBBBBB',200,210,220,230,240,180))  ## PWM
     ser.readline()
     sleep(.5)

Arduino Code:
const int ledPin[6] = {4, 7, 8, A5, 13, A0};
const int ledPin1[6] = {2, 6, 9, A4, 12, A1};
const int ledPin2[6] = {3, 5, 10, A3, 11, A2};

int x;
void setup() {
  Serial.begin(9600);
  for (int k = 0; k < 6; k++) {
    pinMode(ledPin[k], OUTPUT);
    pinMode(ledPin1[k], OUTPUT);
    pinMode(ledPin2[k], OUTPUT);
  }
  Serial.setTimeout(1);
}
void loop() {
  for (int i = 0; i < 6; i++) {
    while (!Serial.available());
    x = Serial.readString().toInt();
    dir(ledPin[i], x, ledPin1[i], ledPin2[i]);
  }
}

float dir(int Pin, float x, int Lpin1, int Lpin2) {
  analogWrite(Pin, abs(x));
  if (x < 0) {
    digitalWrite(Lpin1, HIGH);
    digitalWrite(Lpin2, LOW);
  }
  else if (x > 0) {
    digitalWrite(Lpin1, LOW);
    digitalWrite(Lpin2, HIGH);
  }
  else {
    digitalWrite(Lpin1, LOW);
    digitalWrite(Lpin2, LOW);
  }
}

what have you tried?  ... what failed? ... serial communication is not related to motor control ... the two functions are completely separate

I want to send voltage data from python to Arduino

By using serial communication, we can transfer data from python to Arduino. Here, in my program, that data is PWM. Once it comes in Arduino, I can run the DC motor.

Now, it will get clear. Please read the question once again.

Here, I have determined the voltage required for the DC motor(actuator). Now, I cannot operate the DC motor through python, so I am transferring data from python to Arduino IDE via serial communication. I know how to handle a single DC motor, but I have to run six DC motors here. In python, I have figured out the voltage for each motor, so it is in the form of an array. So, now I want to transfer this array from python to Arduino IDE, where I can run six DC motors.                 I hope you understand now.

The python code you have is sending six bytes of data in binary form as b'\xc8\xd2\xdc\xe6\xf0\xb4', while you are reading it as a String (that is, a series of ASCII) in your Arduino. You need to read each byte like byte x = Serial.read(); and deal with each data received.

Only one Dc motor is running, and the others are not running. I think it may be because they are not getting PWM values. Can you resolve it?

Thank you @hcheung.  I will try, and let you know.

Sorry @jsotola, I did not read your post carefully. I got now your question. I have already posted my code. It works for only one DC motor, and others are not running.

Here is your Arduino loop() should look like:
void loop()
{
    if(Serial.available() > 0)
    {
        for (int i = 0; i < 6; i++)
        {
            while (!Serial.available());
            int x = Serial.read();
            dir(ledPin[i], x, ledPin1[i], ledPin2[i]);
        }
    }
}

Haven't tested it though.

It works. Thanks

@VishalNaik Please accept it as an Answer. Thanks! :)

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


text:
Trying to understand stepper behavior, and I have some specific questions
I'm using a repurposed MKS Gen L V1.0 board (arduino MEGA + RAMPS, basically) to control a pair of IR sensors and a NEMA 23 stepper with TB6600 driver.
The application is simple: raise and lower the end of a roller. Wait for a signal from the sensors, wait for a time to see if the issue fixes itself and if it doesn't, turn 300 revolutions CW to raise, CCW to lower; wait; if we still have an issue, turn 150; issue fixed, return to zero.
It all works the way I want it to, except for the speed and direction of the stepper. NOTE: this is with the motor not attached to anything. NO LOAD.
To test, I've loaded a very simple script:
// speed tests
for (int a = 650; a <= 1200; a += 50) {
    Serial.println(a)
    // do the thing a few times (for this test, once)
    for (int y = 0; y <= 1; y++) {
        // turn one revolution
        for (int x = 0; x <= 200; x++) {
            digitalWrite(stepPin, HIGH);
            delayMicroseconds(a);
            digitalWrite(stepPin, LOW);
            delayMicroseconds(a);
        }
    }
    delay(1000);
}

exit(0);

Any delayMicroseconds value below 650 or above 1200, the motor jitters or vibrates but doesn't turn. When it does spin, the motor changes direction between spins, and as we get near the top of bottom of the range, it'll even change direction mid-spin.
The driver is set to 200p/rev and 1.5a. (I played with microstepping and higher amperage, but it didn't make an appreciable difference.)
Before you enthusiastically recommend a library, I've worked with both AccelStepper and Stepper (the default Arduino library?), and neither were as reliable or predictable as the code above.
I would like to be able to use AccelStepper, but the ac/de-celeration ramps have the same symptoms as my simpler code: between 650 and 1150μs, everything's fine, anywhere outside that range is not.
What don't I know? What am I missing to be able to turn slower and/or faster than that narrow range? Why does it change direction mid-spin or between spins?

Is the motor axle attached to something mechanically? If yes, have you tried it with no load attached to the motor?

This is without load. Once it is loaded, it'll be turning a screw, so very little load on it.

Please provide an image of how you wired everything up. Sudden direction change might indicate a floating dir pin

Done: image as requested.

Did you connect ground of the RAMPS to the negative terminals of the TB6600?

Everything is connected as shown in the image. If the board itself has a ground, I'm not aware of it. (MKS GEN L V1.0 - repurposed 3d printer board)

Mhh, normally you wouldn't change the length of the pulses for controlling the speed of the motor, just their frequency. Please try having the first delay fixed to 50us and vary the second delay. My TB6600 driver works correctly with this

At 50us, the motor whines without moving. If I stray very far from 800us in either direction, the motor just chatters. The driver is set ON-ON-OFF, OFF-OFF-OFF (200 steps, 3.5a). It's a NEMA23 if that makes a difference.


text:
Can’t set duty cycle to 0% with custom PWM
I'm trying to control a heating element with PWM with an Arduino Nano, but the problem is even if I set the duty cycle to 0 it gives a tiny spike.
I want to generate a square wave of 1Hz and that's why I override the default PWM registers.
Here is the code:
// Set up fast PWM on the Arduino Uno at 1 Hz on digital pin D9
void setup() {

    // set I/O pins
    pinMode(LDR_INPUT, INPUT);      // A0
    pinMode(HEATER_OUTPUT, OUTPUT); // D9

    // Enable the PWM output OC1A on digital pins 9
    TCCR1A = _BV(COM1A1) | _BV(WGM11);
    // Set fast PWM and prescaler of 256 on timer 1
    TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS12);
    // Set the PWM frequency to 1Hz: 16MHz/(256 * 1Hz) - 1 = 62499
    ICR1 = 62499;

    // OCR1A = 32149; // this gives me duty cycle of 50%, working fine

    OCR1A = 0;       // but this is not working

    //allow PWM timers to start
    delay(10);
}

For testing, I connected an LED to the PWM pin (D9) and these are the spikes from the LDR reading from analog pin A0 (I don't have an oscilloscope).

I'm getting the same results with the Nano and Uno. My IDE version is 1.8.14.
How can I fix this problem?
Here is my temperature control function:
void Compute()
{
    unsigned long now = millis();
    int timeChange = (now - lastTime);

    if(timeChange>=SampleTime)
    {
        /*Compute all the working error variables*/
        double error = Setpoint - temprature;

        if (error <= 0)
        {
            Output = 0;
            Serial.println("level: 0");
        }
        else if (error <= 1)
        {
            Output = 5;
            Serial.println("level: 1");
        }
        else if (error <= 2)
        {
            Output = 30;
            Serial.println("level: 2");
        }
        else if (error <= 3)
        {
            Output = 50;
            Serial.println("level: 3");
        }
        else if (error <= 10)
        {
            Output = 60;
            Serial.println("level: 4");
        }
        else if (error <= 100)
        {
            Output = 200;
            Serial.println("level: 5");
        }
        else
        {
            Output = 255;
            Serial.println("level: 6");
        }

        analogWrite(HEATER_OUTPUT, Output);
        //OCR1A = map(Output, 0, 255, 0, 62499);
        delay(10);

        lastErr = error;
        lastTime = now;
    }
}

The problem is that after I override the PWM registers, the analogWrite() seems messed up. It's not working, and for all the values of Output, the result is almost the same.
UPDATE 22/06/2021
I'm still struggling to fix this, if I use analogWrite() or digitalWrite() to turn off the PWM pin, the further changes on OCR1A regs are not taking action. whatever values I gave to the OCR1A the pin remains low, if I manually make the pin high with digitalWrite or analogWrite the pin remains high forever the changes on OCR1A are not taking into action.
I wrote a test function
void testPWM3() {

    Serial.println("f: 1Hz | on 0s");
    digitalWrite(HEATER_OUTPUT, LOW); // turn off the pwm pin to get full of (0% duty cycle)
    delay(5000);
    /*
     After turning off the pin with digitalWrite() further changes on OCR1A reg are not taken into action
    */
    digitalWrite(HEATER_OUTPUT, HIGH);
    Serial.println("f: 1Hz | on 125ms");
    OCR1A =  1953;
    delay(5000);

    Serial.println("f: 1Hz | on 250ms");
    OCR1A =  3906;
    delay(5000);

    Serial.println("f: 1Hz | on 500ms");
    OCR1A =  7812;
    delay(5000);

    Serial.println("f: 1Hz | on 1sec");
    digitalWrite(HEATER_OUTPUT, HIGH);  // this works
    delay(5000);
}

Any advice on this will be greatly helpful, thank you

That is how it is supposed to be. In this fast PWM mode, the duty cycle
is (OCR1A+1)/(ICR1+1). If you want a duty cycle of zero, you have to
disengage the PWM and turn the pin to OUTPUT LOW.
This is what the Arduino's analogWrite() does: it treats the
value 0 as a special case. Note that 255 is also treated as a special
case, although that is not useful.
Edit 1: about analogWrite() being messed up.
analogWrite(9, value) sets OCR1A to a value between 1 and 254 (0 and
255 being handled in a different manner). The duty cycle you get is, as
I wrote before (OCR1A+1)/(ICR1+1). This is not what your test
function expects.
I suggest you ditch analogWrite() and instead set directly OCR1A.
Edit 2: Once you have taken control of a PWM channel at low-level,
by writing directly to the hardware registers, you should not use
the Arduino functions digitalWrite() nor analogWrite() on the
associated pin. These functions assume those hardware registers are
controlled solely by the Arduino core, and they will fiddle with them in
a way that will likely break your program.
To set the duty cycle to zero, disable the PWM mode and set the pin to
LOW:
TCCR1A &= ~_BV(COM1A1);  // disable PWM on pin OC1A = PB1
PORTB  &= _BV(PB1);      // set PB1 to LOW

Thank you for your response, I have tried that, but the analogWrite is not working properly in my case, updated the question.

You mean not working properly in a way different from how this answer explains perfectly well?

@timemage, this is a great answer, I got what he says, with analogWrite()  I'm getting clean off PWM, but with analogWrite(9,128) I'm supposed to get a duty-cycle of 50%, but what I'm getting is a really thin pulse..

Re “analogWrite(9,128) I'm supposed to get a duty-cycle of 50%”: No, you are not. Read my answer more carefully.

oh damn me, so for getting 50% I have to give half of ICR1 right..?

Hi, there I'm still struggling to fix this, if I use analogWrite() to turn off the PWM pin, the further changes on OCR1A regs are not taking action. whatever values I gave to the OCR1A the pin remains low, if I manually make the pin high with digitalWrite or analogWrite the pin remains high forever the changes on OCR1A are not taking into action... Any advice on this will be greatly helpful, thank you

Fast PWM works that way, on Duty Cycle 0% the Output is set to high for 1 cycle at TOP+1 for non-inverted PWM mode and to low for inverted mode.
If you want to have a continuous low output, you have to use Phase Correct  or Phase and Frequency Correct PWM.


text:
NODEMCU 1.0 HX711 Load cell reading weird text

Hi Guys! i have a problem with the reading with my NODEMCU where i tried this code on an arduino UNO it is working perfectly fine but until i tried to switch it to NODEMCU 1.0 which have a wifi function that i need, the reading turn out to have this type of error, i've tried looking for solution online and tried every single of them but apparently none of it help. The image is the error i have faced and the connection i have made from the nodemcu to hx711 is VCC --> Vin or 3.3v, GND --> GND, DT --> D2, SCK --> D3.
Here's the code that i found online to use:
#include <HX711.h>

// Scale Settings
const int SCALE_DOUT_PIN = D2;
const int SCALE_SCK_PIN = D3;

HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);

void setup() {
  Serial.begin(115200);
  scale.set_scale(-47740);// <- set here calibration factor!!!
  scale.tare();
}

void loop() {
  float weight = scale.get_units(1);
  Serial.println(String(weight, 3));
}

Thanks in advance!!

Putting your whole code in comments is not helpful.  I edited your post this time, remember to select code and then ctrl+k

Sorry about that, would keep in mind about it! Appreciate your help thanks!

try D1 instead of D3. D3 is io 0, a boot configuration pin

Hi juraj! Thanks for the reply. i tried D1 and the Serial monitor now shows a reading of 0.000 all the way regardless of the weight i put on it.

Hi juraj, i have change the VCC connection from Vin to 3.3v and it work! thanks!! could you post your answer on the answer section so i could upvote? thanks for the help!!

Try D1 instead of D3. D3 is io 0, a boot configuration pin with pull-up on board.


text:
Arduino ADC converter calculation
I am trying to choose a wire encoder for my project. So far, I found this wire encoder (see link). Assuming the measurement range of my cylinder is 1 m. Then, with a 10 bit ADC converter of my Arduino Mega2560, I would have a resolution of 0.09cm (= 100cm/1024). But, lets say some cylinder only have a measurement range of 0.5m. Then the resolution would be 0.048 (=50cm/1024).
I can see that I am missing something here, because the resolution of the later case should be worse than the case with the full measurement range 1m. I would be appreciate for any tipps.

Edit:

Cylinder's movement range 0~1m

Wire encoder's measurement range 0~1.25m

Wire encoder's analog output 0~10v
ADC resolution 10 bit

I guess with "range of my cylinder" you mean its circumference. Then your calculation is right and logical. The ADC has a fixed resolution of 1024 steps. If you distribute these steps onto a smaller range, then it means, that the steps are closer together, thus you are getting a better resolution. Basically you are trading the distance, which is covered by one rotation, for resolution. Higher distance gives a lower resolution and vice versa. I don't see, why this should be different. If this argument didn't convince you, can you explain further, why you think it should be worse?

I meant with "range of my cylinder" the movement range of my cylinder. I added more information. But still not sure, how one should map the encoder movement to the cylinder movement...Could you guide me here a little bit?

Ok, now I don't understand your application. What actually is that cylinder? What are you trying to achieve? What is your project setup? I need a more detailed description to understand, what you are trying to do.

I added some picture to clarify further. Basically, I want to measure the cylinder movement with a wire encoder and since the output of my encoder is voltage, I would like to read in the value using an ADC converter of Arduino Mega2560. And I would like to estimate the resolution in this case...

Ah, ok, with cylinder you mean hydraulic cylinder. Haven't thought of that.

@Joe, you know this thing linked costs like 700+ USD right?  I'm not sure where you got the image from, but even if that's a cheaper one, it seems like you can still swing for a better ADC than the one built into an ATmega2560.  Or maybe one of these with a digital interface.  Otherwise, like chrisl said.

Your calculation is not correct. The encoder has its 0 to 10V output voltage distributed over the whole distance, that the cable can reach, so 1.25m. And that gives you the resolution: 1.25m/1024 = 1.22mm. The resolution doesn't change, if you use less than the maximum length. It's still the same resolution of about 1.22mm. The encoder doesn't care, if you are only using 1m of its range.

But if you try to write the code: 1) with full range 1.25m cylinder_pos = map( analogRead(A0), 0, 1023, 0, 1.25 ) 2) with only 0.5m range cylinder_pos = map( analogRead(A0), 0, 1023, 0, 0.5 ). It matters right?

Only, if you speak about a different encode, that has the range 0.5m. If you are using the encode with 1.25m range you need to use that value for the calculation


text:
Trouble configuring Arduino Due SPI to ADC
I am having trouble configuring Arduino Due SPI to an AD7490 ADC.
Here is how I have the pins connected:

+3.3V > 7490 pin 22 Vin
+3.3V > 7490 Vref
DUE CS (8) > 7490 pin 20 SS - slave select)
DUE SCK > 7490 pin 16 (SCK - clock)
DUE MOSI > 7490 pin 19 (MOSI - data out)
Ground > 7490 pin 24 (all ground lines are tied together)
DUE MISO > 7490 pin 15

Below is my code, I feel like I am writing the correct bits into the register. The problem I think I'm having is getting the timing write. The code is a simple attempt to read a single channel.
#include <SPI.h>

// Set Constants
const int adcChipSelectPin = 8;      // set pin 8 as the chip select for the
ADC:

// Start setup function:
void setup() {

pinMode (adcChipSelectPin, OUTPUT);
// set the ChipSelectPins high initially:
digitalWrite(adcChipSelectPin, HIGH);
// initialise SPI:
SPI.begin();
SPI.setBitOrder(MSBFIRST);         // Not strictly needed but just to be
sure.
SPI.setDataMode(SPI_MODE0);        // Not strictly needed but just to be
sure.
Serial.begin(9600);
//Clock Speed: Master clock/divider
//84Mhz/64 =  1.3 MHz
SPI.setClockDivider(SPI_CLOCK_DIV64);

} // End setup function.

// Start loop function:
void loop() {
float voltage[2];
for (int i = 0; i < 3; i++) {
voltage[i] = readAdc(0, 0);
}

}// End of loop function.

//Function to read the ADC, accepts the channel to be read.
float readAdc(int channel, int slave) {

float value;
if (slave == 0) {
noInterrupts(); // disable interupts to prepare to send address data to the
ADC.
digitalWrite(adcChipSelectPin, LOW); // take the Chip Select pin low to
select the ADC.

byte FirstByte = 0b10000011;
byte SecondByte = 0b00110000;

SPI.transfer(FirstByte);

byte response1 = SPI.transfer(SecondByte);
byte response2 = SPI.transfer(0x00);

digitalWrite(adcChipSelectPin, HIGH); // take the Chip Select pin high to
de-select the ADC.
interrupts(); // Enable interupts.
Serial.println(response1);
Serial.println(response2);

}

The serial.prints output 255 consistently. In my experience this means the SPI is configured incorrectly.
Any pointers are appreciated.

I don't think the communication is like what you wrote here. It looks like it is sending the data with the next byte. Try with SPI.transfer(FirstByte); SPI.transfer(SecondByte); digitalWrite(adcChipSelectPin, HIGH); asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); digitalWrite(adcChipSelectPin, LOW); byte response1 = SPI.transfer(0x00); byte response2 = SPI.transfer(0x00);. The five nops are for respecting the 50nm "t_quiet" time requested in the datasheet

(of course if this work you can avoid using the 0x00 writings and concatenate successive requests; for instance something like (using only one SPI.transfer instead of two, and some pseudo-code) SPI.transfer(read channel 0); CS high, nops, CS low; byte result_ch0 = SPI.transfer(read channel 1); CS high, ..[repeat as many times you need].. , CS low; byte result_chN = SPI.transfer(0x00);

I tried your suggestion and am still getting the same response as before unfortunately.  I'm not sure what the issue could be at this point.

Did you try to measure the value of voltage on the MISO pin? is it 3.3V stable or it is lower? Can you try disconnecting it from the ADC and measure the voltage on the microcontroller MISO? Can you try to put a 10k resistor between MISO and GND?

The voltage on my MISO pin is only about .8V DC. When I disconnect from ADC I read a voltage of about .8V.

If you think the problem may be my board, I just hooked up another ADC through SPI and I am getting correct values.

can you try using weak pull-ups or pull-downs? I mean, try with a 10k resistor between MISO and +3.3V, then between MISO and GND. The 0.8V is really strange, it looks like a disconnected pin... double check the soldering of that wire to the ADC

From 3.3V to MISO I am getting nearly 3.3V and from MISO to gnd I am getting nearly 0V. I ran this ADC through a reflow oven so I may have made a mistake in overheating. I have another board coming in so I'll try and make sure I'm following the datasheet reflow specifications.
Besides that, does my code look alright? Thanks for the help by the way!

So where did the 0.8V come? if you mounted them on your own, then double check the soldering of the DOUT pin on the ADC; maybe it is not correctly soldered. Sometimes just heating it with a soldering iron (and/or adding some solder) fixes the soldering

I just put a new ADC on my PCB and am now getting 3.3 V, still not the write output though.

3.3V seems reasonable. Now what is your output? Can you attach an oscilloscope during transmission to see if it is actually transferring something?

Hey frarugi, I figured it out. Than you so much for the pointers!

For anyone else who comes across the same problem, this worked for me:
// include the library code:
#include <SPI.h>

// Set Constants
const int adcChipSelectPin = 8;      // set pin 8 as the chip select for the ADC:

// Start setup function:
void setup() {
    pinMode (adcChipSelectPin, OUTPUT);

    // set the ChipSelectPins high initially:
    digitalWrite(adcChipSelectPin, HIGH);

    // initialise SPI:
    SPI.begin();
    SPI.setBitOrder(MSBFIRST);         // Not strictly needed but just to be sure.
    SPI.setDataMode(SPI_MODE0);        // Not strictly needed but just to be sure.
    Serial.begin(9600);

    //Clock Speed: Master clock/divider
    //84Mhz/64 =  1.3 MHz
    SPI.setClockDivider(SPI_CLOCK_DIV64);

    //Send dummy values over when ADC is turned on
    //Hold Din High for 16 clock cycles twice
    digitalWrite(adcChipSelectPin, LOW);
    SPI.transfer(0xFF);
    SPI.transfer(0xFF);
    digitalWrite(adcChipSelectPin, HIGH);

    digitalWrite(adcChipSelectPin, LOW);
    SPI.transfer(0xFF);
    SPI.transfer(0xFF);
    digitalWrite(adcChipSelectPin, HIGH);
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    //Send dummy values, next read should have correct values

    digitalWrite(adcChipSelectPin, LOW);
    byte FirstByte = 0x83;
    byte SecondByte = 0x50;
    byte response1 = SPI.transfer(FirstByte);
    byte response2 = SPI.transfer(SecondByte);

    digitalWrite(adcChipSelectPin, HIGH);

    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    ///////////////////////////////////////////////////////////////////////////////////

    //50ns quiet time?
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
} // End setup function.

// Start loop function:
void loop() {
    float voltage[2];
    for (int i = 1; i < 17; i++) {
        voltage[i] = readAdc(0, 1);
        //50ns quiet time?
        asm volatile("nop");
        asm volatile("nop");
        asm volatile("nop");
        asm volatile("nop");
        asm volatile("nop");
    }
} // End of loop function.

//Function to read the ADC, accepts the channel to be read.
float readAdc(int channel, int slave) {
    float value;
    if (slave == 0) {
        byte FirstByte = 0x83;
        byte SecondByte = 0x50;
        FirstByte |= channel << 2;

        noInterrupts(); // disable interupts to prepare to send address data to the ADC.

        digitalWrite(adcChipSelectPin, LOW); // take the Chip Select pin low to select the ADC.
        //Write = 1
        //SEQ = 0
        // ADD3-ADD0 = 0000
        //PM1 = PM0 = 1
        //Shadow = 0
        //WEAK/Tri = 1
        //Range = 0
        //Coding = 1
        //0b10000010 1010 0000
        //extra 4 zeros to fill

        //May need to wait 16 * (1/freq)
        //16 * (1/1.3MHz)
        byte response1 = SPI.transfer(FirstByte);
        byte response2 = SPI.transfer(SecondByte);
        digitalWrite(adcChipSelectPin, HIGH);

        interrupts(); // Enable interupts.

        //Serial.println(response1);
        Serial.println(response2);
        byte channel = (response1 >> 4);
        //byte value = (response1 << 4);
        //byte digitalValue = (response1 << 4) | response2;
        //Serial.println(digitalValue);
        //Serial.println(channel);

        byte digitalValue = 0x00;
        float value = (float(digitalValue) * 3.3) / 4096.000; // The digital value is
        converted to an analogue voltage using a VREF of 2.048V.
        //Serial.print(channel);
        //Serial.print("\t");
        //Serial.println(value);
    }
}


text:
WiFi repeater using ESP8266
I have a ESP8266 and I wonder if it is possible to create a Wi-Fi signal repeater using this module.

I can create a network so that devices connect it.
I can connect to an existing network.

But I can not connect the network created with the network that I connected
Does anyone know how to do this? or you have any examples?

Even if that is possible, the speed will be very low.

You can't have a single ESP8266 be both an access point and a client, at least not using the exposed API (recall that the Arduino libaries do not implement much functionality themselves, all they do is call the underlying RTOS API).
Also, a signal repeater is not a radio-only device. It would have to understand the low-level 802.11* protocols and packet types so you don't end up with forwarding loops. You can't do it just by connecting a pair of 8266s back-to-back over SPI and blindly forward packets; there is a lot of networking code that would have to be written.

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


text:
nRF24L01+ Arduino mpu6050
How do I ever understand what the Arduino IDE means when they advise you of any errors?  The reason I ask is because I got several errors that don't make sense to me as I see what the error means and what line the issue is but I don't see anything wrong with the code. It's written how it should be, the reason I say this is because before I ended the code I was compiling/verifying my code every time I write a new line just to make sure if I got new errors. It's easy to check as it was more than likely the very last line of code I just wrote, rather than write a book then do a spell check you know?
I have included the part of the code where I get errors and the errors themselves. Hopefully someone can point out to me what is it that Arduino sees that I don't and in the same token I'll learn how to counter measure those errors.
1.  //imu's
2.  #include "Wire.h" // i dont think this will be needed on this mcu's "slaves"
3.  #include "I2Cdev.h" // i dont think this will be needed on this mcu's "slaves"
4.  #include "MPU6050.h" // i dont think this will be needed on this mcu's "slaves"
5.
6.  //motors
7.  #include "Servo.h" // select which motor this slave mcu has and comment out the other
8.  #include "Stepper.h" // select which motor this slave mcu has and comment out the other
9.
10. //wireless
11. #include "nRF24L01.h"
12. #include "RF24.h"
13. #include "SPI.h" // i dont think this will be needed on this mcu's "slaves"
14.
15. #define RF_CS 12
16. #define RF_CSN 13
17. RF24 radio(RF_CS, RF_CSN);//RF24 radio(9, 10);
18. const int pinCE = 9;
19. const int pinCSN = 10;
20.
21. byte bArray[] = {0000, 1000, 0100, 1100, 0010, 1010, 0110, 1110}; // this are the Ch 0/7 address from Mux
22. const uint64_t LA = 0xF0F0F0F0D2LL;//mcu1 address of Slave
23. const uint64_t RA = 0xF0F0F0F0C3LL;//mcu2 address of Slave
24. const uint64_t LL = 0xF0F0F0F0B4LL;//mcu3 address of Slave
25. const uint64_t RL = 0xF0F0F0F0A5LL;//mcu4 address of Slave
26. const uint64_t LW = 0xF0F0F0F0E6LL;//mcu5 address of Slave
27. const uint64_t RW = 0xF0F0F0F0F7LL;//mcu6 address of Slave
28. const uint64_t UT = 0xF0F0F0F0F8LL;//mcu7 address of Slave
29. const uint64_t BT = 0xF0F0F0F0F9LL;//mcu8 address of Slave
30.
31. /* MUX CH address To simplify things, 1 is HIGH, 0 is LOW
32.                                                                     0000 – 0
33.                                                                     1000 – 1
34.                   A multiplexer of this sort really just            0100 – 2
35.                   acts as a 16 to one 1 switch. The 4 digital       1100 – 3
36.                   pins are used to set HIGH or LOW, in a binary     0010 – 4
37.                   fashion (0-15) to determine what pin “SIG” is      1010 – 5
38.                   connected to. So bringing all 4 pins LOW would    0110 – 6
39.                   switch the CD74HC4067 to channel 0 (so SIG and    1110 – 7
40.                   C0 would be connected), bringing them all HIGH    0001 – 8
41.                   would switch it to 15 (so SIG and C15 would be    1001 – 9
42.                   connected)                                        0101 – 10
43.                                                                     1101 – 11
44.                                                                     0011 – 12
45.                                                                     1011 – 13
46.                                                                     0111 – 14
47.                                                                     1111 – 15 */
48.
49. int recivers[8][4] = {
50.   { 0xF0F0F0F0D2LL, { 0, 0, 0, 0 }, //0000 – 0 SDATA line from MPU to Multiplexer ch0
51.     { 0xF0F0F0F0C3LL, { 1, 0, 0, 0 }, //1000 – 1 SDATA line from MPU to Multiplexer ch1
52.       { 0xF0F0F0F0B4LL, { 0, 1, 0, 0,}, //0100 – 2 SDATA line from MPU to Multiplexer ch2
53.         { 0xF0F0F0F0A5LL, { 1, 1, 0, 0 }, //1100 – 3 SDATA line from MPU to Multiplexer ch3
54.           { 0xF0F0F0F0D6LL, { 0, 0, 1, 0 }, //0010 – 4 SDATA line from MPU to Multiplexer ch4
55.             { 0xF0F0F0F0E7LL, { 1, 0, 1, 0 }, //1010 – 5 SDATA line from MPU to Multiplexer ch5
56.               { 0xF0F0F0F0F8LL, { 0, 1, 1, 0 }, //0110 – 6 SDATA line from MPU to Multiplexer ch6
57.                 { 0xF0F0F0F0F9LL, { , 1, 1, 1, 0 } //1110 – 7 SDATA line from MPU to Multiplexer ch7
58.                 }
59.               }
60.             }
61.           }
62.         }
63.       }
64.     }
65.   }
66. }
67.
68. MPU6050 mpu;
69. int16_t ax, ay, az;
70. int16_t gx, gy, gz;
71.
72. long long  val[6];//6 DOF MPU 6050 thats where this val{6} come from
73. long val;
74. long prevVal;
75.
76. byte bArray[] = ( 0, 180 );
77.
78. //Mux control pins on the Arduino Digital pins
79. int s0 = 8;
80. int s1 = 7;
81. int s2 = 6;
82. int s3 = 5;
83.
84. //Mux in "SIG" pin
85. int SIG_pin = 0;
86. //int val = readMux(7);
87.
88. void setup()
89. {
90.   pinMode(s0, OUTPUT);
91.   pinMode(s1, OUTPUT);
92.   pinMode(s2, OUTPUT);
93.   pinMode(s3, OUTPUT);
94.
95.   digitalWrite(s0, LOW);
96.   digitalWrite(s1, LOW);
97.   digitalWrite(s2, LOW);
98.   digitalWrite(s3, LOW);
99.
100.      Wire.begin();
101.
102.      for (int i = 0; i < 10; i++) //10 mpu's
103.      {
104.        mpu.initialize();
105.      }
106.
107.      radio.begin();
108.      radio.payload = 6;
109.      radio.setAutoAck(false);
110.      radio.setDataRate(RF24_2MBPS);
111.      radio.openWritingPipe();
112.    }
113.
114.    void loop()
115.    {
116.      for (int i = 0; i < 16; i ++)//Loop through and read all 16 values
117.      {
118.        int readMux(int channel)
119.
120.        int controlPin[] = {s0, s1, s2, s3};
121.
122.        int muxChannel[8][4] = {
123.          {0, 0, 0, 0}, //channel 0
124.          {1, 0, 0, 0}, //channel 1
125.          {0, 1, 0, 0}, //channel 2
126.          {1, 1, 0, 0}, //channel 3
127.          {0, 0, 1, 0}, //channel 4
128.          {1, 0, 1, 0}, //channel 5
129.          {0, 1, 1, 0}, //channel 6
130.          {1, 1, 1, 0}, //channel 7
131.          {0, 0, 0, 1}, //channel 8
132.          {1, 0, 0, 1}, //channel 9
133.          //  {0, 1, 0, 1}, //channel 10
134.          //  {1, 1, 0, 1}, //channel 11
135.          //  {0, 0, 1, 1}, //channel 12
136.          //  {1, 0, 1, 1}, //channel 13
137.          //  {0, 1, 1, 1}, //channel 14
138.          //  {1, 1, 1, 1}  //channel 15
139.        }
140.      }
141.      //loop through the 4 sig
142.      for (int i = 0; i < 4; i ++)
143.      {
144.        digitalWrite(controlPin[i], muxChannel[channel][i]);
145.      }
146.
147.      //read the value at the SIG pin
148.      int val = analogRead(SIG_pin);
149.
150.      //return the value
151.      return val;
152.
153.      for (int i = 0; i < 6 i++)
154.      {
155.        mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
156.        val[0] = map(ax, -17000, 17000, 0, 180);
157.        val[1] = map(ay, -17000, 17000, 0, 180);
158.        val[2] = map(az, -17000, 17000, 0, 180);
159.        val[3] = map(gz, -17000, 17000, 0, 180);
160.        val[4] = map(gy, -17000, 17000, 0, 180);
161.        val[5] = map(gx, -17000, 17000, 0, 180);
162.
163.        radio.openWritingPipe(recievers[i].address);
164.        radio.write(val);
165.      }
166.
167.      delay(50);

    Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Nano, ATmega328"

    sketch_may19a:57: error: expected primary-expression before ',' token
    sketch_may19a:66: error: braces around scalar initializer for type 'int'
    sketch_may19a:68: error: expected ',' or ';' before 'MPU6050'
    sketch_may19a:73: error: conflicting declaration 'long int val'
    sketch_may19a:72: error: 'val' has a previous declaration as 'long long int                val [6]'
    sketch_may19a:76: error: redefinition of 'byte bArray []'
    sketch_may19a:21: error: 'byte bArray [8]' previously defined here
    sketch_may19a.ino: In function 'void setup()':
    sketch_may19a:104: error: 'mpu' was not declared in this scope
    sketch_may19a:108: error: 'class RF24' has no member named 'payload'
    sketch_may19a:111: error: no matching function for call to         'RF24::openWritingPipe()'
    sketch_may19a.ino:111:25: note: candidate is:
    In file included from sketch_may19a.ino:12:0:
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:324:8: note: void     RF24::openWritingPipe(uint64_t)
    void openWritingPipe(uint64_t address);
    ^
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:324:8: note:   candidate         expects 1 argument, 0 provided
    sketch_may19a.ino: In function 'void loop()':
    sketch_may19a:120: error: expected initializer before 'int'
    sketch_may19a:139: error: too many initializers for 'int [8][4]'
    sketch_may19a:140: error: expected ',' or ';' before '}' token
    sketch_may19a:144: error: 'controlPin' was not declared in this scope
    sketch_may19a:144: error: 'muxChannel' was not declared in this scope
    sketch_may19a:144: error: 'channel' was not declared in this scope
    sketch_may19a:151: error: return-statement with a value, in function     returning     'void' [-fpermissive]
    sketch_may19a:153: error: expected ';' before 'i'
    sketch_may19a:155: error: 'mpu' was not declared in this scope
    sketch_may19a:156: error: invalid types 'int[int]' for array subscript
    sketch_may19a:157: error: invalid types 'int[int]' for array subscript
    sketch_may19a:158: error: invalid types 'int[int]' for array subscript
    sketch_may19a:159: error: invalid types 'int[int]' for array subscript
    sketch_may19a:160: error: invalid types 'int[int]' for array subscript
    sketch_may19a:161: error: invalid types 'int[int]' for array subscript
    sketch_may19a:163: error: 'recievers' was not declared in this scope
    sketch_may19a:164: error: no matching function for call to 'RF24::write(int&)'
    sketch_may19a.ino:164:20: note: candidate is:
    In file included from sketch_may19a.ino:12:0:
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:281:8: note: bool     RF24::write(const void*, uint8_t)
   bool write( const void* buf, uint8_t len );
    ^
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:281:8: note:candidate     expects 2 arguments, 1 provided
    expected primary-expression before ',' token

Please post the entire code (with the #include lines at the top).

Can you add line numbers to the code? As without them it is hard to determine which lines the errors refer to. Can you indent the code to make it more readable? Where are mpu and radio declared?

Also, as Spiked3 points out in his answer, the remapped values (of ax, az, gz, gy and gx) assigned to val are discarded, as you successively reassign val with new mapped values, without using the previous value. So only the remapped value of ay is tested. Is this intentional? Should the (val != prevVal) test not be repeated after each remapping?

Regardless, as you are a new user, welcome to SE Arduino, Frank..! :-) Please consider reading the tour page.

Replacing your original question with gibberish, once people have taken considerable trouble to answer it, is irritating. It is disrespectful of the effort they have put into their answers. -1 vote for doing this.

" considerable trouble to answer it"? i did not get no valuable answer if anything i waited my time even asking , so is ok it mutual we all waited our time XD......and btw not everyone wants their answer to be shared " I wanted the answer" if the community did not come up with the question i dont want to share my research

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


text:
How to send two different sets of int numbers over serial?
I have a project that require for the main computer to do most of the processing then for it to send the X and Y coordinates of this processing to the arduino. This at the time didn't seem very hard but now that I have started to dive into serial some more I am completely confused. All of the example I have seen for serial only consist of 1 set of numbers and rather confusing.
The Arduino code I kinda want to go like this
http://pastebin.com/aLJfEExw (I know this is probably completely wrong but I am pretty lost right now)
The Python code is this right now
http://pastebin.com/4aN4dnSC
If you guys could help explain this better for me it would be amazing. I understand that my code is probably wrong. So if you guys could provide an example of how to send the two different sets of int's it would be amazing. Because I am completely and utterly lost.

I wrote a communication protocol for arduino to node.js over Serial. I sent a buffer of bytes using Serial.write() and read it into a buffer. This allows you to send as many numbers as you want. To send long (16 bit) numbers, you simple need to loop over two at a time combining:
C++:
long int a = 0x9A44;
uint_8t b = ( a & 0xFF00 ) >> 8;
uint_8t c = a & 0x00FF;

Python:
a = ( b << 8 ) & 0xFF00 | c & 0x00FF

For a small bandwidth, this is more than sufficient.

I looked at your code, but the main problem seems to be that you have not defined the problem, and it is thus not possible to definitively answer.
The conventional solution to this would be to send 2 numbers with separator (usually space) followed by a newline. I know Arduino does not have an inbuilt function to do this, but you could write one. http://arduino.cc/en/Tutorial/SerialEvent shows one way this could be done.
Another approach is to send bytes (how long is each number? I would guess 16 bits) so you would send 4 bytes and on reception assemble them into 2 16 bit integers. Whether you need to ensure the data is synchronised depends on your problem. If you are sending continuous data this is essential, and you could use the kind of compelled sequence signalling you seem to be implying.
From the code it looks like you are sending from a Raspberry Pi. If I were doing this I would probably use I²C (at least over a short distance).


text:
Infrared interruption counter
Is it possible to create a infrared based interruption counter with an Arduino Uno? If yes, then what additional hardware would be necessary?

Can you please elaborate what does "infrared interruptions counter" mean?

You can use photo any transmissive or reflective photo interrupter (wire or TH) ideally with integrated Schmitt trigger and connect to IRQ driven AVR input to have quick trigger reaction. For production is cheaper photo interrupter with external Schmitt but for prototyping it does not matter.
Don't forget serial resistor to limit current.
Search e.g. "photo interrupter Schmitt" at Farnell.

It's exactly the same, which is easier. Thanks @TMa


text:
How to send data from an Arduino to PC, without using the Serial Monitor?
I have an analog sensor which I want to send data from my Arduino Certified Intel Edison to PC, without using a Serial Monitor and preferably putting the data into a text file.

What do you mean by "serial monitor"? The serial monitor is an application used to.. well, monitor the serial port. Once you can see that the data is correct, you should develop your own application to get the serial data and do what you need. Anyway you used wrong tags for your question (arduino-uno and arduino-mega) and.. The edison is an Intel board, not an Arduino..

I believe you are looking for something like the Telemetry library.
Full disclaismer : I am the author
It allows you to send string, numbers, arrays, sparse arrays through the serial port for instance. Each sent data has a label, called topic, that is used to identify it.
The Pytelemety command line interface then allows you to connect to the serial port, plot received data in real time, write parameters to reconfigure the arduino from the computer, etc.
Example of arduino code thats send an incrementing counter
#include <Telemetry.h>

Telemetry TM;
int8_t counter;

void setup() {
  TM.begin(115200);
  counter = 0;
}

void loop() {
  TM.pub_i8("count",counter);
  counter++;
  delay(10);
}

Overview of the CLI (Command-Line Interface)

Overview of a graph (not produced by the arduino program above)

Output to file is not implemented yet, although all received data is logged to a file (but this log also contains system information). However, this is an interesting feature, quite straightforward to implement, that I might add in coming days if you are interested.
Central documentation is available here.

This looks interesting, thanks for posting.

As the author of the arduino eclipse plugin I want to state that the arduino eclipse plugin has a 6 channel plotter/scope. Also Arduino IDE has a 1 channel plotter/scope. I know there are plenty other similar and advanced tools around. Because there are so many better alternatives to your proposal I'm downvoting this answer as to biased.

@jantje So many better alternatives to my proposal... ? So you haven't even tested what I propose, how can you know what is better exactly ? You have a similar project, that is cool I respect that. However, there are features in my repo that will be extremely hard or even impossible to find anywhere else. Like supporting array data for instance. Or being able to monitor in real time amount of received characters, corrupted frames, to detect issues on the arduino with undersized buffer, too high data throughput. And finally, this project is not tied to Arduino. Runs on Mbed too.

@jantje so please next time you decide to talk about an open-source project, please get informed first, test it and forge your own opinion. And if you find a better alternative, post it, simple as that. Let the people decide. But you should know that I'm not particularly fond of reiventing the wheel. If I developped this project, it is simply because I haven't found an existing solution that would satisfy me.

There are a couple of ways you can communicate between a "Arduino' and a "PC"*.
1)Serial communication.
A serial port on your system is created and a program that reads and writes to the serial port is used as communication.
A program that does this is the "serial monitor" which comes in many flavours.
In linux dumping serial monitor incoming data to a file is as easy as:
cat /dev/ttyS0> myFile

2)Bluetooth (LE)
Bluetooth is a low energy consuming protocol that is commonly used for communication between a PC and a "device". The LE uses even less energy.
I'm not aware of any "official Arduino" boards that contain the hardware for Bluetooth on board.
3) Network
Today network equals to WIFI of tcpip. These methods allow for huge distances between the pc and the device.
Of these methods the serial communication over USB is the best know because -in Arduino world- this method is most commonly used to upload the "sketch" to the  "Arduino". As such all hardware is commonly available.
*I put quotes around Arduino and PC because in perspective of this answer both arduino and PC are to be interpreted as a device containing a cpu.

You seem to be missing the point of the question, mixing up protocol with physical layer, while OP is clearly asking for a software alternative to the serial monitor.

@Overdrivr. I disagree on me missing the point of the question. OP states he does not want to use the serial monitor. OP does not state the serial port is a must. You make the assumption he wants to use the serial port, I do not. Personally I think OP is not aware the serial monitor is using the serial port. Nor is OP aware that there are other ways to communicate. But the way the question is asked the serial port is not a must. Therefore I included other protocols in my answer just as other serial port programs.

@Overdriver I guess you downvoted this answer as: "not related to the question". As stated in the comment above: I disagree.

Well, in this case we'll have to agree to disagree :) The question is not exactly clear either, so I don't see how we could do more.

Regarding our other conversation, I am very open to a friendly and constructive discussion on the chat or by email regarding your opinion on the Telemetry library, and what strongpoints/weaknesses you feel it has, if you're interested. Let me know.

I know, I'm late, but I recommend, using python, as I most always do. The serial module is part of the basic python installation

import serial

S = serial.Serial('/dev/tty/USB0', 115200, timeout=1)

S.write("Hello")
print S.readline()

Should echo Hello, if the arduino sketch replies all incoming data.
Very handy in combination with ipython, where one can interactively poke around with the serial connection object.


text:
Is supplying 5V from both external 5V and USB harmful?
I have an arduino nano which is powered through unregulated 5V (pin 27). For debugging purpose, I'd like to connect the USB port to my computer in order to use the Serial.Print function. The external 5V will stay connected. Will this cause damage ?
edit : I forgot to mention that the external power supplied to pin 27 is regulated with a switching DC-DC converter (measured 5.1V). Sorry it was not clear in my question.
Here is my circuit :

The switching regulator is not exactly the one in the schema.
Is using the circuit with the battery power supply + usb connection to my computer will damage something ?

No, it probably won't damage anything, as the PC's USB port is protected from overvoltage by the D1 schottky device on your arduino board.
Update, my previous answer contained the following paragraph, which is not related to your problem

But you should take care of some things.

Make sure, the voltage applied to your +5V-Net is regulated properly elsewhere. I.e. choose a laboratory PSU or another good
  source.
Avoid having both your PC and your 5V-supply connected to line voltage. Ground levels may differ due to Y-capacitors present in the
  switching PSUs. Those provide a AC voltage of half your line voltage
  to DC ground (only with 0.3 to 0.7 mA, but enough to cause
  disturbances on your signals at 55 volts in the US or 115 V in the EU)
If you have to use two switching PSU for both PC and arduino, provide an equipotential bonding between your PC's mass (e.g.
  VGA-port-screw) to your arduino's PSU's ground directly, to prevent
  leakage currents from the Y-capacitors wandering around in your
  circuitry.

Update according to your enhanced question
You are using a battery powered DC-DC supply for your Arduino. So, my previous notes do not apply to your problem.

5.1 V seem exact enough to drive your arduino safely. No need for additional stabilisation measures
D1 (see genuine arduino schematic) separates USB-Power from +5V and prevents current flowing in reverse direction over your USB connection.
Arduino circuitry and USB port have common GND so there are always well defined voltage levels.

In my opinion, there's nothing with your setup, which may harm your circuitry or your PC.
Depending on the maximum power of your DC-DC converter you may consider adding a fuse to protect converter and components in case of short circuit.

Since the external 5V supply is not regulated, it may cause some problems. It is possible that a small voltage difference will appear if and when the external voltage fluctuates from the 5V level. What you should do is short-circuit the 5V of the USB to pin 27.
And in general, add a 5V regulator circuit to feed the Arduino nano, like this one:

I don't think, shorting VUSB to +5V is a good idea. By this, you bypass D1. Hence, if +5V is slightly higher than VUSB, you may overload the regulators of your PC's USB port. The other thing is: @Masure did not write, the voltage supplied was unregulated. Hence, applying a linear regulator to an already regulated 5V will let the voltage drop below 4V, which is pretty useless, because all power will be drawn from USB then via D1.

@Masure wrote "...which is powered through unregulated 5V (pin 27)". That's why I suggested that

Yes, but Masure probably wanted to express, that by supplying the voltage via this pin, the builtin 7805 is bypassed. Otherwise Masure just had to connect the unregulated voltage to Vin. No need to apply another regulator.

Sorry guys, I edited my question because it was not clear. I'm powering the nano through pin 27 (which I call "unregulated 5v") with a regulated 5v source.


text:
Is Roboteq motor driver compatible with Arduino?
I'm planning use Roboteq motor driver for 24V brushed DC motor but I can't be sure that it's true or wrong. You know, Roboteq controller is too expensive and I don't want to spend money in vain. Have you any experience this controller? Are they compatible with Arduino?
http://www.roboteq.com/index.php/roboteq-products-and-services/brushed-dc-motor-controllers/mdc2230-detail  Roboteq Controller Link
I also think, Pololu RoboClaw driver. https://www.pololu.com/product/1499 I don't know is it enough for wheelchair. Because, I already have used Pololu VNH5019 and it is not enough. (synchronicity and noise problems etc.)
If you have any ideas, I will be glad. Thank you.

and i dont know this group suitable for this subject. If i wrong, correct me please.

This site is suitable for questions like this.

It is not directly supported. But the device description lists RS232 port that can be interfaced with an Arduino using a TTL to RS232 converter. The description also mentions "several Analog, Pulse and Digital I/Os which can be remapped as command or feedback inputs, limit switches, or many other functions" so it is totally possible to control the controller with an Arduino, but depending on the method you choose it may require some effort.


text:
Motor Shield not giving full power, LED DIMS
I have an Adafruit Motor Shield, the V1. I have been using this thing with my OPSEPP Uno and a stepper motor with no issues. (Powered by 12v DC wall wart [CASIO]).
My question, or issue, not sure yet, is this:
Why when I connect my motor directly to the 12v power supply it operates efficiently (for my purposes) and when I run it through my Arduino with the Adafruit Motor.h library does it not power the same.
Basically on direct connection it works fine, but I want to be able to regulate the connection and reverse it, change the speed, etc.
It is possible I am utilizing the library or the board wrong.
Can someone indicate why the power or, torque seems to drop when through the board. I have tried all KHZ all speeds etc, no way to get the same 12v power directly and modulate it?

According to the Adafruit page the V1 version of the shield is not as powerful as their V2 version.
Where is the 12V coming from to get to the shield? There isn't really 12V broken out on the Uno anywhere. If it comes from Vin then there is a 0.7V drop through the reverse polarity protection diode. Plus, the tracks on the Arduino board may not be thick enough to provide enough current.
It looks like the shield may take an external power source (it is hard to tell because they discontinued it). You could try using that.


text:
xBox receiver code output is scrambled
I'm running the following code:
#include <XBOXRECV.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
XBOXRECV Xbox(&Usb);

void setup() {
  Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }
  Serial.print(F("\r\nXbox Wireless Receiver Library Started"));

}

void loop() {
  Usb.Task();
  if (Xbox.XboxReceiverConnected) {
    if (Xbox.getAnalogHat(LeftHatY) == 0) {
      Serial.print(Xbox.getAnalogHat(LeftHatY));
    }
   Serial.print("TEST");
  }
}

After running the example that the library includes and a spin off I wrote for test purposes I keep getting random output, this is just some of it:

9�]==�=�~=���y��:.�:�:����9�=��������:�:�\=���^=�?�}�:^���:�|]=9�\=��������:�ܗ��.\�~=���

Have you changed the baudrate in the serial monitor to 115200?

Seems like wrong baud-rate. Change baud-rate in the Arduino IDE serial monitor.


text:
Standalone Atmega 2560 ISP program
First I need to say, I'm a complete electrics newbie, so I need your help.
I have got a standalone Atmega 2560, which I want to program. I connected MISO, MOSI, SCK, RESET, 5V and GND to an Arduino Uno.
In addition a 16MHZ oscillator is connected to XTAL1 and XTAL2 plus I pull all VINs of the Atmega with a 100nF to GND. Plus I connected a separate VIN and GND to the 2560.
I programmed the Arduino Uno as an "Arduino as ISP". Afterwards I connected the 2560 as mentioned above, changed the board to "Mega 2560" and tried to upload a sketch through the Arduino and I get the error message:
avrdude: stk500v2_getsync(): timeout communicating with programmer
Is there something I missed?
Cheers
jb

Did you connect nRESET to the nRESET of the Uno?

Yes, the Pin10 of the Uno is connected to RESET of the 2560 as decribed here: https://www.arduino.cc/en/Tutorial/ArduinoISP

A 16Mhz crystal needs some caps to. Also if the ATMega2560 is brand new, the fuses don't have the correct value yet. Most notably, it's set to run at 1Mhz. You have to run avrdude at a lower speed (-B10) to program the new fuses

What do you mean by "caps"? I have got an resistor of 1MOhm between both pins of the crystal.Yes the Atmega2560 is fresh out of the box. What fuses do I need to set?

I see, I don't have capacitors at the crystal (like the arduino mega 2560 R3 reference design). Could that be the cause it, doesn't work? @Gerben

Your error message indicates that the problem is between the computer and the Arduino-as-ISP sketch, not anything to do with the connections between that board and the target chip.

@jblaze the Arduino Mega uses a 3-pin oscilator, that has the capacitors build in. If you have the same part, than disregard what I said. If it's a 2 pin crystal you need to add (load) capacitors.

I have got a two pin crystal without capacitors. So I need to add two caps with 22pF each?

I double checked my crystal. It has capacitors built in (CSTCE16M0V53-R0).

I have a sketch that programs bootloaders. A side-effect of that sketch is it fixes up the "divide clock by 8" fuse.
It looks like the wiring will be the same, but cross-check on that page (scroll down to the part about programming the Mega2560).
Once a bootloader is installed you could use it, if you get an FTDI cable, or simply go back to using the ArduinoISP now that the fuse is fixed.

Thanks @Nick I was able to burn the bootloader to my 2560 with "Atmega_Board_Programmer":
Erasing chip .
Writing bootloader .
...
Written.
Verifying.
No errors found.
Writing fuses.
LFuse = 0xFF
HFuse = 0xD8
EFuse = 0xFD
Lock byte = 0xEF
Clock calibration = 0x89
Done.
Signature = 0x1E 0x98 0x01
Processor=ATmega2560
Flash memory size = 262144 bytes.
LFuse = 0xFF
HFuse = 0xD8
EFuse = 0xFD
Lock byte = 0xEF
Clock calibration = 0x89
Bootloader address = 0x3E000
Bootloader length = 7474 bytes.
Look good so far, but still I got "timeout" when uploading my own sketch. Did I miss something?

So far, so good. The chip is alive. :) Please describe your wiring for uploading your own sketch. I'm not totally sure that ArduinoISP supports the Mega2560 - it may do. Alternatives are cheap ISP programmers from eBay and other suppliers (like Adafruit or Sparkfun), get an FTDI cable and use that for serial programming using the bootloader, or use my sketch "Hex uploader" that uploads from an SD card. You need an SD card adapter for that, but they are around $15.

Yes I think so. My wires are: MISO-MISO, SCK-SCK, MOSI-MOSI, 5V, GND, and Pin10 Uno to Reset in Mega. // Tthe fuses should be OK with your sketch "Atmega_Board_Programmer"? I have this crystal (3 leg) with a 1MOhm resistor between both legs connected to XTAL1 and XTAL2: CSTCE16M0V53-R0. The middle leg is connected to GND. // Thanks for the hint with the programmer. I will search for one.

I was able to write my sketch to the Atmega2560 with a USBasp. But somehow the program does not work. Simple example: I have a small LED connected to Pin D2 (thats PE4 on Atmega2560). But when I do "digitalWrite(2, HIGH);" it is not working (it has been initialized before with "pinMode(2, OUTPUT);"). Anything I need to change in my sketch? Or do I need to change fuses?

I think you should start a new question now. You can upload sketches so this particular one is dealt with. As to why it doesn't "work" please make a post describing your setup, post the sketch, show your wiring, etc.


text:
Help with school project (Arduino GSM and Thermal printer)
I'm with some friends from my school and we have started to do a project where we send an SMS text message to our Arduino UNO (with GSM module), which then print the text message on a thermal printer(tx, rx). we've got huge problems, and now we can not figure it out anymore.
We started making a machine that will print out a message that is sent from any mobile.So I send an SMS message with my mobile to Arduino connected to a GSM shield (SIM800L). Then sends the Arduino the message to the thermal printer via TX RX, and then the message should be printed out.
We have spent two examples, GSM shield from Arduino itself, and thermal printer example from SparkFun.
These two files work fine separately, but when we try to merge them together, there is a compilation error.
The printer model from Sparkfun.

code:
#include <GSM.h>
#include <SoftwareSerial.h>

#define PINNUMBER ""

//Printer
SoftwareSerial Thermal(6, 7);
//GSM modul
//SoftwareSerial GSM(4, 5);

int heatTime = 10;
int heatInterval = 2;
char printDensity = 15;
char printBreakTime = 15;

// initialize the library instances

GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
  while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
  }
Serial.println("SMS Messages Receiver");

// connection state
boolean notConnected = true;

 Thermal.println("GSM initialized");
 Thermal.println("Waiting for messages");
 }
 /*{
 Thermal.begin(19200); // to write to our new printer
 initPrinter();
 }
 */
void initPrinter()
{
 //Modify the print speed and heat
 Thermal.write(27);
 Thermal.write(55);
 Thermal.write(7); //Default 64 dots = 8*('7'+1)
 Thermal.write(heatTime); //Default 80 or 800us
 Thermal.write(heatInterval); //Default 2 or 20us
 //Modify the print density and timeout
 Thermal.write(18);
 Thermal.write(35);
 int printSetting = (printDensity<<4) | printBreakTime;
 Thermal.write(printSetting); //Combination of printDensity and     printBreakTime

 }
 void loop() {
 char c;

 // If there are any SMSs available()
  if (sms.available()) {
  Thermal.println("Message received from:");

// Get remote number
sms.remoteNumber(senderNumber, 20);
Thermal.println(senderNumber);

// An example of message disposal
// Any messages starting with # should be discarded
if (sms.peek() == '#') {
  Thermal.println("Discarded SMS");
  sms.flush();
}

// Read message bytes and print them
while (c = sms.read()) {
  Thermal.print(c);
}

}

delay(1000);

}

And what actually are these "huge problems" that you have?

Had a look at that sketch - wont compile, basic stuff. Also, they are sending startup messages to the thermal printer that they should be sending to serial. The usual story - they are hacking up some sample code, and stopping in bewilderment at the very first problem they got. Or simply scrambling the sample code somehow and have no idea about C++ syntax.
Guys: get online and google "C++ tutorial".

Your sketch isn't that long. Please include it in the question using the code formatting markdown (four leading spaces). For help see Markdown help. You should be able to do this by selecting the code and pressing Ctrl+K to have your browser do this for you. Also copy and paste the error messages you get. we've got huge problems - we all have problems. Can you be more explicit? Please read How do I ask a good question?


text:
Can't get call / message from A7 gsm+gprs+gps module
I am making a project using arduino uno & A7 gsm+gps+gprs module.my circuit connection is like this:
A7 UTXD -> arduino RX
A7 RTXD -> arduino TX
A7 GND -> arduino GND
A7 pwr_key -> A7 VCC5.0

When i make call from my mobile to A7,it's ok.But i cannot get call/msg from A7.
Here is my code for making call:
char phone_no[]="phone_no";

void setup()
{
Serial.begin(9600);
delay(200);
Serial.println("AT");
delay(1000);
Serial.print("ATD");
Serial.println(phone_no);
//Serial.println(";");
delay(10000);
Serial.println("ATH");
}

void loop()
{
}

What can i do now??? Please help me to fix it.I apologize for my poor english.

What is the output returned from your ATD command? Any debug messages, errors, etc?

Don't use delay() like that. Instead you need to actively parse the returned text from the modem to understand what is happening with it.

Increase your second delay to 2000 (ie. 2 seconds).
delay(2000);

Using delays in place of proper serial processing is not good advice. Increasing delays to try and combat a basic failing of the entire methodology is even worse advice.


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

You can use the serial monitor in this way, as long as you ensure you do not send anything from the serial monitor out to the Arduino or peripheral, only to monitor data.
That said, if you try to send debug prints from the Arduino to the serial monitor, they will also be sent to the peripheral device, where there may be conflict, depending on the peripheral.
So you technically can, but it's not advised because there are several ways it can go wrong.
One alternative is to use the SoftwareSerial library to create a second, bit-banged serial port. Note, however, that this library can't operate at high speed (probably best to keep at 9600 bps) reliably.


text:
Connecting multiple component's VCC wires to one Arduino UNO R3 5V Pin
Apologies for the title gore and whether this seems to be a fairly basic question, I'm an Arduino noob.
I'm working on a wearable sensor system project at my university using an Arduino UNO R3 to handle all the sensors and power them. I'm currently powering the board with a USB connection and will be powering my components from the board's 5V pin as they can all safely operate with that voltage. The individual components do not exceed their I/O pins max current and their combined current usage doesn't exceed the boards maximum current.
My question comes in here: in the past if I've needed to connect multiple components to the ground and 5V pins of an Arduino board, I was always taught to use a matrix board to solder my component's 5V and GND wires to, where they could then be powered from two soldered wires from the microcontrollers 5V and GND pins.
Given that this is a wearable system, I would like to minimise any unnecessary hardware and so proposed to my supervisor that we cut out the matrix board and simply solder the VCC wires of the components together to one header pin which we can then plug into the 5V pin on the board to draw power. He strongly cautioned against this but wasn't able to provide a concrete reason as to why it would be a problem; as far as I can see the fundamental theory is the same and we are simply cutting out an unnecessary middle man.
Is there something I'm missing here or does this solution seem like it would work fine? Additionally, if this solution works for VCC, would the same principle work for sharing a grounded connection?

I would suggest you look for a supervisor who understands circuit theory. He/she may simply be sceptical about your soldering ability, but should be able to rationalise any valid concerns.

I don't see a problem with splicing together all the power pins. The problem here is that single pins don't connect very solidly to the Arduino's pin headers, and can easily come out. Especially with a wearable project. I'd suggest getting a cheap proto-shield, and soldering all the wires of the components to that (maybe add some hot-melt glue for strain-relief). Then you can just press the shield onto the Arduino, and get a very solid (and reliable) connection.

Assuming you have suitable soldering skill, there are some considerations when you solder lots of wires to one header:

Lots of wires means lots of weight. The strain of several wires may degrade your connection or header over time, especially for a wearable system, where I assume the parts would be subject to some movement.
The width of the connection when all the wires are soldered to it. It might touch adjacent pins, or lean on them, creating mechanical stress. Heatshrink or sleeving can help with the electrical contact issue, but won't remove the mechanical risk.
Lots of wires soldered to one point may make the system more difficult to service. Instead of desoldering the wire to one component, you have to either desolder them all, or cut the wire to the one suspect component and then solder together wire stubs later to replace it.

When referring specifically to power supply pins, you'll need to consider the peak current requirements of anything you power from it. Based on https://playground.arduino.cc/Main/ArduinoPinCurrentLimitations it seems like you shouldn't be pulling more than 200mA from the Vcc PIN. Check the maximum current draw of all of your components that you want to power, add them together, and make sure it's under the limit of the Arduino board.


text:
Can this work as a waterproofing method?
Im making my garden automated with temperature, humidity and soil temperature sensors. I want to be able to connect my Arduino Uno to a solar panel and keep it outside at all times. I dont want to have to remove it to water the plants. Could I cover it in clear nail polish to water proof it?

Is there a reason why you don't want to use a weatherproof enclosure?

need access to changing the pins where cables are connected.

@Tech2025 And how would nail polish be better at that?

Use a LilyPad? They are washable. Might need to cut the power when watering the plants?

If you don't varnish the pin headers, those won't be water-proof. Just get an enclosure. Unrelated; please don't use an UNO for this. An Uno just pisses away power with it's usb-to-serial chip and very inefficient voltage regulator.

Nail polish would work in general as a fair conformal coating. However, conformal coatings are not generally intended as waterproofing, but moisture or humidity resistance.
If you product is going to be regularly submerged or deluged with water, you are better off using a waterproof enclosure with a good watertight gland around the cable entrance.

Thanks. Im using the nail polish and it has worked great. No problems with anything. I've gone ahead and bought my self some Elegoo Uno's since they are so cheap and do the same.


text:
How well will the Arduino Uno survive in a vacuum?
Im doing some experiments with Pocketlab and Arduino, Vacuum will get to around -30inHg. I tried with my raspberry pi and it just kept dying everytime a vacuum was pulled. The only problem I can image is the arduino heating up.

http://www3.telus.net/schmaus2/vacf/vace1.html

This is a SE Electrical Engineer question.

Interesting question. You're right- heat is your enemy. Given the power dissipated by a Pi even when idle I'm not surprised it died. Most chips depend on convection to get rid of heat. A loaded Pi might require a (convective) heat sink and/or fan to keep it's core temperature down to an acceptable level, and that's at normal pressure and temperature. An Arduino -might- be able to work in a vacuum- it can lose some of it's heat through lead conduction- it'll only draw ~.25 watts normally vs 2.5 watts plus for a loaded Pi.
Ultimately it will depend on your application. If you have idle time when you can put the Arduino to sleep that will help keep it cool. If you have a conductive heat sink you can use then that would certainly help.

Also (assuming an Uno as it's tagged) the electrolytic capacitors on the board will most certainly pop. You'd want to replace those with tantalums at the very least.

Thanks, I've never had problems with capacitors in a vacuum before so I dont expect problems with that, I do expect the on board LED's to die though.


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

Please read our [ask] page and then edit your question.

what is a port whatever ?

your posting shows no effort to find the answer on your own.

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

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

You will find those pins on the rightmost header on the top edge of the board in this picture:


text:
Passive buzzer works with analogWrite(), but not with digitalWrite(). It also has constant static noise
I have a YL-44/MH-FMD passive piezo buzzer hooked up to an ESP8266/NodeMCU.
It's connected like this: Buzzer ---> NodeMCU
- GND ---> G
- VCC ---> 3V
- I/O ---> D2
This code makes a clear beep.
void loop() {
  analogWrite(BUZZER, 255);
  delay(100);
  analogWrite(BUZZER, 0);
}

This code makes a weird low clicking sound, no beep.
void loop() {
  digitalWrite(BUZZER, HIGH);
  delay(100);
  digitalWrite(BUZZER, LOW);
}

I have no idea why the second one doesn't work, as all the tutorials reference that one.
Also, why does the buzzer have a weird constant static noise and gets hot?
Am I doing something wrong in the wiring? I use no resistors, as the tutorials don't show that.

it is passive as you have in the title. it doesn't vibrate by itself. use tone() function. example is with basic examples in IDE

@Juraj Do you have any idea why there is static noise and it gets hot?

it is like a coil. under current it is pulled together. the click is the sound. 0 Hz :-) the noise is that it is not good to have it under constant current

@juraj Can you please explain how do I fix the constant noise? I don't see a way.

@Juraj I am using tone. It makes noise before and after the sound. There is no HIGH.

it is the WiFi. I set the pin as INPUT after the tone(). it makes it better

@Juraj Niiiiiiiice. Thank you so much Juraj, you are a hero! I am very new to this and you've helped me a ton.

YL-44 is active buzzer. you have something else

You haven't shown your setup() function. Did you forget to set the pin to OUTPUT when using it with digitalWrite()?

@Majenko I have this: #define BUZZER 4; and pinMode(BUZZER, OUTPUT); in setup.

To sound a passive buzzer, use Arduino tone() function. If you set the pin HIGH the piezo surfaces are pulled together (or pulled away). It is what makes one click but nothing more. To make a tone the input must oscillate at right frequency. PWM is one way how to do a beep. Use tone() function to generate tones of desired frequency.
Your analogWrite(255) is PWM at 1/4 of full on, because max analogWrite value on esp8266 is at default 1023. So it makes a nice beep with 255.
If you use a speaker or passive piezo with esp8266 you can expect noise generated by WiFi operations. I set the pin as INPUT after tone() to eliminate the noise.

But why does analogWrite work, and digitalWrite not?

analogWrite is PWM. oscillation or 'pulse train'. https://en.wikipedia.org/wiki/Pulse-width_modulation

On the ESP8266 analogWrite goes from 0 to 1023 not 0-255, so analogWrite(BUZZER, 255); is not the same as digitalWrite(BUZZER, HIGH);.  It's more like analogWrite(BUZZER, 63); on the Arduino.

@Majenko, thank you. I added it to answer

One thing to note about the digital write part.  While you have a delay between the HIGH to LOW, there is no delay to go back to HIGH (other than the time to leave loop and re-enter; which can be very small amount of time).
While on a slower processor (like AVR) this time maybe enough to cause some buzz (and consistent buzz), on the esp8266 its going to be fast enough that IO pin may not change state at all from LOW to HIGH.  On Esp8266, IO physical pin state is at a different frequency than instruction counts.  I believe its only 8 MHz.  Due to the time before a pin state change to take effect, changing back before it got around to changing the physical state may ignore that state change.  In the specific example, the LOW may get ignored often and you will have more random effects from that sketch.
Try adding another delay of 100 ms after setting the pin LOW.  this will simulate a PWM of 1000 ms on width of a 1100 ms duty cycle.
And even better, lower the delays by a factor of 100 (first being delay 10 ms, the new one a delay of 1 ms), you get a 10 (or so) Hz buzz.

Your code example does not work because you have a PASSIVE buzzer.  Your example would work okay with an ACTIVE buzzer.
With a passive buzzer you must turn on/off the digital I/O pin at the desired audio frequency.  Using the tone() API is an easy way to do this.
tone(BUZZER_PIN, 432, 250);   //  Play the buzzer at 432Hz for 250ms
Your buzzer is getting hot because it likely uses a PNP transistor to switch the coil on your buzzer module.  This type of transistor conducts when the input is LOW.  Some buzzer modules use NPN transistors and conduct when the input is HIGH.
To keep your buzzer from getting hot (and wasting current) set its input HIGH to turn it off (assuming it's using a PNP transistor which it sounds like it is based on your description)
digitalWrite(BUZZER_PIN, HIGH);
You'll need to do this after using tone() each time as it leaves the output pin LOW.
I recently created a discussion on this topic on AVRFreaks forum:
Buzzer Module gets Warm and Wastes Power


text:
Communicating with a 12V device?
I'd like to connect a 12V access control device to the Arduino, but I lack the understanding.
How can the signals from and to the device be done when they have different voltages?
I am afraid that the 12V would brick the Arduino.

Opto-isolators are your friend here...

D0 an D1 are weigand26 for external reader. it should be 5 V

@Juraj Interesting. I can't find info on this, and the vendor doesn't understand my question. I guess I'll just buy it and measure it myself.

where do you see that this version has D0 D1 pins?

@Juraj I'm sorry, I linked the wrong one. I fixed the link. Here it is here as well.

here is the info about weigand26  https://www.dhgate.com/store/product/rfid-proximity-entry-door-lock-access-control/168634282.html

@Juraj Hmmm, I don't see the D0, D1 pins on this one. Are they labeled differently?

down on the page is a table. it mentions it as option. it is input only for additional reader

@Juraj Yes, I saw the table. I was talking about the pictures, as they don't have those pins.

You could use an opto-coupler:

An opto-isolator (also called an optocoupler, photocoupler, or optical
isolator) is an electronic component that transfers electrical signals
between two isolated circuits by using light. Opto-isolators
prevent high voltages from affecting the system receiving the
signal. Commercially available opto-isolators withstand
input-to-output voltages up to 10 kV and voltage transients with
speeds up to 25 kV/μs.
A common type of opto-isolator consists of an LED and a
phototransistor in the same opaque package. Other types of
source-sensor combinations include LED-photodiode, LED-LASCR, and
lamp-photoresistor pairs. Usually opto-isolators transfer digital
(on-off) signals, but some techniques allow them to be used with
analog signals.

Here is an example schematic and packaging:

If you have a heavy load (although this does not seem to be your case) then they can also be used in conjunction with relays - here is an eight channel opto-coupler relay module board:

I see. So the way this would work is:

12V power to the access control.
5V power to the Arduino.
A wire from the D0, D1 pin on the access control, to the opto-coupler, and a wire from it to the Arduino in a digital pin.

Is this correct?

@Majenko Can you please tell me if my comment above is accurate?

An opto-coupler is like an LED on one side and like button on the other. You treat it pretty much like those items.

On the input side of the board, connect an Arduino output pin to the the input of one of the opto- or relay inputs. Connect the Arduino Ground (and +5v if the board calls for it) to the respective board inputs. On the output side of the board, If the access device just needs a contact closure, connect those two device connections to the Common and Normally Open contacts of the same opto where you connected the Arduino pin. Or if the device needs switched 12v, Connect +12v to the Common contact and the device's switched input to the Normally Open contact.

An octocoupler/relay is definitely the right answer when you're doing things properly, But sometimes you're running some quick tests and dont have one on hand, or you simply dont want to put together a complex circuit involving them.
Dont worry though, octocouplers are nice to have but they're not actually not needed for what you're trying to do.
I managed to interface with a 12V device using an ESP8266 (rated at 3.7V) with a couple of resistors. You can do exactly the same thing with an Arduino (which is actually a bit more rugged than the ESP8266).
----------------------------- 12V ground ------------|
                                                     |
--- 12V+ (signal) ---|                               |
                     |                               |
                     |                               |
              2K ohm resistor                        |
                     |                               |
                     |----------- 10K ohm resistor --|
                     |                               |
        |--------------------|                       |
        |            D1      |                       |
        |                    |                       |
        | <microcontroller>  |                       |
        |                    |                       |
        |                 G  |                       |
        |---------------------                       |
                          |                          |
                          ---------------------------|

The key thing here is that you can a use a 10K ohm "pull-down" resistor to get rid of excess voltage that would damage your microcontroller.
Its a one-way flow (read only from the keypad/card reader, and you cant write back) but this was still good enough for me. Hopefully it'll be good enough for you too!
Posting some images:

Your setup delivers 10 V to D1, which is too much. If you replace the 2 kΩ resistor by 33 kΩ, you get 2.8 V, which should be fine for a 3.3 V input.

Thank you for your answer.

Hi @EdgarBonet good point. At least thats what an online voltage divider calculator tells me as well. But the multimeter tells me a different story (see pic). I just couldnt get it to work by using the calculator alone. I think the reason why I'm getting 3.83V with the setup above is because of an internal pull-down resistor inside the ESP8266 NodeMcu microcontroller.  If its set at at 20K ohm then the resistance would be 12*10K/22K+10K=3.75V. Does that seem about right?

If you get 3.83 V, it is likely the effect of an ESD protection diode within the MCU. I wouldn't be comfortable relying on it.


text:
Can't make ultrasonic sensor work with motor controller
I just started using Arduino Uno, I can't get the ultrasonic to work ,with motor controller board, the output value is always zero.
Just to make sure I'm talking about the correct stuff:
I used this guide to try to make it work (look at the picture how did I connect the parts).
And this is my code:
#define trigPin A4//Attach Trig to port 8
#define echoPin A5//Attach Echo to port 7
#include <AFMotor.h>
//SMARS Demo 2 with Line sensor

AF_DCMotor R_motor(2); // defines Right motor pin
AF_DCMotor L_motor(1); // defines Left motor pin

int lmotorpin1 = 3;
int lmotorpin2 = 5;
int rmotorpin1 = 6;
int rmotorpin2 = 9;
int distancecm = 0;
//const int trigPin = 18;
//const int echoPin = 19;

// defines variables
long duration;
int distance;
void setup() {

  Serial.begin(9600); // sets up Serial library at 9600 bps

  //changes the following values to make the robot drive as straight as possible
  L_motor.setSpeed(200); // sets L motor speed
  R_motor.setSpeed(140); // sets R motor speed

  R_motor.run(RELEASE); //turns L motor on
  L_motor.run(RELEASE); //turns R motor on

  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
}

void loop() {
      Serial.println(trigPin);
    Serial.println(echoPin);
  distancecm = mdistance();
  if (distance < 5) {
    L_motor.run(BACKWARD); //moves motor L Forward
    R_motor.run(FORWARD); //moves motor L Forward
//    delay(1000);
//    L_motor.run(FORWARD); //moves motor L Forward
//    R_motor.run(FORWARD); //moves motor L Forward
//    delay(1000);
  }
  else {
    L_motor.run(FORWARD); //moves motor L Forward
    R_motor.run(FORWARD); //moves motor L Forward
  }
}

int mdistance()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  Serial.print("Duration: ");
  Serial.println(duration);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
}

As you can see I tried different pin numbers but it always 0 ....
what do you think can be wrong?
The motors work.
Motor Controller: KEYES L293D Motor Control Shield
Sensor: Ultrasonic Ranger V2.0

and the motors work? do you have the shield?

what sensor are you using?

I added the info in the main post at the end

the way the description of your problem reads is the ranger does not work with the motor controller, but it works without the motor controller ..... is that what is happening?

I didn't check it without the motor controller.

Pin numbers 0 and 1 are reserved for the Serial monitor which you're using on the board.
The function int mdistance() should return an integer.
You also didn't seem to set the motor pins as OUTPUT.

This seems to be more of a comment than actual solution to the OP's problem

Where is pins 0 and 1? I don't see why this is a problem because the motors are working.. The problem is the ultrasonic sensor.. Please explain yourself.

the motor number is not a pin number


text:
Arduino alternating between high and low signal without button press
I have connected my LCD with arduino uno. I am controlling contrast with the library and not the potentiometer. I am trying to read input from the button, it is connected to pin 9 of arduino. The resistor in the image is grounded, now arduino is not sensing signal from the button it keeps printing this even though in the timestamp below I have not touched the button. The resistor is 1k ohm.
20:03:30.808 -> button not pressed
20:03:31.816 -> button pressed
20:03:32.798 -> button pressed
20:03:33.827 -> button not pressed
20:03:34.821 -> button pressed
20:03:35.849 -> button not pressed
20:03:36.847 -> button not pressed
20:03:37.842 -> button pressed

#include <LiquidCrystal.h>

const int buttonNumPad1 = 9;

int buttonNumPad1State = 0;

int Contrast = 127.5;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  Serial.begin(9600);
  pinMode(buttonNumPad1State, INPUT);
  analogWrite(6, Contrast);
  lcd.begin(16, 2);
}
void loop()
{
  buttonNumPad1State = digitalRead(buttonNumPad1);

  if (buttonNumPad1State == HIGH){
    Serial.println("button pressed");
    lcd.setCursor(0, 1);
    lcd.print("pressed");
  } else {
    Serial.println("button not pressed");
  }

  lcd.setCursor(0, 0);
  lcd.print("Hello");

  delay(1000);

  lcd.clear();
}

Top view of my breadboard

is it something related to? https://docs.arduino.cc/learn/microcontrollers/digital-pins

Input pins make extremely small demands on the circuit that they are sampling, equivalent to a series resistor of 100 megohm in front of the pin. This means that it takes very little current to move the input pin from one state to another

is it a breadboard with the power rails separated in the middle?

@Juraj yes it is a breadborad with power rails separated in the middle

Then have you connected these two parts of the power rail? The described behavior suggests that you have a floating input pin. Maybe the resistor isn't actually grounded

@chrisl do you want me to connect both power rails? I uploaded a top view of my breadboard(note the lcd is just kept on the breadboard and it is not connected)

@chrisl also which parts of the rails are you talking about

What Juraj meant with "separated in the middle" was, that in your top view of the bread board the power rails are separated not only between top and bottom of the image, but also between left and right. Then you would need a connection at the middle, connecting the left part of the row with the right part. Or you could try to put the button and its connections also on the left side of the board.

@chrisl do you mean something like that(added a picture in the question)

I tried this and then also this https://imgur.com/a/JRLFEMt but still it arduino sends random high low values

Regarding the rail test, they're more or less asking you to do this. Either those two points will test as continuity (or near-0 ohms) or it will be open.

Look at this breadboard image:

I have marked the power rail connections with green and red lines. Do you see, that they are not connected in the middle, right there where I've drawn the blue dotted line. Often the power rails of breadboards are not connected internally at that place. If that is the case for your breadboard you would need to bridge that gap with some jumper wires.
If you don't do that, your button and pulldown resistor are not connected to anything but the digital input pin. So there is nothing setting the state of that pin (HIGH or LOW). Its just like you simply connected a wire to the digital input pin. And that's called a floating pin. It is not actively pulled in one direction, so any noise, that comes by, might change the state of the input pin.
Make sure your button and pulldown resistor are actually electrically connected to ground. Bridge any gaps in the power rails, that your breadboard might have.