text:
Cannot display a chr string using Wire.read() and u8g2.drawStr()
I'm still getting myself acquainted with C++, so I expect this is a very basic issue I'm facing. I've got an OLED screen connected to a Teensy LC and can display text on it just fine. The Teensy receives bytes via I2C, and I want to reassemble those bytes into strings and display them on the OLED.
My relevant code:
#define I2C_ADDRESS 4
char buf[16];

void setup(void) {
  Serial.begin(9600);
  Wire.begin(I2C_ADDRESS);
  Wire.onReceive(receiveData);
  u8g2.begin();
}
void loop(void) {
  // U8G2 setup code snipped
  // This line doesn't output anything on the screen:
  u8g2.drawStr(0, 0, buf);
  // This line does:
  u8g2.drawStr(0, 20, "Foobar!");
  u8g2.sendBuffer();
  delay(1000);
}

void receiveData(int byteCount){
  Serial.print("Data received: ");
  int i;
  for (i=0; i<byteCount; i++)
  {
    buf[i] = Wire.read();
    Serial.println(buf[i]);
  }
  buf[i] = '\0';
  Serial.println(buf);
}

In the receiveData() function, the Serial.println() within the for loop prints out each letter of the payload as it's received, one after the other - but the Serial.println() below the for loop, which in my estimation should print out the whole message, prints out a blank line. I presume that's related to the fact that the received string doesn't show up on the OLED display.

Add a Serial.print(byteCount); as first line of receiveData . Perhaps that gives a hint.

This is kind of convoluted to put as a comment and it is sort of an answer, so I'm making it an answer.  Just to warn you, I have not tried to compile any of the code snippets here.
Wire.onReceive(receiveData); registers your function so that it can be later called back in the context of the interrupt service routine used for handling I2C ("Wire") data.  Or at least this is how it usually works.  So when your receiveData function is running you are in the middle of handling an interrupt associated with the I2C peripheral.
Using Serial.print(), .println(), .write(), and many other things, including non-serial related things like delay() inside of an interrupt service is usually a no-no.  On the AVR Arduino core, if the outbound serial buffer happens to fill, your code will deadlock with the underlying .write() waiting for there to be room in the outbound serial buffer and the serial transmit interrupt waiting for .write() to get done waiting for it.  I don't know how the Teensy LC and its MCU are configured, whether or not it prioritizes interrupts, etc, but it is likely that you're still not supposed to call functions like these inside the interrupt context.
There's really not a lot you're supposed to do in an ISR except:

communicate with hardware (which is being done for you here)
manage the non-volatile variables that belong to the ISR itself.
set global volatile qualified variables to communicate with the main line of execution.
call functions that have no shared state with the main line of execution.
call functions that have shared state but are carefully designed to be called from both ISR contexts and main line of execution.

That said, I don't know precisely why you're seeing what you're seeing, but I'm not overly surprised either.  The above may be related to it, but I haven't drawn that connection yet.
The way you currently have receiveData, it may overflow buf.  All that's required for that is for the sending side to send more than 15 bytes.  Any number of weird things can happen if you manage to overflow.  Is it related? Maybe.
For communicating between the receiveData running in the ISR context and the main line of execution in loop, buf should be volatile qualified.  Without that the main line of execution can behave as though buf never changes after it is first seen.  Because of how you're using it and familiarity with the compiler, I'm going to guess that this isn't manifesting as a bug, but I don't know that; it could be related.
So I'd recommend updating something like your buf declaration to volatile qualified and removing the Serial print calls from the receiveData function, and preventing overflow:
volatile char buf[16];

/// ...

void receiveData(int byteCount){
  static const size_t room_for_non_null_chars = sizeof buf - 1;
  const size_t read_amount = min(byteCount, room_for_non_null_chars);

  int i;
  for (i = 0; i < read_amount; ++i) {
    buf[i] = Wire.read();
  }

  buf[i] = '\0';
}

If it weren't for the fact that we need to read into something volatile qualified the above loop could really just be a read call taking the buffer and size.  You can see that's updated to prevent overflow.
Part of loop would then become something like:
void loop() {
  char non_volatile_buf[sizeof buf];
  size_t write_index = 0;

  noInterrupts();
  for (char c: buf) {
    non_volatile_buf[write_index++] = c;
  }
  interrupts();

  // U8G2 setup code snipped
  // This line doesn't output anything on the screen:
  u8g2.drawStr(0, 0, non_volatile_buf);

  // ...

We're turning off interrupts while copying the data into a local buffer so that the onReceive handler cannot interrupt the use of the buf, updating while you're in the middle of using it in drawStr.
If you care about losing messages there's more that would need to be done.  Surrounding what to do if you've got a call to receiveData while there's a message currently in buf.  The way the above is written it just drops whatever is in there whether it's been seen by loop() or not.

I didn't get a load of sleep last night but I finally figured it out, thanks to timemage's post. I'm concerned that my solution is hyper-specific, but I'd rather share it to save someone the trouble in future.

timemage was right in that the buffer should really be volatile qualified and that as little processing as possible should happen in what I now understand is an ISR. I couldn't get their code to work, but I eventually stumbled on i2c_t3, an enhanced I2C library specifically for Teensy 3.0/3.1/LC. Looking at the library's code and especially its basic peripheral example, it looks like it implements similar techniques to those timemage recommended.
The other thing I didn't consider was the way the controller was communicating. I was using the smsbus2 Python library, and at one point I changed the address offset from 0x00 to 0x01. This mysteriously seemed to make the Teensy code work, but I don't know why!

data = [1, 2, 3, 4, 5, 6, 7, 8]
bus.write_i2c_block_data(0x21, 0x01, data)

Lastly, from reading forum posts about saving data to variables from I2C, it looks like a lot of quite simple code that does work on other Arduino devices doesn't work on the Teensy.1 I'd have to get an Arduino device to test this theory, though.

Because I'm a bad scientist, I haven't checked whether any of my original code or timemage's improved code works when I offset the address in the smbus2 code. But for what it's worth, these are the things I did to solve my problem!

See for example: https://forum.arduino.cc/index.php?topic=570597.0; https://forum.arduino.cc/index.php?topic=619902.0.


text:
Controlling a flat brushless DC motor with integrated speed controller
I have recently purchased the Brushless DC-Flat Motors Series 2610 from Faulhaber and I am honestly new to this type of motor as it’s pins are not like any other I have used before. I would appreciate any help on how to connect and code this motor to rotate on an arduino using the integrated speed controller in the motor.

Everything you need to know is in the datasheet. The built in speed controller uses the industry standard 0-10V input signal to control the speed.

What exactly is your problem with it? Have you read the datasheet? Is there something, that you don't understand?

I read the data sheet, but I’m not very good with motors and arduinos so didn’t really know where each pin should be connected to and how to command it to rotate in varying speeds. I apologize for the lack of knowledge and if my question is stupid

You need a circuit to generate 0-10V analogue voltage. You can probably find a shield to do it.

source: Stack Exchange

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

sort: votes


text:
FG Frequency output
I have bought the Brushless DC-Flat Motors Series 2610 and Pin number 6 is called FG which is defined as frequency output. I have plugged this pin into the Arduino in A0 and I have tried displaying the outputs. The outputs is either 0 or 1023 and I am not sure how I can convert this to angular speed or RPM. Any help will be appreciated

Without looking at the motor, I'm pretty sure, that this is not an analog output. Almost certainly it is a digital pulse output. So it will output a specific number of pulses per revolution of the motor (Thus you can get the RPM by counting the pulses per time interval). You get 0 and 1023, because you are just reading the HIGH and LOW signal parts of the pulsed signal.

That will be a hall effect output giving you a square wave, the frequency equal to (or proportional to) the RPM.

in the manual it says "6 lines per revolution" does this mean that I need to observe 6 ones in a row for a revolution to be considered? or is a pulse a 0 followed by a 1 then a 0. Sorry if I'm asking basic questions

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


text:
Arduino uno R3 Not detected in windows 7 64
i have 3 arduino uno r3 out of which 1 is not detected in any of my Pc's,
i was working and must have accidentally short circuited some how , the power led and 5v regulator on uno is burnt out but,i replaced both of them, but then again, windows was unable to detect it,but if i remove and plug the atmega328p in another uno it works fine.am able to upload sketch and do work,and put back the atmega in the non functioning uno.
the uploaded sketch runs fine but not detected, its kinda tiring removing the atmega and uploading a sketch through another uno and putting it back and the pins are so delicate each time i pull carefully somehow the pins getting bent.
i also checked other components on the board but everything seems to be in good shape and not heating or anything, hope some has better solution...

It's dead, Jim.  A common issue when you short circuit seems to be that the ATMega16U2 chip dies in some way and the USB never works again.

Maybe you can check the answer in the following question to prevent it next time: https://arduino.stackexchange.com/questions/43188/burning-arduinos-one-after-another/43190#43190

hi, i tried uploading the sketch using an FTDI breakout board with 5V selected connecting as
GND       GND
CTS       not connected
VCC       5V
TxD       D0 (RX)
RxD       D1 (TX)
DTR       To RESET  after hitting upload the progress bar gets struct at 100% after taking too long i get this error :programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x83
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x83
goes about 10 attempts, is there anything wrong in my connection?

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


text:
How to get the angle from vertical window blinds
How can i know the angle of the vertical window blind by placing a small sensor on one of the blind slat
i am trying to make a arduino/esp8266 controlled window blinds, the controlling can be easily achieved in horizontal blinds, but my apartment has a vertical blind which are not interconnected at the bottom
Tried so far:

open and close based on time which it takes to open and close, but it keeps drifting over time
Cannot use light sensor to sense the ambient light, does not give correct information (day and night)
Tried to put a potentiometer on top of one of the blind slat ( no enough room to place things there, potentiometers have more friction)

any suggestions for angle sensor ?

Is this the sort of bind where you open / close or by turning a stick, or by pulling a string? Could you just start it in a known position, and let it keep track of where it is by how far it has turned - use a stepper motor so that you have predictable control of the movement.

A hall-effect sensor, plus a small magnet attached (glue?) to the outside edge of one slat ought to be able to tell you the strength of the magnetic field, and thus the distance of the magnet from the sensor. From that, given that the rotation is with a fixed radius, you can deduce the angle while introducing zero additional friction.
Edit:
I had imagined something like:

However, looking again, this introduces difficulty in detecting the 90deg position, where the magnetic flux lines are exactly parallel to the hall-effect sensor plane.
If you experiment with this enough, you may be able to get repeatable values from the sensor to know the angle of the blind slats.
Edit 2:
The timing measure you noted in your question could also be a possibility. If you could use a microswitch or photo-interrupt sensor on the extreme ends of travel (0deg and 180deg), so that any time those extreme ends are detected, you can eliminate drift.

Ya this sounds to be a good idea, Actually I can have a small magnet fixed to the bottom end of one of the slat, and place the hall effect sensor below it fixed to the base( i have some room below the slats for my window) , do you have good suggestions for cheap hall effect sensors  with rotating magnetic field .. Thanks @ Jose

just to know, does the hall effect sensor give you absolute value even when it loses power

If the sensor loses power, it doesn't work. If you mean, does it have to start from a "known value" after the power returns, then the answer is yes, it gives an absolute value. It measures magnetic flux through the plane of the sensor, which is not dependent on any initial position when power is first applied.

i was thinking this way http://imgur.com/a/whos7

A hall-effect sensor isn't going to work that way. It detects/senses magnetic flux "through" it, so simply rotating the magnet without moving it in the X or Y position relative to the sensor will not be detectable.

a cheap "tilt switch" (with a roller ball) could discriminate the extreme vertical state polarity...

@josecanuc, and forgot to mention, the other issue is that, these slats move like a pendulum (they are not steady in their axis)  when tried to change the angle, for this i can use a small magnet at the top of the slat holder and place a hall effect sensor on the window frame to eliminate the oscillation

@dandavis .. HOW ??  could you elaborate it

@SaiGanesh Given these difficulties, I would suggest to look for another place to put the sensor. Surely there is a cable/rope/chain that is used to adjust the angle -- can you put a potentiometer on the axle that is turned by that cable?

@josecanuc , thanks for the idea, while i was working with some GY-271 Compass modules, i figured this would be the perfect solution for my window blinds. I had my compass module stick to one of the window slat (perpendicular) and pulled some ultra thin copper wires to my board .. works Perfect now

How to get the angle from vertical window blinds

vertical blinds have by definition a 90degree angle.
unless "angle" means something else to you.

I believe each strip can rotate around the vertical axis, though...

each strip has ~180 degrees rotation angle along its own vertical axis

In that case, tie a weighty item at end of a rope and wind it over the shaft of a potentiameter. you can measure that potentiamiter's resistance by charging up a capacitor with it, or via an adc.

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


text:
Serial monitor and plotter coming up blank
I'm looking to calibrate a load cell and for some reason, when I open both the serial monitor and plotter, they both come up blank. My plotter is set to the corresponding 9600 baud, however, this doesn't seem to change anything.
here is the code below:
#include "HX711.h"
#include <Servo.h> // Include the Servo library

#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define LOADCELL_DOUT_PIN  3
#define LOADCELL_SCK_PIN  2
int servoPin = 5; // Declare the Servo pin

HX711 scale;

Servo Servo1; // Create a servo object
float units;

void setup() {
  Serial.begin(9600);
  Serial.println("HX711 scale demo");

  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");

  Servo1.attach(servoPin);  // We need to attach the servo to the used pin number
}

void loop() {
  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();

 Serial.print("Reading: ");

 units = scale.get_units(10);
     if (units > 3.35 && units < 3.45)
     {
       Servo1.write(180);
       delay(1000);
       Serial.print("Success. Door is now OPEN!");
     }

       else
     {
       Servo1.write(0);
       delay(1000);
       Serial.print("Success. Door is now CLOSED!");
     }

}

here are screenshots of the potter and monitor:

Have you tried a simple serial test program at different baud rates? Several of my clones only work at 115200.

I don't think you can use both serial monitor and serial plotter. They use the same port. Use one at the time.


text:
Two function Reset button - long/short press
I am trying to make a circuit using an ATmega328, that has a reset button that behaves like many consumer devices:

A short press just restarts the micro-controller
A long press (5 seconds?) causes the settings to be restored to default

What is the best way to achieve this behaviour? I imagine it is going to require two pins? Can it be done just using passive components?
Thanks!

I wouldn't use the reset pin but a regular pin. Time how long button is pressed. Then, when released optionally restore the settings and reset the board using software. That way you don't have to experiment with different resistor and capacitor values, and don't have to work around bootloader delays.

I am personally more inclined to use the reset pin because it re-initialises the hardware. It should also always succeed - there is always a risk of a bug in software and not resetting correctly.

Using the Watchdog to reset the device is pretty reliable.

It can be done with one button, one resistor, one capacitor and one GPIO pin (in addition to the RESET pin):

simulate this circuit – Schematic created using CircuitLab
Pressing the button causes a LOW pulse on the RESET pin (in the exact same way as the USB interface does).
During your startup procedure you read the GPIO pin you have chosen. If it's LOW the button is still being pressed in. If it's HIGH it has been released.
If you are using an Arduino with the normal bootloader the bootloader itself imposes a 2 second delay (which may be enough for you). Alternatively you will need to have your own delay in your program before reading the button to ensure that you have plenty of time to release the button so you don't accidentally reset your settings.

Thank you for the very complete answer. Exactly what I was hoping for!

You can set the RSTDISBL (bit 7 on the HIGH fuse) to disable the external reset and use the reset pin as PC6 to manage the reset behavior from your program.

The second part is to capture when reset button is pressed: put some code in the ISR for PCINT1 handler when the pin changes (PCINT14 pin function). If you are programming an Arduino board, the reset button is pulled up (press becomes LOW and release becomes HIGH).
Detecting long press or short press is a timer affair. According to your requirements, you will restore some EEPROM values or external state to factory defaults before the microcontroller resets with a long press.
This C snippet will reset the microcontroller after the short or long press (watchdog timer feature):
#include <avr/wdt.h>

    // ...
    wdt_enable(WDTO_15MS);
    for (;;) {}

Use a state machine to detect thee king presses. Once done, you can either trigger a hardware or a software reset, or to simulate one by jumping to the reset vector - you will need to write the code to support that, like an explicit initialization of variables, etc.

Notice that jumping to the reset vector does not initialize the hardware to its normal power-on state. It does however initialize the memory (data and bss sections), as this is performed by the C runtime before it calls main(). A hardware reset can be triggered by configuring the watchdog with a very small timeout.


text:
Help understanding SoftwareSerial recv() and PCINT
In the SoftwareSerial library, I see the beginning of recv() as follows
void SoftwareSerial::recv()
{

#if GCC_VERSION < 40302
// Work-around for avr-gcc 4.3.0 OSX version bug
// Preserve the registers that the compiler misses
// (courtesy of Arduino forum user *etracer*)
  asm volatile(
    "push r18 \n\t"
    "push r19 \n\t"
    "push r20 \n\t"
    "push r21 \n\t"
    "push r22 \n\t"
    "push r23 \n\t"
    "push r26 \n\t"
    "push r27 \n\t"
    ::);
#endif

  uint8_t d = 0;

  // If RX line is high, then we don't see any start bit
  // so interrupt is probably not for us
  if (_inverse_logic ? rx_pin_read() : !rx_pin_read())
  {

This comment seems to be testing for if the pin change was from low to high, or high to low.  If you are using inverse logic - where the line is held high, and start bits are low - then a call to rx_pin_read() should return 0.
This doesn't seem correct.  In inverse logic the line is held high and a drop indicates a start bit.
Is the SoftwareSerial library ignoring the start bit and relying on some kind of return to zero break between the start bit and any subsequent bits?
It seems like it can't handle start bits followed by high bits since there would be no change in the pin state.

"If you are using inverse logic - where the line is held high, and start bits are low" No, that's normal logic for a UART.

This doesn't seem correct. In inverse logic the line is held high and a drop indicates a start bit.

No, in inverse logic (for a UART) the line is held LOW and a rise indicates a start bit. The diagrams you show in your question show that UART communication normally is HIGH with LOW for a start bit.

It seems like it can't handle start bits followed by high bits since there would be no change in the pin state.

The PCINT is only used to identify the falling (or rising in the case of inverse logic) edge of the start bit. From then on it samples at pre-defined periods to read each bit. Accurate timing is needed for that, so assembly code is used to give precise delays (see tunedDelay()). Once the whole 10-bit packet has been received the interrupt handler finishes and control is returned to the main thread again. The PCINT is then free to look for the next start bit.

But, it doesn't look for a start bit.  It just ignores the start bit and hopes that the second bit has a rising edge.  There's no tunedDelay() to wait for the next bit after the start bit.

No it doesn't. It uses the falling edge of the start bit to begin receiving. That is the ONLY edge that is ever looked at. It then immediately delays for half a bit to centre the readings properly, then reads 8 bits with a full bit delay preceding each read. Have you actually read and understood the ::recv() function?


text:
someone can help please? am getting an error saying expected } at the end of input
    //set initial values
int x = 0; // set initail zero value for the counter
int preE = 512; // set initial value for light intensity in east direction
int preW = 512; // set initial value for light intensity in west direction
int predtime = 512; // set initial value for delay time
int pretol= 512; // set initial value for tolerance value
void setup() {
  Serial.begin(9600); // set the baud rate for the serial monitor

  // first set the relays off
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  digitalWrite(7,HIGH);
  digitalWrite(8,HIGH); // began the loop
}

  void loop()
  {
    // Read the first reading

    //read the east LDR
    int E1 = analogRead(5); //read the west LDR
    int W1 = analogRead(4); // read the delay time potentiometer
    int dtime1 = analogRead(1);
    //read the tolerance potentiometer
     int tol1 = analogRead(0); // Check if the readings reasonable, otherwise set them to previous ones.

if (E1 < 10 || E1 > 1000 )
{
  E1 = preE ;
  }
  if (W1 < 10 || W1 > 1000 )
  {
    W1 = preW ;
    }
    if (dtime1 < 10 || dtime1 > 1000 )
    {
      dtime1 = predtime ;
      }
      if (tol1 < 10 || tol1 > 1000)
      {
        tol1 = pretol ;
        }
        delay(100); // delay for one 0.1 second and take the next reading

        int E2= analogRead(5);
        int W2= analogRead(4);
        int dtime2= analogRead(1);
        int tol2= analogRead(0);
        if (E2 < 10 || E2 > 1000 )
        {
          E2= preE ;
        }

if (W2 < 10 || W2 > 1000 )
{
  W2= preW ;
  }
  if (dtime2 < 10 || dtime2 > 1000 )
  {
    dtime2= predtime ;
    }
    if (tol2 < 10 || tol2 > 1000 )
    {
      tol2= pretol ;
      }
      delay(100); // delay for one 0.1 second and take the third reading

      int E3= analogRead(5);
      int W3= analogRead(4);
      int dtime3= analogRead(1);
      int tol3= analogRead(0);
      if (E3 < 10 || E3 > 1000 )
      {
        E3= preE ;
        }
        if (W3 < 10 || W3 > 1000 )
        {
          W3= preW ;
          }
          if (dtime3 < 10 || dtime3 > 1000 )

{
  dtime3= predtime ;
  }
  if (tol3 < 10 || tol3 > 1000 )
  {
    tol3= pretol ;
    }
    int E4 = analogRead(5);
    int W4 = analogRead(4);
    int dtime4= analogRead(1);
    int tol4= analogRead(0);
    if (E4 < 10 || E4 > 1000 )
    {
      E4= preE ;
      }
      if (W4 < 10 || W4 > 1000 )
      {
        W4= preW ;
        }
        if (dtime4 < 10 || dtime4 > 1000 )
        {
          dtime4= predtime ;
          }
          if (tol4 < 10 || tol4 > 1000 )
          {
            tol4= pretol ;
            }

delay(100);
int E5 = analogRead(5);
int W5 = analogRead(4);
int dtime5= analogRead(1);
int tol5= analogRead(0);
if (E5 < 10 || E5 > 1000 )
{
  E5= preE ;
  }
  if (W5 < 10 || W5 > 1000 )
  {
    W5= preW ;
    }
    if (dtime5 < 10 || dtime5 > 1000 )
    {
      dtime5= predtime ;
      }
      if (tol5 < 10 || tol5 > 1000 )
      {
        tol5= pretol ;
      }
      delay(100);
      int E6 = analogRead(5);
      int W6 = analogRead(4);
      int dtime6= analogRead(1);
      int tol6= analogRead(0); if (E6 < 10 || E6 > 1000 )
      {
E6= preE ;
}
if (W6 < 10 || W6 > 1000 )
{
  W6= preW ;
  }
  if (dtime6 < 10 || dtime6 > 1000 )
  {
    dtime6= predtime ;
    }
    if (tol6 < 10 || tol6 > 1000 )
    {
      tol6= pretol ;
      }
      delay(100);
      int E7 = analogRead(5);
      int W7 = analogRead(4);
      int dtime7= analogRead(1);
      int tol7= analogRead(0);
      if (E7 < 10 || E7 > 1000 )
      {
        E7= preE ;
        }
        if (W7 < 10 || W7 > 1000 )
        {
          W7= preW ;
          }
          if (dtime7 < 10 || dtime7 > 1000 )

{
  dtime7= predtime ;
  }
  if (tol7 < 10 || tol7 > 1000 )
  {
    tol7= pretol ;
    }
    delay(100);
    int E8 = analogRead(5);
    int W8 = analogRead(4);
    int dtime8= analogRead(1);
    int tol8= analogRead(0);
    if (E8 < 10 || E8 > 1000 )
    {
      E8= preE ;
      }
      if (W8 < 10 || W8 > 1000 )
      {
        W8= preW ;
        }
        if (dtime8 < 10 || dtime8 > 1000 )
        {
          dtime8= predtime ;
          }
          if (tol8 < 10 || tol8 > 1000 )
          {
            tol8= pretol ;
            }

delay(100);
int E9 = analogRead(5);
int W9 = analogRead(4);
int dtime9= analogRead(1);
int tol9= analogRead(0);

{
if (E9 < 10 || E9 > 1000 )
{
  E9= preE ;
  }
{
  if (W9 < 10 || W9 > 1000 )
  {
    W9= preW ;
    }
{
    if (dtime9 < 10 || dtime9 > 1000 )
    {
      dtime9= predtime ;
      }
{
      if (tol9 < 10 || tol9 > 1000 )
      {
        tol9= pretol ;
        }
        delay(100);
        int E10 = analogRead(5);
        int W10 = analogRead(4);
        int dtime10= analogRead(1);
        int tol10= analogRead(0);

          if (E10 < 10 || E10 > 1000 )

        {
E10= preE ;
}
{
if (W10 < 10 || W10 > 1000 )
{
  W10= preW ;
  }
  {
  if (dtime10 < 10 || dtime10 > 1000 )
  {
    dtime10= predtime ;
    }
    {
    if (tol10 < 10 || tol10 > 1000 )
    {
      tol10= pretol ;
      }

      //Average the ten readings

   int E=(E1+E2+E3+E4+E5+E6+E7+E8+E9+E10)/10;

   //light intensityin east
   int W =(W1+W2+W3+W4+W5+W6+W7+W8+W9+W10)/10;

   // light intensity in west
   int dtime=(dtime1+dtime2+dtime3+dtime4+dtime5+dtime6+dtime7+dtime8+dtime9+dtime10)/10;

   int tol = (tol1+tol2+tol3+tol4+tol5+tol6+tol7+tol8+tol9+tol10)/10;// tolerance value
   int delaytime = (dtime *10);// increase the delay by magnitude of 10
   int tolerance = tol / 40;

   // display the readings through serial monitor
   Serial.println("Light intesity in the East");
   Serial.println(E);
   Serial.println(" ");
   Serial.println("Light intesity in the west");
   Serial.println(W);
   Serial.println(" ");
   Serial.println("delay time");
   Serial.println(delaytime);
   Serial.println(" ");
   Serial.println("tolerance");
   Serial.println(tolerance);

   //check the differenc and open the coresponding relays

   // check the diffirence of light intensity in east and west
   int diff = E - W;

   // check if the diffirence is in the tolerance else rotates the motor
   {
   if (-1*tolerance > diff || diff > tolerance)

   {
    if (E > W)// check if light intensity in east is greater than in west

    {
      if ( x <30)// check counter to ensure the motor does not run infinitely

    {
      Serial.println("Turn motors towards east");

   digitalWrite(7, LOW);// Turn ON Relay 1

   delay(2000);

   digitalWrite(7,HIGH); //Turn OFF Relay 1
   ++x;
   }
   }
   //check if light intensity in west is greater than in east
   else if (W > E) { if (x > -30)

   {
    }
    }
   }

Serial.println("Turn motor toward west");
digitalWrite(8, LOW);// Turn ON Relay 4
digitalWrite(9, LOW);
delay(2000);
digitalWrite(8, HIGH);//Turn OFF Relay 4
digitalWrite(9, HIGH);
--x;
// decrease counter
}
}
}
//store the values for the next loop

preE = 512;
preW = 512;
pretol= 512;
predtime = 512;
Serial.println(" ");
Serial.println("--------------------------------------------------------------------- ");
// delay the next loop
delay(1000);
}

Copy your code into an editor which does proper indentation for C++ and the error should be obvious.

In the Arduino IDE press Ctrl+T for auto-indent. You have mismatch with '{' en '}'.

I mean no offence by this but you have got in such a mess because you have written monolithic code.  As a new developer you aren't expected to know this, I sure as hell didn't know it 30+ years ago.  The fact that you have posted you code on here, shows that it is too big for a normal brain to manage.  You loop function is over 300 lines long!  A screen full is about all a normal person can manage.
What I think you should do is refactor your code, look at it and pick out common blocks and turn them into functions, this will reduce the number of lines, making in it easier to read and reduce the possibility of bugs.  So firstly I notice you have this block repeated:
if (E1 < 10 || E1 > 1000)
{
    E1 = preE;
}

If you wrote that as a function:
int CheckLimits (const int& value, const int& lowerBound, const int& upperBound, const int& default)
{
  if (value < lowerBound || value > upperBound)
    return default;
  return value;
}
// This means those 4 lines collapse to this one line.
E1 = CheckLimits (E1, 10, 1000, preE);

Those 4 lines of code appear at least 39 times in loop, that's 120 lines that have just bee removed!
The preE value (and its pre friends) is never changed, so make it a constant and that will remove another 4 lines at the end.
Using literal numbers for your pins makes it harder to change them if you ever need to rewire.  More importantly it makes the code harder to understand, so always #define them at the top of you code.
If you create two variables to hold the same sort of number you should be thinking about using an array instead.  When you create E1 to E10  to hold ten readings, you should have done it in an array.  The array size should be a constant, defined in a single place, so you can change it if necessary.  And guess what, the averaging code should have been a function.
ANYWAY
I rewrote you code and hopefully it will explain what I mean.  Loop is down to about 90 lines now and it would be easy to make it smaller.  Yes, get a decent editor, Notepad++ or Visual Studio or Visual Code are all free, but you have to learn to think in smaller blocks, if you ever copy and paste more than one line, it probably should be a function :)
I haven't compiled it, but it should work - Please don't copy it just look at it and make your code better than this.
//set initial values
int x = 0; // set initial zero value for the counter
static const int preE = 512; // set initial value for light intensity in east direction
static const int preW = 512; // set initial value for light intensity in west direction
static const int predtime = 512; // set initial value for delay time
static const int pretol = 512; // set initial value for tolerance value
// Define the PINS
#define APIN_E (5)
#define APIN_W (4)
#define APIN_DTIME (1)
#define APIN_TOL (0)
static const int MaxReadings(10);       // The number of readings used to form the average
int E_Reading[MaxReadings];             // Holds all the readings, not sure it is required any more, replaced by average variable.
int W_Reading[MaxReadings];
int dtime_Reading[MaxReadings];
int tol_Reading[MaxReadings];

void setup()
{
    Serial.begin(9600); // set the baud rate for the serial monitor

                        // first set the relays off
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH); // began the loop
}

/// Check that the given value is within the limits
/// value: The reading to check
/// lowerBound : The lowest acceptable value
/// upperBound : The highest acceptable value
/// defValue : The value to use if outside the range.
int CheckLimits(const int& value, const int& lowerBound, const int& upperBound, const int& defValue)
{
    if (value < lowerBound || value > upperBound)
        return defValue;
    return value;
}

/// Take a reading from the specified pi and check it is within the acceptable bounds.
/// pinNumber   : The Analog pin number
/// lowerBound : The lowest acceptable value
/// upperBound : The highest acceptable value
/// defValue : The value to use if outside the range.
int TakeReading(const int& pinNumber, const int& lowerBound, const int& upperBound, const int& defValue)
{
    return CheckLimits(analogRead(pinNumber), lowerBound, upperBound, defValue);
}

void loop()
{
    int Eaverage = 0;
    int Waverage = 0;
    int dtimeaverage = 0;
    int tolaverage = 0;

    // Read the first reading
    for (int index = 0; index < MaxReadings; ++index)
    {   // You don't actually need the values unless you want them, TakeReading could be assigned to the average variables.
        E_Reading[index] = TakeReading(APIN_E, 10, 1000, preE);         // read the east LDR
        W_Reading[index] = TakeReading(APIN_W, 10, 1000, preW);         // read the west LDR
        dtime_Reading[index] = TakeReading(APIN_DTIME, 10, 1000, predtme);  // read the delay time potentiometer
        tol_Reading[index] = TakeReading(APIN_TOL, 10, 1000, prepretol);    // read the tolerance potentiometer

        Eaverage += E_Reading[index];
        Waverage += W_Reading[index];
        dtimeaverage += dtime_Reading[index];
        tolaverage += tol_Reading[index];
        delay(100);
    }

    //Average the ten readings
    Eaverage /= MaxReadings;
    Waverage /= MaxReadings;
    dtimeaverage /= MaxReadings;
    tolaverage /= MaxReadings;

    const int delaytime = (dtime * 10);// increase the delay by magnitude of 10
    const int tolerance = tol / 40;

    // display the readings through serial monitor
    Serial.println("Light intensity in the East");
    Serial.println(E);
    Serial.println(" ");
    Serial.println("Light intensity in the west");
    Serial.println(W);
    Serial.println(" ");
    Serial.println("delay time");
    Serial.println(delaytime);
    Serial.println(" ");
    Serial.println("tolerance");
    Serial.println(tolerance);

    //check the difference and open the corresponding relays

    // check the difference of light intensity in east and west
    const int diff = E - W;

    // check if the difference is in the tolerance else rotates the motor
    if (-1 * tolerance > diff || diff > tolerance)
    {
        if (E > W)// check if light intensity in east is greater than in west
        {
            if (x < 30)// check counter to ensure the motor does not run infinitely

            {
                Serial.println("Turn motors towards east");
                digitalWrite(7, LOW);// Turn ON Relay 1
                delay(2000);
                digitalWrite(7, HIGH); //Turn OFF Relay 1
                ++x;
            }
        }
        //check if light intensity in west is greater than in east
        else if (W > E)
        {
            if (x > -30)
            {
                // MISSING CODE??
            }
        }
    }
    Serial.println("Turn motor toward west");
    digitalWrite(8, LOW);// Turn ON Relay 4
    digitalWrite(9, LOW);
    delay(2000);
    digitalWrite(8, HIGH);//Turn OFF Relay 4
    digitalWrite(9, HIGH);
    --x;
    // decrease counter

    //store the values for the next loop
    Serial.println(" ");
    Serial.println("--------------------------------------------------------------------- ");
    // delay the next loop
    delay(1000);
}

usually unmatched brackets.
run your code through astyle and it will be more clear to you.


text:
Default sketch working but arduino is not recognizing
I have an arduino UNO and when I connected the device through the USB to the PC (with windows 7 64 bit),
The default blinking sketch, which comes shipped with it, is working,
but the device recognition sound is not playing.
and the device driver installation dialog never appeared and no arduino entry in the device manager.
And when I tried to upload a successfully compiled sketch from the ide 1.8.4 ,
It just says, 'problem uploading to board'
More verbosely, ' avrdude: can't open device""\.\COM1": the system cannot find the file specified'
The device is getting power and running the sketch,
But device is not recognized, maybe it is connected charge only, can I install the drivers manually?
Thanks in advance for any help.

Is it real or a copy?

What do you mean?

Is it a genuine Arduino or a cheap clone from eBay or Amazon?

I got it from a local electronic parts store so it is a copy.

Then you need to identify what usb interface chip it uses and install the right drivers for it, and make sure that your cable is working right.

Thanks for the quick help but how to identify it?  I'm new to arduino

By reading the text on it.

Let us continue this discussion in chat.

Sorry, can't chat now. Just read the text on the USB interface chip. That's the one closest to the usb socket, obviously.

Chip says: MEGA16U2

Then you have a (potentially) genuine Arduino Uno R3. Installing the IDE should install the drivers for you - otherwise the drivers are included in the ZIP version of the IDE for you to manually install. So next is to try a different  USB cable. Some cables only have power wires in them and no data, which may be what you have there.

Welcome to Arduino Stack Exchange.  Please take the tour at https://arduino.stackexchange.com/Tour to get the most out of this site.  Generally the IDE will only offer ports that will work.

I tried a new cable but it's still the same issue.

Hahaha! I figured it out! The USB connector on the board's side was loose connected! It didn't felt like more pressable & when I pressed it enough, it firmly fitted.
When it loose connected, the board connects power only.
The drivers were installed automatically & it showed under COM6. I've got sketches running in no time.
I' ve tried a lot of knight rider patterns with a bunch of RGB LEDs then ;-)
Thank you @Majenko and the arduino stack exchage for your kind replies.


text:
Sine wave PWM Arduino Micro
I'm trying to generate a sine wave on my Arduino micro.
I used this code.
int Pin = 9;

void setup()
{
 Serial.begin(9600);
 pinMode(Pin, INPUT);
}

void loop()
{
 float something = millis()/10000.0;
 int value = 128.0 + 128 * sin( something * 2.0 * PI  );
 analogWrite(Pin,value);
}

I have a low pass filter at the output of the pin to smooth the wave. The problem is : I get a nice square wave with a duty cycle from 0 to 100%, but not a sine wave. Ideally, I'd like to set a frequency of 10 Hz.
Can anyone tell me where I made a mistake ? Thanks a lot !!!

Maybe a bit of a delay? You will be changing the duty cycle very rapidly.

I tried it, the duty cycle of the square wave is changing according to the delay, but it's still not a sine wave.

then your low pass filter isn't enough

You can make a simple R-2R ladder DAC to create a sin wave. However it does require the use of many I/O pins, depending on the resolution you want in your sin wave.

it is how PWM works. digital pins can do only 1 and 0.

So it's not possible to do a sine wave?

Maybe use the PWM to charge a capacitor? You can balance charge and discharge with resistors to possibly get a pretty sinusoidal voltage on it.

I found you a tutorial that should help you to create a circuit that changes a square wave to sinusoidal wave. All you need to do is to output from your arduino 0 for 50ms and 1 for 50ms (to get 10Hz) and adjust the capacitor sizes to get a sin wave. (Tutorial shows circuit working for 10kHz square wave)
http://www.learningaboutelectronics.com/Articles/Square-to-sine-wave-converter-circuit.php

Can anyone tell me where I made a mistake ?

put a lpf on the pwm output.


text:
How do I wire a ground rail to a VEROboard?
I’m looking to move my project from a breadboard to a vero board. However, I’m not sure how to go about soldering in my ground and power connections as the veroboard doesn't seem to have dedicated ground and power rails like the breadboard.
I’ve also attached a photo of my schematic in its current state.
Also, I’m using an Arduino Nano Board as opposed to the UNO featured in the schematic. (I’ve just used it as a placeholder as I could find a component for the nano.
Any help would be greatly appreciated.

Here’s a photo of the type of veroboard I have:

A minor correction in terminology: Your board - one with no interconnections - is usually known as perf-board. Veroboard, aka strip board, has holes already connected in rows. Thus it's easy to assign power, ground, and signal rails, and with a layout that takes good advantage of the strips, it requires fewer hand-wired connections.

Ahh got it - thanks!

sometimes i solder a striped 20AWG solid wire along the edge for an ad-hoc easily solder-able ground rail.

Ahh good shout @dandavis

There's nothing special about ground. It's just a wire like any other.
You could designate a row of holes as ground then link them all together, but you don't need to. Just wire your grounds together as you would any other connection.

Ahh fair enough! So does this also apply to power?

Yep. Everything is just wires.

Makes sense! Thanks for your help!


text:
Is there a way to make the RESET pin work in the inverse?
Is there a way for me to have this work the opposite way?
I have one cable with an alligator clip hooked up to the reset pin and another hooked up to ground.
When I clip them both together, the board resets.
However, I would like for this to work in the opposite way such that they’re already clipped together and when you detach the cables, the board resets.

My personal preference would be to attach a NOT gate to the RESET pin.  This can be constructed very simply from a single NPN transistor (or N-channel MOSFET) and a resistor.

simulate this circuit – Schematic created using CircuitLab
With the wire disconnected R1 turns on Q1 which pulls the RESET pin LOW.  With the wire connected Q1 is turned off, allowing RESET to be pulled back up by the pullup resistor that's built into the Arduino.
This method also won't interfere with the programming reset action of the Arduino.

Thanks for sharing this. I will give this a go and update how I get on

The easiest way to do that would be to use an external pulldown resistor (a resistor from the reset pin to ground) and connect to Vcc (5V on the Nano) via your alligator cables.
As long as the alligator cables are connected, the reset pin is held HIGH through them. When you disconnect them, the pulldown resistor pulls the reset pin to LOW. That holds the Nano in reset until you again connect the alligator clips.
If you want the Nano to reset and then directly work again without the alligator clips reconnected, it gets more difficult. One way I can think of is building a monostable vibrator circuit, which gets in the excited state, when your alligator clips are disconnected, resets the Arduino and then goes back into the stable stable, letting the Arduino execute its code. Though that is more an electrical question, than an Arduino one.

Since there is already a 10K pullup resistor on the reset pin you will want the pulldown to be considerably smaller than that. Probably in the order of 100Ω. That will cause considerable power wastage...

Thanks so much for sharing this! I’ve Bus true this out, hope we, it doesn’t seem to want to work. I have both cables with the alligator clips hooked up to 5V (am I right to do this or does the second clip need to go elsewhere?) It’s worth mentioning in doing this on a veroboard and haven’t yet snipped the kegs off the resistor. Interestingly enough, when the leg hooked up to ground touches one of the alligator cables, the board resets. Also, I was using a 10k before I saw the second comment. I have a 220 one around. Would that work? And could that perhaps be the issue?


text:
Can we use Arduino mini in eagle to create new custom modal
I want to learn pcb design in Eagle/Fritzing. So i was thinking of using existing amazing Arduino mini/nano in eagle and create a custom pcb which has all arduino capability and plus some components like 7 segment/Bluetooth radio etc.
Can we do that? Is is allowed or arduino design is not open to be modified?

From https://www.arduino.cc/en/Main/FAQ#toc8:

I want to design my own board, what should I do?
The reference designs for the Arduino boards are available from their specific product pages. They're licensed under a Creative Commons Attribution Share-Alike license, so you are free to use and adapt them for your own needs without asking permission or paying a fee.

You can find the board design files on the Documentation tab of each product page.
Arduino Mini product page:
https://store.arduino.cc/arduino-mini-05
Arduino Nano product page:
https://store.arduino.cc/arduino-nano

Arduino is open-source hardware. The Arduino website has schematics and board layout files.


text:
Calculate power requirement for 64 rgb led ws2812b
Hi I am working on small project where I want to run ws2812b module via arduino and lipo battery. I have purchased 64 matrix for ws2812b from eBay and lipo battery with 500mah.
I am looking to find how I can calculate how much power does WS2818b modules will consume with all leds running and will the battery be sufficient for it. How long will it run on full charge.
Can someone please point me to the formula how I can calculate this. Also to note I am using a power up converter from 3.7 to 5v.

If all LEDs are in full bright white, assume 60mA per LED. 64 would mean a maximum current draw of 64*60mA=3840mA. This figured would not include the Arduino itself.
a 500mAh battery could power this for no more than 7.8 minutes (500mAh / 3840mA = 0.17 hours = 7.8 minutes)
If your usage will not be full bright 100% if the time, then you could run longer.
You didn’t say how long you want it to run. Perhaps start with the design goal before specifying parts.
For a more realistic view of how much power it takes, measure with a multimeter the current draw from the battery or bench power supply to your boost converter while displaying a typical usage on the matrix. Use calculations as above to determine the expected battery lifespan.

The battery capacity is rated at 3.7V and the LEDs run at 5V. You need to account for that. And can that small battery even provide almost 4A?

@gre_gor my arduino has 5v output pin can i not use it? As per answer above i need 3840mA to run all LED. Is it not possible will the battery get damaged?

Whether your battery will run it for any amount of time depends on the battery specifications. What is the "discharge rate" of the battery? This is usually measured in "C", or multiples of the battery capacity. If you have a 5C discharge rate for a 500mAh battery, then you can discharge at 5*500mA, or 2500mA. What is the rated discharge rating of the battery?


text:
Weight Measurement System using arduino and load cell
I want to use a load cell (Capable of measuring up to 1 ton) connected to a arduino board.
I am a beginner, my questions are as follows :
1. How to calculate the current generated by the load cell ?
2. If current is too high, how will We make the arduino use the current to display weight ?
p.s If you know some helpful articles that might help me learn, please suggest.

What load cell do you use exactly?

My suggestion would be to make a spreadsheet with some items of known weights. Generally while using scales you’ll have a 5lb calibration weight that has a very tight tolerance. You can find the output voltage changes and map it from 0-1023.
This should mean for every 2.2lbs you will get another increment. Not extremely accurate but fine when measuring at the ton scale

Load cells are extremely linear. There is little reason to do such small incremental changes. I designed some scale electronics that we manufacture at my work. The automated test checks four points in order to check linearity and offsets. I have never found any reason to have more that that tested. It will show anything worth looking at.

You need to use a load cell amplifier between the Arduino and the load cell. Load cells are around 350 Ohms. Four wire. And the signal that needs to be measured are very small.
The current will not be too high. The question indicates that you don't understand the application. (and therefore you are looking for help)
Here are some useful links.
https://www.hackster.io/MOHAN_CHANDALURU/hx711-load-cell-amplifier-interface-with-arduino-fa47f3
https://circuits4you.com/2016/11/25/hx711-arduino-load-cell/
A typical load cell has an output of 2 millivolts per volt of excitation voltage at the full rated weight. For example, if 5 volts were used for the excitation voltage, and the output is 2 mV/volt, then the voltage out would be 10mV at full scale. The voltage difference (compared to the unloaded load cell) is what is measure.
If the excitation voltage (just a technical name for applied voltage) were 5 volts, the voltage at the output terminals, measured from the negative terminal, would be 2.5 volts, half of the applied voltage. But this 2.5 volts is not the measured output. What is measured is the difference between the +signal and the -signal wires.

Get a multimeter and check the max output. That would be the best way to find it. If you actually have items around that weigh a literal ton that’d be the best way to find out the max current. Once that’s done you can split the current with a few resistors. If I recall correctly twice as much current would flow through a resistor with twice the value of the other. Make a y and pick the end that outputs the value you like. If you need 1/4 you should have a resistor for example with 47k and 3 together would be 141k. Connect to the 3 to get 1/4 the output current
Wikipedia has a pretty good article on  Current Dividers  if the output current is too high.

That makes sense, most of my experience is with Mettler Toledo but I have never used the voltage for reference. A lot of the time hacking something together on Arduino requires mapping to values it likes. I had a few ultrasonic distance sensors that were just slightly different in the way they responded so I spent a while getting them just right.


text:
I have built a battery level indicator and have tested with a 12V battery Would it harm my arduino board if I connect a 48V battery?
I am a newbie and have followed a tutorial to build a battery level indicator as below

Please suggest any changes I'll need to make to make the circuit useful with a 48V battery as the above circuit is tested with a 12V one.
Thank You.

Care to share the code?

does it work with super 1000ah, 12v battery?

You have a voltage divider there, which would give (if the pre-set pot was set to the maximum):
Vout = (Vin * R2) / (R1 + R2)
Vout = (12 * 10000) / (100000 + 10000)
Vout = 1.09

Thus a 12V battery would present 1.09V at the analog input.
This same wiring would seem to be in range for a 48V battery:
Vout = (48 * 10000) / (100000 + 10000)
Vout = 4.36

Since the analog input can handle up to 5V, then that should be OK. However I would test the voltage divider output first with a multimeter to make sure it doesn't exceed 5V - before connecting it to the Arduino.

You would probably need to change the code to test for different ranges of input voltages, other than what is used for the 12V battery.

Also, if you are using a 3-pin trimmer/pot, be sure to short the central pin to the "unused" one. In this way, if dust/dirt collects on the resistive element, or in case of a major failure, the maximum resistance of that trimmer will be 10kOhm, and not "infinite", avoinding feeding a destructive 48V to the digital input.

Good idea. You don't want the pot to go open circuit as you turn it as it hits specs of dust.

That's great! Edited because I figured it out.

You might also want to connect a 5V zener diode between the voltage sensing pin and ground. That way if you exceed 5V the zener will shunt the excess voltage to ground and protect the pin.

To get a smoother switch from one level to another you could introduce another resistor and use analogWrite() to dim one LED and make next brighter.
Ref.: https://www.arduino.cc/en/Tutorial/PWM


text:
NodeMCU and relay with VIN power
Have read a lot of different things online, and I just ain't sure yet.
I'm trying to hook up a NodeMCU to control some relays. And want to power the NodeMCU by the VIN pin.
Anyone know if this setup is possible?
Or should I do it in another way?

Is it necessary to use the JDVCC at all when I use this setup?
Maybe I can keep the jumper on VCC/JDVCC and only connect to the VCC on the relay?

you would use JDVCC with separate power supply for relay coils. then you would not connect the grounds. main reason would be to prevent EMI from relays switching

So what you are saying is that, for my setup, I don't need to use JDVCC?

I see. For my setup, I will only be using max 2-3 relay at the time

24VAC to control some irrigation valves

it should, but you could also be just out of range of the 5v hi/lo. You can fix that with a level shifter, or, feed the esp32 3.6v instead of 3.3v (still in spec).

Looks fine to me, I don't see any issues, assuming the PSU has sufficient 'grunt' to power both, and most will have.

I'm using a 24VAC to 5VDC 3A converter as the PSU supply

Plenty of surplus power there, you shouldn't have any issues


text:
LED does not blink - Arduino UNO+WiFi R3 ATmega328P+ESP8266 board
As I am learning the Arduino coding, I want to see if my program can turn on the LED light. I have tried all the things, but the code does not start the LED light I have installed on the board.
The code compiles successfully and upload on the board, but nothings happens after that. See the output logs as below:
See all the configuration of board as below:
The board I have:
UNO+WiFi R3 ATmega328P+ESP8266 CH340G Board compatible with Arduino
https://robocraze.com/uno-wifi-r3-atmega328p-esp8266-ch340g-board-compatible-with-arduino
Board switch settings:
5,6,7 => ON (to upload the code from Arduino IDE)
Yellow LED installed:
13 => Positive, GND => Negative
Board setup:

Arduino IDE Setup:

Program:
void setup()
{
  pinMode(13, OUTPUT);
}

void loop()
{
  digitalWrite(13, HIGH);
  delay(2000);
  digitalWrite(13, LOW);
  delay(2000);
}

Output logs after uploading the code:
esptool.py v2.8
Serial port COM8
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: ec:fa:bc:3e:2e:6f
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0340
Compressed 261472 bytes to 193134...
Wrote 261472 bytes (193134 compressed) at 0x00000000 in 17.1 seconds (effective 122.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

As you can see, the last message is Hard resetting via RTS pin....
Would anyone please tell me what is happening here? Why the program does not start the LED light even after everything looks fine?
Any help would be greatly appreciated.
Thanks.

switch the DIP switches to ATmega328p, set Uno in Tools menu and upload the Blink sketch. the esp8266 is there as a network adapter, not as a main MCU of the board

Thank you @Juraj. It is working now. Please put this comment as a answer and I will mark a an accepted answer. Thank again.. You made it.

that is all? this was the problem?

Yes @Juraj. That was the only issue. Thanks very much.

Related, if not about the same thing: https://arduino.stackexchange.com/questions/83377/arduino-uno-with-integrated-esp2866-wifi-not-working-correctly

I don't understand why but after uploaded the ESP8266 (with switchs 5,6,7 ON), the program upload correctly but not running. If put Switch 7 OFF the program run.

@V34Michel 7 switches the flashing mode of the esp8266 bootloader. so of course it must be on for upload and off for run

The Uno+WiFi board is an Uno. With DIP switches 3 and 4 in ON position it is a normal Arduino Uno clone with CH340 chip for USB. All the pin headers at board sides and the ICSP pins are as on an Arduino Uno. Every sketch for Uno will work.
The esp8266 is added for WiFi functionality. The DIP switches allow to program the esp8266 over the CH340 or to connect the esp8226 to Serial of the Uno part (ATmega328p).
To have Serial free for USB, it is usual to wire the esp8266 to a common Uno on some other pair of pins then RX/TX and use SoftwareSerial. There is no such connection on this Uno+WiFi, but the esp8266 header has the Rx/RX pins of the esp8266 so it is possible to wire SoftwareSerial pins with jumper wires (power and ground are connected on board of course).

Don't switch the DIP switches too frequently. They are not made for it and fall apart. Upload some permanent firmware to esp8266 or use OTA upload for esp8266.

Thanks for the answers. What would be the DIP switch settings if I want to run Arduino UNO clone with CH340 + Wifi functionality. (Wifi is already on board). What would be the switch settings for both to work together? so that I can create a program to read the data from internet and display on LED panel. Please suggest.

you should not use switches 1+2 and 3+4 at same time so you can set 3+4 for 'Uno' and put two wires between the RX/TX of esp8266 and a pair of Uno pins and use SoftwareSerial on that pins

Thanks, but not getting it right as I am beginner and not sure how to do that. Any information on how to do that would be greatly appreciated.

the Internet has many tutorials how to connect an esp8266 module to Uno. now you know how to apply them to Uno+WiFi


text:
How to import my own library or file?
I have some small functions to format numbers. I move them to a new file and I would like to import it to my proyect.
I can't find how to do it without defining a class (maybe it's the only way). I would like to import like JavaScript, PHP or other languages: just using the import word or something similar.
I know how to import libraries. Example:
#include <OneWire.h>
#include <DallasTemperature.h>

If the file is in your sketch folder then you use this syntax:
#include "foo.h"

All source files in the root of the sketch folder are shown as tabs in the Arduino IDE. In some cases that might not be desirable. If so, you can put the file in the src subfolder of your sketch folder and use this syntax:
#include "src/foo.h"

Or you might want to group files together into separate subfolders:
#include "src/foo/foo.h"

If you want to access the file from multiple sketches then you should turn it into a library and use this syntax:
#include <foo.h>


text:
Which voltage should I use with a component that allows between 3v and 5.5v?
I have a DS18B20 temperature sensor that needs between 3v and 5.5v to work, as seen in its documentation.
What's the difference? Should it work better which 5.5v?
I know that a LED with more voltage will bright more but it will burn or a pump with more voltage will take water faster.  But what about the temperature sensor?

what do you mean by difference?  it will properly at any voltage between 3V and 5.5V.  the output is digital, not analog

You should use the voltage that matches your hardware.  What sort of Arduino are you using?

I have an Arduinon Uno.

According to the datasheet the absolute maximum is -0.5 V to 6.0 V.
The normal voltage for which it works according to the specifications in the datasheet is 3.0 V to 5.5 V.
That means het DS18B20 works well with 3.3 V and just as well with 5.0 V. One voltage is not "better" than the other. There is not difference. You can use it with a 3.3 V Arduino board and with a 5 V Arduino board.
The power it uses when being active is 1 mA * 5.0 V = 5 mW. It is possible that it causes some self-heating. But let's not go there. That is something for nerds.

When a sensor like this allows a range of power supply voltages it's not because one voltage is "better" than another. It's purely to allow it to work with a wider range of controllers.
The voltage you would use it with is more dictated by what it is you are using it with. If you are using it with a 5V microcontroller, such as the Arduino Uno then you would run the sensor at 5V, since that is the logic levels your MCU will be working at.  If you are using it with a 3.3V microcontroller, such as a Teensy, Due, or chipKIT board, then you would run the sensor at 3.3V to maintain the right logic levels for the board you are using.
By running both the MCU and the sensor at the same voltage you remove the need for any logic level translation between the two.

It's the same thing for a measurement module. You can use the 5V of the arduino, but with a resistance of 4.7KΩ between "Data" and "5V". Like this example


text:
How many sensors can be supported by a single Arduino unit?
I am a beginner in the Arduino world. I made some basic projects of the book that comes with the starter kit (it's was borrowed by a friend of mine) and also I used a humidity, a temperature sensors and a LCD display.
I want to buy an Arduino Uno for measure room temperature, humidity, carbon monoxide, carbon dioxin and maybe a couple more variables. I will to use 4 sensors, 1 buzzer, 1 LCD display and 1 ESP8266 serial WIFI wireless module.
After this work I will add for functionalities but as I have a lot of components I am not sure if the Arduino Uno can supports them because it has a limited quantity of pins.
Do I need an Arduino with more pins? what if I use all these pins and I need more? Can the Arduino Uno be expanded with more pins?
As the Arduino Uno is a very small computer, can its processor support all these components and their operations?

That would depend on their unspecified details, but consider that the esp8266 is a substantially more capable computer than a classic arduino you might be better just using that.

It would be best if you asked 1 question per post.

You can increase pins using shift registers

I'll be more clear, you should ask your other questions.  Just ask them in a different posts.  You probably should consider asking about temperature , co, ect sensors in different posts.  As some are non-linear, others need age compensation, still others need temperature compensation.

As a beginner you have a lot of valid questions.  As Arduino is not just UNOs I would suggest you look at the Arduino web site at all the flavors offered.  As you advance in Arduino world you will find Mega's offer more pins, Yun's can provide a Linux flavor and the MKR1000 has IoT entry.

Since the Uno has support for I2C and SPI, the exact number of pins isn't the limiting factor.

Don't forget that you also have the 10digital and 1 analogue pins on the ESP8266(E), which is a 32 bit processor capable of running at 160MHz.  Using it for WiFi to serial is like buying a Ferrari to nip 1/2 a mile to the shops once a week.

And don't forget to mark an answer as accepted, if it answers your question. This way the question will not bump again to the homepage in the "unsolved" list

An Uno has more than enough pins for the devices you described.

A DHT22 Relative Humidity and Temperature sensor needs only one digital pin for both variables.
An MQ-7 Carbon Monoxide sensor needs one analog pin.
An MG-811 Carbon Dioxide sensor needs one analog pin (and an amplifier).
A Piezo buzzer needs one PWM pin.
The LCD with a Hitachi interface needs four digital pins.
The ESP module needs two digital pins.

That's 7 digital pins, one of which needs to be a PWM pin, and 2 analog pins. I did not make any choices about best or cheapest devices, just ones I either knew about or could find quickly by searching. But with this pin requirement doesn't come close to exhausting the available pins on an Uno so there's plenty of capacity left unassigned for you to make other choices that might require different interfaces or more pins.

Look at the MUX Shield, I just used one to add 48 Inputs to a MEGA making it capable of having 98 Inputs or Outputs

The question itself is a bit broad, but I'll try and provide some insight here.
The number of sensors that can be supported, and the number of pins they require, will depend on what sort of interface they use.

If your sensor has an analog interface, you will need an analog input pin for each sensor.
If your sensor has an I2C interface, you can have multiple devices sharing the same pins (a bus) provided that they have different I2C addresses (often configurable with jumpers on the device).
If your sensor has an SPI interface, you can have multiple devices using the same pins (a bus), except that each will need a chip select PIN connected to a digital I/O pin on your Arduino so that it can 'select' each device.
If your sensor has a serial interface, you can generally only have one device.

To add complexity to the problem, you can get expansion modules for the Arduino that will give you extra analog pins or other communication interfaces.
With the long list of sensors you have above, you may also be hard-pressed for program space, as most sensors will need code and/or libraries to interface with them. The Arduinos with more pins (such as the MEGA) also have more program space.
I would encourage you to do some further research on the sensors you want to use, and finding out what interface they use, and what Arduino libraries are available for them. This way, you can fully understand the requirements and limitations of any parts you want to use.
Further reading:

https://www.arduino.cc/en/Reference/Wire (I2C interface)
https://www.arduino.cc/en/Reference/SPI (SPI interface)
https://www.arduino.cc/en/Reference/Serial (Serial interface)
https://www.arduino.cc/en/Guide/Libraries (Using libraries)
https://www.arduino.cc/en/Tutorial/HomePage (Arduino tutorial)

I think you want to know how many sensors 1 Arduino can support.  But just in case, I am answering both interpretations of the title of your question:

How many different types of sensors can an Arduino support?:

With the correct software and hardware, the Aruidno can interface with almost any kind of sensor.  The exceptions include but are not limited to sensors which produce more data than an Arduino can process (such as a video camera) or sensors that require fast responses (such a time of flight laser distance sensors (LIDAR)).

How many sensors can an Arduino support at the same time?:

This depends on what processor resources are needed.  If the sensor needs the ADC there 6 channels on most Arduinos.  If you need more, there are hardware solutions.  But many here have suggested to simply add a 2nd Arduino.
To specifically address your laundry list:

room temperature

Thermistor connected to ADC.  But most are not linear, so you will have to create a look up table.

humidity

I think there is a SPI module on the market to do this.

carbon monoxide

These sensors usually require an amplifier.  And change with age & temperature.  So a lot of software here as well as hardware.

carbon dioxin

Not sure about this one.

buzzer

Self osculating? Then you only need a logic output.

1 LCD display

Alpha & numeric? Most have 4 or 8 pin Hitachi interfaces.  But you can look for a SPI or serial port LCD so as to conserve on Arduino pins.

ESP8266

This is just a serial device.  You will need the Ardino's serial port.
I'll leave it up to you to make a detailed assessment of the necessary processor resources.  Because you need to first pick out the specific hardware you will be using.
That's half the battle.  The other half is verifying the libraries for all these sensors and communication devices will not interfere with one another.  That I will leave up to you as it is not an easy task to wade through all the code for all the different libraries you will be using.  And, again, until you pick out exactly what sensors and devices you will be using it is impossible to even start analyzing as we wouldn't know which libraries to look at.

This answer has been flagged as "not an answer". Can you please elaborate on the question asked? That is, "how many sensors can an Arduino support?". I see where you are going with this answer, but it is a bit tangential.

I will try.  But the question is broad.  Since no one answered the question after almost a day, I thought to give it a try.

I think it's worth adding that you can have many I2C devices connected to the Arduino's I2C bus, so it's a good option if you need one Arduino drive many sensors. Same for SPI, except for the "slave select" line.

authors: Андрей Милованов


text:
How to keep amperage in serial and parallel?
I have a 2000mA AC adapter and also I have the lights that I show here:

Each of these lights consume up to 300mA.
If I make a circuit with 3 lights in serial, ¿will the amperage of each light decrease?
If I make a circuit with 3 lights in parallel, ¿will the amperage of each light decrease?
I am asking it because I don't want the lights to decrease the luminosity. I want the maximum luminosity in each light.
The lights are for growing lettuces. Now I am using a low consumption light but are not efficient:

The simple answer to that is "No, and stop right now whatever you are doing."
Those LEDs, because of their high current requirements, need a constant current driver.
First a little theory:

LEDs in series sum the voltage, the current stays the same.
LEDs in parallel with no form of current management split the current unevenly and LEDs start dying (or even exploding when you have high currents involved).

If you don't want any control over the brightness then the simplest constant current driver is to use an LM317 voltage regulator wired in constant current mode.
It is also possible to make a constant current sink (the same as a constant current source but between the LED and ground instead of positive) using discrete components.
If you want control of the brightness then the best solution is to use something like the CAT4101 PWM LED driver.
Why don't you use a simple resistor like you would for any other small LED? It's quite simple. Both resistors and LEDs characteristics change with heat. When you are using higher currents like this both the resistor and the LED give off heat (more so the LED than the resistor unless you pick too small a wattage). That means you get changes in the characteristics, which means the current you originally calculated for is now wrong - typically the current increases above what you had originally calculated. More current means more heat. More heat means more current. The result: a cascade. Worst case? The LED dies.

If you put them in series the they require 300mA, but you'd need to have a higher voltage (around 10 Volt).
If you put them in parallel, you could keep the same voltage as a single led (around 3.3 Volt), but you'd require trice the amount of current (i.e. 900mA).
You however need to add proper current regulation, of you'll burn out the leds. The advantage of having the leds in series, is that you only need a single constant current driver.
You could use resistors, but since these leds require that much current, the leds will have to dissipate a lot of heat. Which is both wasteful, and requires special high wattage resistors.

You haven't said what the voltage rating of your Power Supply is, but if we assume it is a "constant voltage" regulated supply, then it will attempt to maintain a constant voltage up to the rated current capacity (2000 mA).
If you put your LEDs in series, then the voltage from your power supply is distributed across the LEDs, and is therefore lower on each LED. This would cause your LEDs to be less bright.
If you put your LEDs in parallel, then the voltage remains constant.

The power supply convert from 220v to 12v. Your answer confirm what I was thinking about voltage, but I would like to know about the amperage.

The other answers by Gerben and Majenko correctly note the requirement to limit current to avoid destroying your LEDs. If you don't limit the current on purpose, the LEDs will dissipate more power than they are designed to and will die.


text:
How to identify RGBW LED pins?
I have a RGBW LED but I don't know how to identify the negative and the colors pins.
I tried different combinations with an Arduino Uno but it never produce light.
I never used it so I am not sure if its name name RGBW LED.

That's not the kind of LED that even wakes up for less than 50mA, which the Arduino can't even reach.

try a battery directly across the pins (with a current limiting resistor of course)

Brand Name: LEDGUHON
Model Number:JH-4RGBW14G

The pin with a + is the anode of one colour. The three next to it are also anodes.
Each anode is connected to one LED. The cathode of that LED is connected to the pin directly opposite the anode.


text:
How to connnect Arduino to Wemos D1 (send data)?
I made a project with an Arduino Uno, a 16x2 LCD display and a DS18B20 temperature sensor. It shows the temperature in the display:

I want to connect it to Internet so I got a Wemos D1 Mini. It works great: it send data through my router.
But I need to connect my project with the Wemos D1 Mini:

I think that I just need to send the data (temperatures grades) from my project to Wemos so then Wemos resolve it.
How can I do it?

A) Throw out the Arduino, and just connect your display and sensor to the WeMos directly.
B) Connect the Arduino to the WeMos using UART, SPI or I²C and send the temperature value to the WeMos. Keep in mind that the Arduino UNO is a 5V device, and the maximum voltage for the ESP8266 is 3.3V, so you'll need a level shifter.
You can send the temperature as a binary value (beware of framing errors), but the easiest way is to use a text-based protocol. Since you just have to send a single value, you can just use a single delimiter (e.g. new line). That makes it very easy to parse.

Option A): Do I need a I2C converter between Wemos and LCD? Like this: https://www.digibay.in/image/cache/data/sachinelectronics/ED01/ED01-09-0020-A-600x600.jpg. Option B: Do you have a sample code or schematic code? Thanks.

A) you could do that to save pins, but you don't have to. B) Google for Serial input basics by Robin2 on forum.arduino.cc

If you want to use the Wemos D1 only as a 'network adapter', put a firmware into esp8266. 'Classic' is Espressif AT firmware in esp with WiFiEsp library in your sketch. New option is WiFi Link firmmware in the esp with WiFi Link library used in your sketch.
Both libraries recommended by me (WiFiEsp and WiFiLink) have standard Arduino networking API like the Ethernet and WiFi library.
WiFi Link firmware is an Arduino sketch for the esp8266.


text:
Can I use a DAC with an L293D driver?
I'm trying to provide analog control to a Bluetooth controlled car, via Arduino. I have joystick app (as the pot).
It send values between 0 to 255
So I'm thinking... Whether this flow down here  will work?
Joystick app --> Bluetooth Rx --> DAC --> Vs pin of L293D. Or motor?
Is Arduino required at all? Or is the serial word enough to translate into voltage via DAC?

You need a PWM signal for a motor driver, not a DAC.

@Majenko but I am using a simple dc motor not any servo or stepper motor

So? What difference does that make? A motor driver requires PWM. A DAC (unless it's a very expensive industrial one designed for the purpose) cannot directly drive a motor.

@Majenko that's what... I mean to use the output of the DAC to use with the "motor voltage" pin of l293d.

What "motor voltage" pin? If you mean the pair of VCC pins, I reiterate: a DAC cannot drive a motor.

@Majenko I totally agree that Kotor requires l293D to be driven. I agree.

@Majenko the thing is, the DAC provides variable voltage at its output depending on input bits? Right? So this voltage I'm planning to apply to the Vss pin or the motor voltage pin if l293d. So my idea was to vary the motor's input voltage through l293d via DAC. The variable voltage will alter it's rpm also right?

The power you put into the supply pins of the motor driver is what is used directly by the motor. That supply has to have enough current to drive the motor, which a DAC cannot provide. The motor driver is designed to switch a high current supply on and off to the motor. That is how it controls the speed. To use a DAC you will first have to convert that voltage into a PWM waveform to switch the EN pins of the driver so it can switch a high current source to drive the motor. The driver does not magic extra power from thin air.

@Majenko oh right... So the the current required by the motor is not provided by the DAC(insufficient), unlike a battery supply.

Correct. You need to amplify that some how, and for a motor the most efficient way is with an H bridge (motor driver) and PWM. There are voltage-to-PWM chips available that would do the job, but you may as well just use an ATTiny and lose the DAC.

@Majenko so the voltage level at the DAC output, which is determined by input bits, is converted to a pwm waveform. This is fed to en pins to enable that respective motor.

@Majenko this voltage that varies over say, 8 bits will produce a different waveform for each of the 256 voltage levels? If so, then this will keep on switching the en pin repeatedly depending on wavefrom and thus varying motor speed by determining for how long the motor remains on before giving it another pulse. Right?

Or you can try power amplifier and weep over all of the power turned into heat on it...

@NiranjanDixit Correct. But like I say - easier to just use a small MCU and not worry about the complexity of a DAC and PWM chip.

It seems part of question arises from confusion between the sparse PWM pulses (repeating only about 50 times a second) used as a command to radio control hobby servos and speed controls, vs the kind of continuous PWM needed to cause a simple H-bridge to directly modulate power to a motor itself.  Essentially the poster will be building their own "ESC" where the high rate continous PWM output is controlled by software and messages originating with bluetooth, rather than controlled by sparse PWM from an RC transmitter.

Also, consider getting something better than the antiquated L293D, especially if you want to run on batteries.  It is rather horrible, and there are a number of threads discussing better alternatives.

No, you cannot. A DAC cannot provide enough current to either directly drive a motor or to power a motor driver (which is basically driving the motor directly through a switch anyway).
A motor driver requires a PWM signal to rapidly switch a high current source on and off to set the motor speed.
You could feed the DAC output into the input of a voltage-to-PWM converter chip which would then feed the motor driver's EN pin, but that is pretty pointless when you could just use a small microcontroller to receive the digital speed value and directly generate a PWM signal.
After all, that is the kind of job that small microcontrollers are designed for...


text:
Serial ports(in 1.0.5 & Port in 1.6.11) is greyed out under tools
I am running a linux distro on my pc(Ubuntu 16.04). I have installed Arduino IDE(version 1.0.5 since it's the only one available on the store) from the Ubuntu Software Center and also using the .ZIP file from the official Arduino website(version 1.6.11). When I ran IDE(1.0.5) the "Serial Port" drop-down was greyed out. Next ran the IDE(1.6.11) and again the "Port" drop-down under Tools was greyed out. I have spent hours looking online for a solution but all in vain. A tried and tested working solution will be highly appreciated.

Are you in dialout group?

Well, every time I launch the IDE it shows me the following message:
`You need to be added to the "dialout" group to upload code to an Arduino microcontroller over the USB or serial ports.
Click "Add" below to be added.
You must log out and log in again before any group changes take effect.`
And then as instructed I clicked on the add button. Even then the Serial port remained greyed out. And besides, shouldn't the adding be a one time thing? Why do I have to do it every time I launch the IDE?

Maybe you don't have enough access rights to change it. Otherwise it should be one time action. Try to add this group for your account from root account (or with sudo).

Or launch the IDE from the root account and let it sort it out for you.

Information on a “Serial Port Setup” page at fedorahosted.org should be adequate to sort the problem manually.  Here are a few snippets from that page, along with notes about application to the current problem.
• Use command ls -l /dev/ttyUSB* to find out the serial port's group.  For example, on my Ubuntu system that shows
crw-rw---- 1 root dialout 188, 0 Aug 20 11:13 /dev/ttyUSB0

Note, substitute for ttyUSB if the port you're concerned about doesn't start with that.
• Use command groups to find out which groups you belong to.
• The fedorahosted page says to use command sudo adduser (username) dialout to add dialout to your groups list.  I haven't tried that approach, and would be more inclined to instead try sudo usermod -a -G dialout (username) [where  “(username)” represents your username].

One must then log out and log back in for the group membership change to take effect.


text:
PWM generation for inverter by Arduino
Can I generate a PWM signal for a Mosfet driver using a saw tooth wave and sine wave through Arduino ?

You could  add a DAC chip. Or use some resistors to create an R-2R resistor ladder.

PS I think most inverters use regular PWM (at a higher speed), and smooth the output. Using mosfet in a none-saturated is inefficient, and will make them run hot.

Read the datasheet of your inverter: What should the PWM signal look like? What frequency? Duty cycle? If you add this information to your question, it would be possible to provide a useful answer.

Yes you can very easy generate an PWM Output with an Arduino:
void setup()

{

  pinMode(pwmPin, OUTPUT);   // sets the pin as output

}

void loop()

{

  analogWrite(pwmPin, yourWantedValue);  // analogWrite values from 0 to 255

}

On most Arduino boards (those with the ATmega168 or ATmega328), this
  function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it
  works on pins 2 - 13 and 44 - 46. Older Arduino boards with an ATmega8
  only support analogWrite() on pins 9, 10, and 11.
The Arduino Due supports analogWrite() on pins 2 through 13, plus pins
  DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to
  Analog converters, and act as true analog outputs.

Visit quote origin for more Information.

Note that the PWM frequency is quite low: 490 or 977 Hz depending on the pin. The OP should check the datasheet of the inverter to make sure those frequencies are OK.

Currently, none of the boards have a DAC on them, with the exception of the arduino Due. Thus, Unless you have the Due board, it is not possible.
If you have a due board, and are interested in generating wave functions, then check out here: https://www.arduino.cc/en/Tutorial/DueSimpleWaveformGenerator


text:
Transforming from analog output to speed and acceleration with gy-61
Maybe it's a simple question but I'm unable to get what I need.
My task is this:
Get the acceleration and speed of each axis of the accelerometer.
I thought of something like:
const int VCCPin = A0;
const int xPin   = A1;
const int yPin   = A2;
const int zPin   = A3;
const int GNDPin = A4;

// variables
int old_x = 0;
int old_y = 0;
int old_z = 0;

int new_x = 0;
int new_y = 0;
int new_z = 0;

void setup() {
  // pin A0 (pin14) is VCC and pin A4 (pin18) in GND to activate the GY-61-module
  pinMode(A0, OUTPUT);
  pinMode(A4, OUTPUT);
  digitalWrite(14, HIGH);
  digitalWrite(18, LOW);

  // activating debugging for arduino UNO
  Serial.begin(9600);
}

void loop() {
  new_x = analogRead(xPin);
  new_y = analogRead(yPin);
  new_z = analogRead(zPin);

  Serial.print("Difference in X=");
  Serial.println(abs(old_x - new_x));

  Serial.print("Difference in Y=");
  Serial.println(abs(old_y - new_y));

  Serial.print("Difference in Z=");
  Serial.println(abs(old_z - new_z));

  old_x = new_x;
  old_y = new_y;
  old_z = new_z;
}

Unfortunately, the analogRead will give me a value between 0 and 1023 and I don't know how to convert this to speed and acceleration.
Any ideas on how to get this convertion?

Probably relevant http://arduino.stackexchange.com/q/13887/972

I assume that your accelaration hardware work. Becuase it gives you different analog outtput in with diffrent accelaration. it seems what you are asking for is how to calibrate it. As a guess there should be away to calibrate the accelaration for each axis when the sensor not moving in the x,y,z plane for zero acceleration. See the page https://learn.adafruit.com/adafruit-analog-accelerometer-breakouts/programming is what you seem to be looking for. Im not sure how your code works works, because acceleration is defined as the differential of velocity function which to me means that yoe mu

st measure the rate of change of velcocity at two different point in time to measure the accelaration-to estimate the accelaration at that time point. Or if the hardware gives you the accelaration directly you dont need to measure new and old velocities. Once you have calibrated it you can convert the accelaration to a single accelration by using pythagoros's theorem in three dimension to get the size of the final accelaration.

However, the above two comments are are just an educated guess, to give you some ideas,  becuase I dont have the accelaration hardware you are using.

Since I can't comment I must post this as an answer. To get changes in values to be considered as speeds and accelerations you need to take time into account. Distance=rate*time. So Distance divided by time gives you the rate (speed). Then you can measure the change in speed over time to get accelerations. The GY-61 is capable of directly giving some of the readings you are looking for. Here is one article about it that you may find useful: https://waime.wordpress.com/2015/03/15/basic-measurement-with-accelerometer-gy-61-with-adxl335-chip/ Like @qwerty, I am just ruminating here.