text:
Help - Atmega328p, converting a PWM servo code from pin9 to pin6
I found a working code that uses pin9 (PB1) on my Arduino for controlling a Servo, but in my project, an ultrasonic sensor is already using that pin/timer. I want to convert the code to use pin6 (PD6), changed the registers according to the atmega's datasheet, but it doesn't work. Need help :/
The code should allow me to turn a servo using a potentiometer.
#define F_CPU 16000000 //16MHz
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>

#define PWM_PRESCALLER 64
#define ICR_MAX (long double)F_CPU/PWM_PRESCALLER/50
#define OCR_MIN (float)ICR_MAX/37.5 // /8.75
#define OCR_MAX (float)ICR_MAX/8.7 // 37.5

volatile unsigned long adc_val=0;
volatile unsigned long counter=0;
unsigned long curr_adc=0;

ISR (ADC_vect)
{
adc_val += ADC;
counter++;
}

int main(void)
{
    DDRD |= (1<<DDD6);
    ICR1 = ICR_MAX;
    OCR0A = OCR_MIN;
    TCCR0A = (1 << COM1A1) | (1<<WGM00) | (1<<WGM01);
    TCCR0B = (1<<WGM02) | (1<<CS01) | (1<<CS00);
    ADMUX = (1 << REFS0);
    ADCSRA = (1 << ADEN)|(1 << ADATE)|(1 << ADIE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

    sei();
    ADCSRA |= (1<<ADSC);

    while(1)
    {
        if(counter >= 1000)
        {
            cli();
            unsigned long round_val = round(adc_val / counter);
            adc_val=0;
            counter=0;
            if(abs(round_val - curr_adc) > 1)
            {
                curr_adc = round_val;
            }
            long double ocr = OCR_MIN + ((long double)curr_adc * (OCR_MAX - OCR_MIN)/1024);

            OCR0A = (int)round(ocr);
            sei();
        }
    }
}

Please edit your question and try pasting the code again. Somehow there are extra newlines and all indentation was removed, making the code pretty hard to read.

Wouldn't it be a lot simpler to just do an analogRead each time through your loop? And use the Servo library to control the servo?

PORTB bit 6 is controlled with TIMER0 while PORTB bit 1 is controlled with TIMER1.  Therefore you need to change the timer variables appropriately.  One mistake in your code is that you leave ICR1.  It should be OCRA if you want to use TIMER0.

I thought of ICR0, but according to the datasheet, there is no ICR0.

Checked that, you are right.  I think you can only use OCRA.  Not OCR0A?

No OCRA according to Atmel studio

Timer0 is already used for delay and millis. Use pin 3 or 11, as those use timer2 which isn't used.

My problem is now that I have to use ICR0 for my servo and ultrasonic sensor and then they get confused. Is there an alternative for this ICR0?

I think you will solve it by reading the data sheet.  Values for TCCR0A and TCCR0B are determined by the waveform generation mode, value of TOP and clock prescaler.  According to your code, WGM=0x7 i.e. fast PWM, OCR0A=TOP.  Read section 19.7.3 of Atmel-42735B-ATmega328/P_Datasheet_Complete-11/2016

I agree with Nick Gammon's comment that it is a lot easier using the Arduino Platform and use AnalogRead() function in conjunction with the servo library.
Having said that, you have chosen to write the program from scratch as many others prefer to do for one reason or another. I wanted to pass on the 2 web pages that I always go to when I am playing with the PWM frequencies and setup.

http://playground.arduino.cc/Main/TimerPWMCheatsheet
https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM


text:
control 3 relays with 1 button
Is there a way to control 3 relays with 1 button?
My idea is: There are 3 modes; mode 1 for relay 1, mode 2 for relay 2 and mode 3 for relay 3.
With a long press you switch between modes (After 3 comes 1) and with a short press you activate the relay which is in the activated mode.
I need this for my wheelchair so please help me.
Thank you, Michael

Further question:
Does the relays really need a external power supply?
Because I have a small amount of power to control with the relays.

you asked only one question ... the answer is "yes" .... is that what you really wanted to ask?

What do you need to control? If the thing you need to control takes DC, and it's voltage and current needs are reasonable, you might be able to control them using MOSFET transistors rather than relays. You could power those just fine from the Arduino's voltage regulator

Sure you can. This site isn't a great place for open-ended questions like this though. Since you have a serious real-world need I'll give you some guidance anyway.
You'd need to break it into pieces and solve each one in turn.
First create code that recognizes long and short presses (not using delay().) You'll probably want to respond on releasing the button, since at that point it's easy to tell if it was a long or a short press.
The pseudo-code might look something like this:
void loop()
   if button_is_pressed
      if !press_in_progress
         press_in_progress = true
         start = millis()
   else
      if press_in_progress //Button has been released
         elapsed = millis() - start
         press_in_progress = false
         if elapsed > long_press_threshold
            long_press_function()
         else
            short_press_function()

For controlling the relays, I suggest getting "digital" relays that are made to be controlled with 5V logic signals. Relays like this work well. (Link). Since you need to control 4 relays, a 4 channel model like this one would be a better choice. Note that you'll need a fairly high current power supply. A 2A 5V regulated supply should be plenty for both your Arduino and your relays, although it's more of a sure thing if you use separate power supplies for the arduino and the relays (that way the voltage to the arduino doesn't bounce around as the relays energize and de-energize.
You'll need a global variable for the currently active relay. The long press would increment that value modulo 4: (going from 0 to 3 and then back to 0)
relay_index = (relay_index + 1) % 4;

You'd need an array of 4 bools for the states of each relay:
bool relay_states[4];

The short press would toggle the state of the current relay
relay_states[relay_index] = !relay_states[relay_index];

Note that if you're more interested in solving your wheelchair problem cost-effectively than tinkering, this is the sort of thing that a maker space would be ideal for. There are lots of tinkerers there who love a challenge, and would likely pitch in and help you.

You posted an answer to your question asking if you really need an external power supply. Don't do that. Post a comment on my answer. But the answer is "very likely". Each relay draws 50-60 mA. At 60 mA, that's 240 mA just for the relays. You might be able to get away with powering that from the 5V supply on the Arduino, but as the relays energize and de-energize they will cause dips and spikes in the voltage from the supply, as the supply tries to adjust to the varying load. You can try it, and if you have problems like the Arduino restarting, switch to a higher current external supply.

Note that you should NOT use bare relays. You want relays that are made to be driven from logic signals and have built in transistors and flyback diodes. (Bare relays will almost certainly fry the Arduino used to control them.)

@MichaelMesser Consider buying a relay driver board such as this one:  Arduino Compatible 4 Channel 12V Relay Module

@sa_leinad I included a link to a 5V 5 channel relay module in my answer.

Can I use a powerbank as a powersupply?

@DuncanC, so you did. Sorry I missed that.

I would not recommend using a powerbank because those consume power just to maintain 5V. It's probably better to buy 12V rlays like those shown by sa__leinad, and use a 12V lead-acid battery on your chair. Those store a large number of amp-hours, and have good shelf-life.

Then you can get a 5V switching power supply, attach it to the 12V battery and feed it's output into the USB connector on your Arduino. That way you have a large capacity, high efficiency way to power your Arduino.

Its a little complicated to use the battery from the wheelchair, so I'd like to use a 5v external power supply.

Can I use this relays too: https://www.amazon.de/Boladge-4-Kan%C3%A4le-Steuerschalter-Treiber-Raspberry/dp/B0734P228K/ref=asc_df_B0734P228K/?tag=googshopde-21&linkCode=df0&hvadid=231932152232&hvpos=1o2&hvnetw=g&hvrand=8055025540693799388&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9068490&hvtargid=pla-613740420672&psc=1&th=1&psc=1

Cause I'm from Germany

If you have a high enough capacity power bank that will work but it will need to be recharged pretty regularly. A 12V lead-acid battery, and a 5V switching power supply would give you MUCH longer running time.

@DuncanC do you know where i can find someone programming it for me?

Yes, it is possible to do that and there are libraries for that purpose. Check for example  ObjecButton library, which supports click, press and double click action. It is well documented and comes with many examples...
And does the relays really need a external power supply? It depends, what kind of relays you want to use, what kind of power supply is available on wheelchair, what is the load switched by these relays and so on...

The load switched by the relays is really low. Are there alternatives for a relay which have the same function, but a lower power consumption for switching on and off?

Yes, there are. For DC load use transistors, for AC load use e.g. triacs or SSR relays. There is plenty Arduino modules on the market with these kind of switching "elements".

source: Stack Exchange

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

sort: votes


text:
How to make 4 digits 7 segments common cathode thermometer
I'm new to Arduino and I have this problem: The common cathode 4 digits 7-segments keep on blinking even the code and my connection is correct (in my opition). I have used an LM35 IC to read the temperature
 I've just followed this pattern:
and I used this code:
const int digitPins[4] = {5,4,3,2}; //4 common CATHODE pins of the display (inverted the pins order)
const int clockPin = 7;    //74HC595 Pin 11
const int latchPin = 8;    //74HC595 Pin 12
const int dataPin = 12;     //74HC595 Pin 14
const int tempPin = A0;     //temperature sensor pin
const byte digit[10] =      //seven segment digits in bits
{
  B00111111, //0
  B00000110, //1
  B01011011, //2
  B01001111, //3
  B01100110, //4
  B01101101, //5
  B01111101, //6
  B00000111, //7
  B01111111, //8
  B01101111  //9
};
int digitBuffer[4] = {0};
int digitScan = 0;
float tempC; //Deleted kelvin and farenheit

void setup(){
  for(int i=0;i<4;i++)
  {
    pinMode(digitPins[i],OUTPUT);
  }
  pinMode(tempPin, INPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(tempPin, INPUT);
  //Serial.begin(9600);
}

//writes the temperature on display
void updateDisp(){

  for(byte j=0; j<4; j++) {digitalWrite(digitPins[j], HIGH);} // Turns the display off. Changed to HIGH
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  digitalWrite(latchPin, HIGH);

  delayMicroseconds(2);

  digitalWrite(digitPins[digitScan], LOW); //Changed to LOW for turning the leds on.

  digitalWrite(latchPin, LOW);
  if(digitScan==2)
    shiftOut(dataPin, clockPin, MSBFIRST, (digit[digitBuffer[digitScan]] | B10000000)); //print the decimal point on the 3rd digit
  else
    shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);

  digitalWrite(latchPin, HIGH);

  digitScan++;
  if(digitScan>3) digitScan=0;
}

void loop(){
  tempC = analogRead(tempPin)*0.00488;  //multiplied for this conversion constant
  tempC = tempC*10000;
  digitBuffer[3] = int(tempC)/1000;
  digitBuffer[2] = (int(tempC)%1000)/100;
  digitBuffer[1] = (int(tempC)%100)/10;
  digitBuffer[0] = (int(tempC)%100)%10;

  if (digitBuffer[0]>=5) {
    digitBuffer[0] = 5;
  }
  else {
    digitBuffer[0] = 0;
  }

  delay(5);
  updateDisp();
}

Who designed that circuit?

By "blinking" do you mean the display is showing the right thing but it's just flickering, or it's just flashing random stuff on and off?

it just flashing random stuff sir Majenko.

I just saw it on a comment in this link https://www.instructables.com/id/Temperature-Displayed-on-4-Digit-7-segment-common/

Ah right, well maybe using the original circuit from the instructable may be better - that one is using its resistors completely wrong, and if something so basic is wrong then I can't vouch for the rest of the circuit being right...

i cannot use the original circuit sir because i'm just using 12 pins 4 digits 7 segments while he is using 16 pins sir

Looks like he's using a 12 pin display to me - even the pin layout is the same. Follow the wires and note the order. Ignore the fact he is showing it with individual displays - that'll just be because he didn't have the real one in Fritzing.

Also, is there any reason you want to use the shift register? The Uno has enough pins o drive the display directly without need of a shift register, and you'll get a much smoother display (no delays while it shifts). You could even drive it with a timer interrupt to make it even smoother.

because sir later i will need the other pins to use fire sensor,light sensor,buzzer, tilt and LEDs

Maybe removing the 5ms delay from your loop may improve things a little.

A better way is to have the resistors on the anode side of the LED instead as this will help balance any uneven voltage drop of the diodes.

First thing to check is that you have the IC and the 7-segment display module connected the correct way around. As a reference, the green wire is attached to Pin 14 of the 74HC595 IC, so pin 1 would be the top right pin. The 7-segment display should have the the dot points towards the bottom.
Check that you have a common cathode display. You can do this by applying a voltage, through a 220 ohm resistor, verifying that it lights up when positive is on pins A-G and Gnd connected to the common cathode pin.
Check the code by removing the temperature section of the code and just writing '0's to all 4 digits. In fact it would be worth testing the digits one by one. The below code should do just that (unverified):
const int clockPin = 7;    //74HC595 Pin 11
const int latchPin = 8;    //74HC595 Pin 12
const int dataPin = 12;    //74HC595 Pin 14
const int digitPins[4] = {5,4,3,2};

void setup(){
  for(int i=0;i<4;i++)
  {
    pinMode(digitPins[i],OUTPUT);
    digitalWrite(digitPins[i], HIGH);
  }
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  for(int i=0;i<4;i++)
  {
    //select the digit by enabling the common cathode (sink)
    digitalWrite(digitPins[i], LOW);

    // write '0'
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 63);
    digitalWrite(latchPin, HIGH);
    delay(1000);
  }
}

This code will display a '0' one digit at a time, each for 1 second.  If this code works then I suspect the problem lies in the updateDisp() function.
NB: In your code, tempPin is setup twice as an input.

In the line shiftOut(dataPin, clockPin, MSBFIRST, 63);, the number 63 may actually be 252 depending on which way the wires A-G are wired to the shift register. You could always use 255 to turn on all bits from the shift register.

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


text:
Arduino language
I'm learning with my school Arduino and how to use it etc.
I know Swift and a little bit of HTML and I would like to learn Arduino language, because I think it's easy!
What are the best resources for learning Arduino?
What are the best programs to write Arduino?
Thanks!

As FYI, there is a free/commercial Swift for Arduino available. I've not tried it ... yet. Just noting the option.

I would like to learn Arduino language, because I think it's easy!

it is C/C++.

Ok....  I dont know why, but when im writing Arduino, its not that hard like c/c++ .   Thanks

Maybe you find it easy because you have never written anything complex in it. And as arduino atmel chips are limited in memory, you wont write there complex applications...

@Divisadero οκ. I understand this. I have wrote complex code..   I have connected to an Arduino UNO an thermal censor, a temperature-humidity censor and a 16pin LCD 11x8 (I think, or 11x6 :)) ).   This code was my most complex. (I am learning Arduino with my school for almost a year.)

@AlexKordatzakis Do not take it personally, but what you have mentioned are not complex projects at all. I guess you have used the libraries for these projects. I suggest you look into the libraries and try to understand them.

@Divisadero 1st. I'm not taking it personally. :))   2) I didn't said that I have wrote the most complex code in Arduino..   3) For the libraries, should I download the arduino program, or just browse them?

'Arduino program' is Arduino IDE [integrated development environment]. Here is some documentation for libraries: https://www.arduino.cc/en/reference/libraries and here is some source code https://github.com/arduino/Arduino/tree/master/libraries You can find more directly in Arduino IDE folders.

I guess Arduino is not the best language to learn as a beginner if you are interested in programming. Try Python, C#, JavaScript. Or directly C++ (which Arduino is actually).
Arduino has too specific usage and is limited. You wont use OOP here very often and will miss a lot of programming principles and practices.

Ok. But I'm already learning. 2 Languages. I started with Swift and now I'm in HTML.  I will stop here, and when I learn very smoothly to use these two languages I will move to C++. What do you think?

Yeah, sorry, I havent't noticed Swift. My bad.

Is it good you mean?

It is not about being good or bad language. Who am I to say if one programming language is better or worse. But one can say if language is suitable for getting into programming for beginners. For me, personally, C# seems to be best for beginners. It is powerfull enough to learn you OOP, you can try design patterns and .NET contains enough frameworks to try client applications, web and SOA programming. Compared to C++ it abstract more difficult concepts you can grasp later. On the other hand, python seems to be to be too flexible for beginner.

I appreciate for giving me these advices!  But now I have to learn two languages and I like these languages.. thank you for the help anyway!!

Sure, I was talking in general. Acutally I have only basic knowledge about swift (as it targets apple), but I guess it is suitable as well. Good luck on your path.

To begin as a newbie get started with the inbuilt examples that are already given.You will learn one by one and its easy to understand anyways.Try few simple codes like LED BLINK,LED WITH SWITCH, SENSOR INPUT AND OUTPUT USING SERIAL MONITOR and you will get used to with the ARDUINO IDE.
Ofcourse the best site is www.arduino.cc but try few pdfs for Arduino beginners which are available on the internet.Try youtube if you are having any trouble working out with just text information.
Go through the book "ARDUINO PROJECTS FOR DUMMIES"
LINK: http://www.dummies.com/store/product/Arduino-Projects-For-Dummies.productCd-1118551478.html
check out this link:
http://www.makeuseof.com/tag/getting-started-with-arduino-a-beginners-guide/

Best resources:

Official website: www.arduino.cc
This site (duh)

I don't know what you mean with 'best programs' ... that depends on what you want. My 'best program' is probably not your 'best program'

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

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


text:
Troubleshooting duplicate libaries (Arduino motor shield and stepper motor)
I have tried a software. It work flawless on the first laptop in a fresh install arduino IDE environment with the libraries I imported.
However when I copy the exact same program over. I get lot of errors and tried to clean up some of the old libraries from earlier programs. Then rerun the compiler; got even more errors and I am not sure what to do except completely clean everything including older libraries that I may need to keep around for older programs.
My includes are as following:
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Error from the Arduino IDE from the second laptop is as following:
Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Uno"

Invalid library found in C:\Users\B Family\Documents\Arduino\libraries\examples: C:\Users\B Family\Documents\Arduino\libraries\examples

libraries\utility\Adafruit_MS_PWMServoDriver.cpp.o: In function `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: multiple definition of `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)'

libraries\Adafruit_Motor_Shield_V2_Library-master\utility\Adafruit_MS_PWMServoDriver.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit_Motor_Shield_V2_Library-master\utility/Adafruit_MS_PWMServoDriver.cpp:28: first defined here

libraries\utility\Adafruit_MS_PWMServoDriver.cpp.o: In function `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: multiple definition of `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)'

libraries\Adafruit_Motor_Shield_V2_Library-master\utility\Adafruit_MS_PWMServoDriver.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: first defined here

libraries\utility\Adafruit_MS_PWMServoDriver.cpp.o: In function `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: multiple definition of `Adafruit_MS_PWMServoDriver::setPWM(unsigned char, unsigned int, unsigned int)'

libraries\Adafruit_Motor_Shield_V2_Library-master\utility\Adafruit_MS_PWMServoDriver.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: first defined here

libraries\utility\Adafruit_MS_PWMServoDriver.cpp.o: In function `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: multiple definition of `Adafruit_MS_PWMServoDriver::write8(unsigned char, unsigned char)'

libraries\Adafruit_Motor_Shield_V2_Library-master\utility\Adafruit_MS_PWMServoDriver.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: first defined here

libraries\utility\Adafruit_MS_PWMServoDriver.cpp.o: In function `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: multiple definition of `Adafruit_MS_PWMServoDriver::reset()'

libraries\Adafruit_Motor_Shield_V2_Library-master\utility\Adafruit_MS_PWMServoDriver.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: first defined here

libraries\utility\Adafruit_MS_PWMServoDriver.cpp.o: In function `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: multiple definition of `Adafruit_MS_PWMServoDriver::begin()'

libraries\Adafruit_Motor_Shield_V2_Library-master\utility\Adafruit_MS_PWMServoDriver.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: first defined here

libraries\utility\Adafruit_MS_PWMServoDriver.cpp.o: In function `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: multiple definition of `Adafruit_MS_PWMServoDriver::read8(unsigned char)'

libraries\Adafruit_Motor_Shield_V2_Library-master\utility\Adafruit_MS_PWMServoDriver.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: first defined here

libraries\utility\Adafruit_MS_PWMServoDriver.cpp.o: In function `Adafruit_MS_PWMServoDriver::Adafruit_MS_PWMServoDriver(unsigned char)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: multiple definition of `Adafruit_MS_PWMServoDriver::setPWMFreq(float)'

libraries\Adafruit_Motor_Shield_V2_Library-master\utility\Adafruit_MS_PWMServoDriver.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire/Wire.h:77: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling.

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

The diagnostics tell you exactly what is wrong! You have multiple copies of the same library, probably because you installed it at different times from different places. The diagnostics even tell you which libraries are duplicates. Remove them and everything will work fine!
While we are at it: another source of duplicate definitions is badly written .h files that define (as opposed to only declaring) external symbols. Those you have to deal with as they happen, there is no global solution.

While there were some stuff you got wrong. Turn out that Arduino was looking for libraries in TWO places and it didn't specific which one in compiler errors. So I had to delete those in Document > Arduino > Libraries. Turn out the %arduino install path% > libraries had the correct libraries after all.


text:
Arduino and USB power, what to choose
I am a beginner at Arduino. I want to power the Arduino through the USB cable that is usually plugged in the USB of the laptop, but plugged in the wall instead of the laptop.
Here are my questions:

Can I use a phone charger that has a USB (in which the end of the USB
cable will go instead of the USB of the PC)?
What should I look for written on the charger so it is best
compatible?
Is it ok to be done that way?
Will it be the same as means of power like when it is plugged in the
PC (for example when later on I connect LCD display, diodes, etc.)?

I did my research, but it got confusing, so I wanted to ask my own question. Thanks in advance.

Yes, you can power the Arduino using a USB phone charger.
The Arduino Uno draws less than 100mA when connected by itself. So ideally you would want the USB phone charger to provide at least 100mA. All of the USB chargers I have come across to date provide more than 400mA. Most of the modern USB chargers provide upwards of 1A for fast charging of your phone.
A USB(2) port of a laptop can provide up to 700mA to the Arduino (500mA continuous).
In terms of the overall current draw, it really depends on what you have connected to the Arduino. LEDs generally draw 20mA or less per LED. Some screens can draw anything from <100mA to a couple of amps. Most of the screens I have come across draw less than 1A. It really depends on the devices you want to connect.
For the most part, a USB charger will be sufficient.

As you are still a beginner so I would not go into complex details. Your Arduino can run perfectly on a laptop powered USB but try to avoid connecting the power hungry electronics with your Arduino while powering it from the laptop USB port.
A Laptop USB port can give nearly 700mA that is enough for Arduino to run a couple of sensors easily.
Secondly, most wall chargers give 1A(1000mA) current that is better in my opinion. It can handle some power hungry electronics better then connecting your Arduino with the Laptop USB port.
I personally power my Arduino with either a Wall Charger or a power bank. Hope it helped solve your problem.
The more you dig into Arduino, the more fun it becomes. So have fun and be Creative.

How many V should the charger be? 5V or 12V? @M. Hussnain

He doesn't really have to worry about blowing up his USB port on the laptop, the arduino board has a 500mA poly fuse on the USB power in line so it should blow before his laptop USB gets damaged. You can't draw more than 500mA from USB, you can only draw about 1A from the barrel power jack, although it's the absolute maximum as the voltage regulator will get very hot very quickly.
@the.matrix the barrel jack must have more than 7 volts to get 5V out of it, but try to keep it as close to 7V, 9V is fine, 12V is meh. The bigger the voltage difference (Vin - 5), the hotter it will get.

And how many volts should a charger that goes into the USB be @Andrei Dragan ?

The USB voltage is 5V.

The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins on Arduino bypasses the regulator, and can damage your board.


text:
error: stray '\' in program with servo
I'm doing a project for school using Arduino to make a catapult, but I have this error that I didn't have the previous week.
Can anyone see the program and search where is the error?
#include <Servo.h> //libreria necesaria para utilizar el Servo

Servo catac; //motor de giro continuo utilizado

int ledPin = 13; //led conectado a agujero 13
int button = 8; //boton conectado a agujero 8
int estado = 0; //varaible que permite saber el estado del boton

void setup()
{
    pinMode(ledPin,OUTPUT);
    pinMode(button,INPUT);
    catac.attach(12); // servo unido al agujero 12
    catac.write(180); //coloca al servo en 180 grados
}

void loop()
{
    estado = digitalRead(button); //la variable obtiene el estado del boton
    if(estado == LOW)
    {
        digitalWrite(ledPin,HIGH); //prende led
        catac.write(70); //servo levanta a 70 grados la catapulta
        delay(500);
        digitalWrite(ledPin,LOW); //apaga led
        catac.write(180); //servo coloca a la catapulta en posicion original
    }
}

Error:
cataoukta:6: error: stray '\' in program
cataoukta:8: error: stray '\' in program
cataoukta:9: error: stray '\' in program
cataoukta:10: error: stray '\' in program
cataoukta:13: error: stray '\' in program
cataoukta:14: error: stray '\' in program
cataoukta:15: error: stray '\' in program
cataoukta:16: error: stray '\' in program
cataoukta:20: error: stray '\' in program
cataoukta:22: error: stray '\' in program
cataoukta:23: error: stray '\' in program
cataoukta:24: error: stray '\' in program
cataoukta:25: error: stray '\' in program
cataoukta:26: error: stray '\' in program
cataoukta:9: error: expected constructor, destructor, or type conversion before 'void'
cataoukta:6: error: expected initializer before 'u037e'
cataoukta.ino: In function 'void loop()':
cataoukta:20: error: 'estado' was not declared in this scope
cataoukta:20: error: 'button' was not declared in this scope
cataoukta:20: error: expected `;' before 'u037e'

Can you please post the exact error message.

I edit the post with the error ;)

The problem appears to be in your library. What version of Arduino IDE are you using? Are you using the built in Servo library?

Is this your full code?

My guess is you have some strange unicode character(s) in there. A common problem when not programming in English.

And yep, as soon as I copy and paste your code into a real IDE I get millions of boxes instead of semi-colons.

You have bad Unicode characters in your code. All your semicolons are something completely different and need replacing with real semicolons.

$ charinfo '13;'
U+0031 DIGIT ONE [Nd]
U+0033 DIGIT THREE [Nd]
U+037E GREEK QUESTION MARK [Po]


text:
Stuck on uploading sketch via USB 6 pin
I'm just got a Galileo Gen2 and wanted to try a simple blinking-led. The firmware have been updated to 1.0.4. My problem is whenever I try to upload the code I get this error:
Sketch uses 83,775 bytes (0%) of program storage space. Maximum is 10,000,000 bytes.
...
echo "Sending Command String to move to download if not already in download mode"
echo "~sketch downloadGalileo" > $tty_port_id

Deleting existing sketch on target
#Move the existing sketch on target.
echo "Deleting existing sketch on target"
"$fixed_path/lsz.exe" --escape -c "mv -f /sketch/sketch.elf /sketch/sketch.elf.old" <> $tty_port_id 1>&0
Login timed out after 60 secondsPoky 9.0.2 (Yocto Project 1.4 Reference Distro) 1.4.2 clanton /dev/ttyS1clanton login:`

The answer was simply that 6-pin are not designed for uploading sketches. Instead use the micro-USB port to upload sketches.


text:
Power issues with RFDuino
I am new to hardware, I have always used plug and play shields to accomplish simple projects. A while back I purchased RGB LED Shutter Shades from Macetech. I got the hacker version thinking I would add a RFDuino and use that to power the glasses and receive commands from my iPhone. I found out that the glasses needed 5v and the RFDuino could only do 3V. So i used a Sainsmart Nano v3 to control the LED's and I added a RFDunio to receive commands from my iPhone, the RFDuino is powered by the Nano.
The issue I am having is that when Im using an external battery pack, the kind you use to charge your phone, I'm guessing the power is not consistent enough and the RFDuino drops its connection to my phone. When I run the glasses using my computers USB port I do not have that problem.
My question: Is there something I can add to my circuit to make this inconsistency with my power stop happening?

I am the designer of the RGB Shades and co-own macetech LLC. The RFDuino specifications claim only 18mA on transmit and receive, so there should not be a current draw issue from that module.
Known power issues with the RGB Shades include high current draw on startup. They can pulse about 1.3 amps (the blue flash) before your software sets them to a more reasonable level. Most USB power packs made today can handle 1.0 amps, some can supply more, but it's still common to find packs limited to 500mA...that would be one thing to check.
Since you are using your own code, please also note that our default code on the controller-included RGB Shades sets the maximum brightness to about one-quarter the actual maximum brightness of the LEDs. This is done to conserve power as well as reduce brightness to non-blinding levels. If your code is attempting to operate at normal brightness, please be aware the RGB Shades could draw up to 4 amps.
The best way to detect the problem would be to get a multimeter and compare the supply voltage when connected to your computer and when connected to the USB power pack.

Upon closer inspection both of the battery packs I have were 500mA. Im thinking that must be the issue. Thanks.


text:
Need clarification with arduino syntax
I've been learning how to program this fine piece of equipment but i seem stuck. I came upon the "Knight rider" example where you are supposed to blink LED's from one side to another and i can't understand where some of the code comes from. For example:
byte ledPin[] = {4,5,6,7,8,9,10,11,12,13};
int ledDelay;
int direction = 1;
int currentLED  = 0;
unsigned long changeTime;
int pot = 2;
int i;

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

    for (i = 0; i < 10; i++)
    {
        pinMode(ledPin[i], OUTPUT);
    }

    changeTime = millis();
}

void loop()
{
    ledDelay = analogRead(pot);

    if ((millis()- changeTime) > ledDelay)
    {
        changeLED();
        changeTime = millis();
    }
}

void changeLED()
{
    for (i = 0; i < 10; i++)
    {
        digitalWrite(ledPin[i], LOW);
        Serial.print("i = ");
        Serial.println(i);
    }

    digitalWrite(ledPin[currentLED], HIGH);

    currentLED += direction;

    if (currentLED == 9)
    {
        direction = -1;
    }

    if (currentLED == 0)
    {
        direction = 1;
    }
}

In this code I don't  know where the "direction" variable is coming from I searched on the arduino reference page but can't find it. Are there other references where I could look or am I misunderstanding something?

It's coming from the program itself:
int direction = 1;

That means "Create a signed integer called 'direction' and assign it the value 1.

You defined the direction variable on the top with:
int direction = 1;

Yes I am fully aware of that. But in the sketch it is coloured red, if i rename it to "dir_etc" for example it is not highlighted by the IDE.  So i'm sure there is more to it than just me defining it. Hope my explanation is clear enoght.

Hm, that's interesting. What IDE are you using? It could be defined as a global variable in one of the files that you are including, but that sounds very unlikely to me. What files are you including in your project? Also (depending on your IDE) you might be able to right click on the variable and chose "View variable declaration" or something like that.

I'm using the official IDE v1.8.1 from the arduino site. Other than that i don't know to be using  any files for this sketch, but then again I'm just a beginner so i might be wrong. Also i can't find the "View variable declaration" you're  writing about.

Ok, so we ruled out a couple of things. I'm using the same IDE, but I haven't had a similar thing happen to me. Can you post a screenshot of how the code looks like (how the direction variable is colored)? And post the error message you receive?

Hope these images are clear enough   http://imageshack.com/a/img922/9182/9xd84Z.png http://imageshack.com/a/img923/8880/Fdx0x9.png

And i don't have any errors actually the sketch is running just fine I'm just trying to understand how the code works in order to modify it and it seemed strange that "direction" is highlighted red and i can't find it on the reference page.  Sorry for double post.

Aaa nice, the mystery is solved. All that means is some library author decided direction was a keyword (which is a horrible idea in my opinion). Searching and greping on my system says that this is person to blame: ./arduino/arduino-1.6.12/libraries/Stepper/keywords.txt (I don't know what system you run, but it should be in a similar hierarchy where you have Arduino IDE installed).

This however is not a problem for you (except that it's highlighted). When you define a direction variable in your code your variable will be used because of how variable scope works. This is not a language keyword, you can't define a variable named int (you might know all of this, if so sorry). So that's it :) I'll provide more links in a new comment. Feel free to ask more.

You can make your own keywords when writing a library so they are highlighted in the IDE (and only there) to make things nicer, an in your case someone decided to make the word direction a keyword in their library :)

Simple explanation of your case

A bit more complex explanation

Really detailed technical explanation

As I said feel free to ask more, and thanks, I learned something myself today! :)

Marvelous! Thanks for the help and sorry for the late reply.


text:
How do you make an Arduino count down timer?
I want to make a countdown timer with a LilyPad Arduino for 3 seconds with red (1 second), then orange(1 second), then yellow (1 second), then green (3 seconds), all being triggered by a button. I want to check to see if I have the right code. I am a self taught programmer, so apologies if this is a little messy. (or a lot)
#include <Adafruit_NeoPixel.h>
const int inputPin = 3;

void setup() {
  // put your setup code here, to run once:
  pinMode(inputPin, INPUT_PULLUP);
  strip.begin();
  strip.show();
}

void loop() {
  // put your main code here, to run repeatedly:
  If (digitalRead (inputPin) == LOW) {
    For (int i = 0; i < 12; I++) {
      Int pixelNum1 = 1;
      strip.setPixelColor( pixelNum1, 244, 0, 0);
      strip.show();
      delay (27);
      pixelNum1 ++;
    }

    For (int i = 0; i < 24; I++) {
      Int pixelNum2 = 1;
      strip.setPixelColor( pixelNum, 247, 247, 0)
      strip.show();
      delay (27);
      pixelNum ++;
    }

    For (int i = 0; i < 12; I++) {
      Int pixelNum3 = 1;
      strip.setPixelColor( pixelNum, 0, 247, 41)
      strip.show();
      delay (27);
      pixelNum ++;
    }
  }
}

[edit] your question. Select all the code and hit . Read editing-help for more info.

Also, If, For, and Int are not valid C++ keywords (unless you have some defines/typedefs). Please post the actual code.

Does the code do what you want it to?

variables are case sensitive so i and I are not the same variable

In addition to what has already been said, I would add these two
recommendations:

Do not repeat yourself. If you are repeating the same code, only with
different data, then put that data into an array and loop through it.
Define all your constants at the beginning, instead of having them as
“magic numbers” within the code itself.

Note that those are only good programming practices. They are not
critical for the functioning of your code, but they make it easier to
read and to maintain.
Applying those recommendations, here is my throw at this. Note that the
Color struct is only meant to make it easier to define colors as
constants:
#include <Adafruit_NeoPixel.h>

struct Color {
    uint8_t r, g, b;
};

const uint8_t  INPUT_PIN  =  3;
const uint8_t  STRIP_PIN  =  6;
const int      LED_COUNT  = 12;
const uint32_t LED_DELAY  = 27;
const int      NUM_COLORS =  4;
const Color    COLORS[NUM_COLORS] = {
                   {244,   0,  0},  // red
                   {247, 122,  0},  // orange
                   {247, 247,  0},  // yellow
                   {  0, 247, 41}   // green
               };

Adafruit_NeoPixel strip(LED_COUNT, STRIP_PIN);

void setup()
{
    pinMode(INPUT_PIN, INPUT_PULLUP);
    strip.begin();
    strip.show();
}

void loop()
{
    // Nothing to do until the button is pressed.
    if (digitalRead(INPUT_PIN) == HIGH)
        return;

    // Cycle through the colors.
    for (int i = 0; i < NUM_COLORS; i++) {
        Color color = COLORS[i];
        for (int led = 0; led < LED_COUNT; led++) {
            strip.setPixelColor(led, color.r, color.g, color.b);
            strip.show();
            delay(LED_DELAY);
        }
    }

    // Switch off.
    strip.clear();
    strip.show();
}

For (int i = 0; i < 12; I++) {
      Int pixelNum1 = 1;
      strip.setPixelColor( pixelNum1, 244, 0, 0);
      strip.show();
      delay (27);
      pixelNum1 ++;
    }

Assuming you fix the upper-case lower-case issues here first, you've still got a scope issue.  Since pixelNum1 is defined inside the for loop, it will go out of scope at the end of the for loop.  So it will be 1 on every iteration and it won't increment like you seem to think it will.
Why don't you just get rid of it altogether and use i+1 instead?


text:
Servo.attach method causing strange issue
I am using the L298N motor driver for a robotics project to control 4 motors. 2 motors in each input and output terminal. I have this connected to an Arduino Uno which is powered by about 7-8v from NiMH batteries. This battery source also powers a servo with a 470uF capacitor and the L298N board.
I have a strange problem when I use the servo attach method for my servo, only outputs 1 and 2 on the L298N start working meaning the wheels on the left of the robot start moving only. When I have the servo connected and imported the library but don't use the attach method, the L298N outputs to all DC motors meaning it works. Even when I use the servo attach method on a pin where nothing is connected to it, the motors on out 4 and 3 on the L298N don't move. For some reason this attach method is causing issues. Can anyone explain why?
Note:  I applied a larger power supply, from my 7V to about 12V but the problem still persists. I don't think power is the issue since the problem even happens when the attach method is called on a pin that has no servo connected to it.

Are you using PWM outputs for driving L298? If there is any of PWM outputs on the same Counter/Timer as Servo, it won't work, as Servo needs different settings for that timer.

what do you mean counter/timer

In the microcontroller used in the Arduino Uno, there are three Timer/Counter modules. Each of them has two hardware PWM channels. If you mix up one PWM output and one Servo output, it'll change settings for PWM and it might stop working (thats a problem mainly for Timer1). Pins 3 and 11 are on Timer2, 9 and 10 on Timer1 and pins 5 and 6 are on Timer0 (this one is used for millis() too)

I agree with @KIIV . It seems a problem with Servo library and PWM outputs (specially with pins 9 and 10).

If possible, could you please include your code and your schematic?

The L298N boards can either control stepper motors or general DC motors. You have mentioned that you are using the servo library which is for servo motors which generally only rotate 180 degrees. Can you please clarify what motors you are using?

We need to see your code and schematic.


text:
HMC5883L tilt compensation
I have a HMC5883L 3-axis magnetometer. I would like to add tilt compensation to my Arduino Uno project.
Since the IC has 3 axis that it measures (X,Y,Z) is it possible to add tilt compensation without an accelerometer? If yes would this how do I find an equation to do the calculation. Is this equation found from http://bluelemonlabs.blogspot.fi/2013/08/arduino-simple-compass-with-hmc5883l.html correct?

No. You need an accelerometer.
If you read the article you link to you can see this bit:

There are many margin of improvement. First, we ought compensate the potential tilt of the device using the accelerometer data from the ADXL345, for example using the info on my previous post!

To do tilt compensation you need three axes of both magnetometer data and accelerometer data to scale and merge those three axes.


text:
Peak counting in serial Arduino
I want to count peak of photocell data with serial communication in Arduino.
Here is the question. My problem is when I count one of the peaks it continues the counting and doesn't stop counting. My project is count Michelson Morley fringes with a photocell and Arduino.
If somebody can help me with the coding part I would appreciate it.
Here is the code that I used:
int count=0;
int val;
int data;

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

void loop() {
  data=analogRead(A0);
  val=map(data,0,1023,1000,0);
  if(val>700) {
   count++;
  }
  Serial.println(count);
  delay(100);
}

This picture shows what I am trying to achieve:

Example Michelson Morley fringes:

keep in mind that since you used
delay(100)

your 'loop' code runs in 10HZ (10 times a second)
So, every time you are lighting on your sensor, if its for longer than 1/10 of a second, you are likely going through several instances of 'loop', in which the condition
(val>700)

is satisfied.
If you know that your peaks are going to take several loops, and only want to count each peak once- a simple way would be to make sure you dropped from the previous peak before incrementing the counter. you can achieve that with something like:
int count=0;
int val;
int data;
bool inPeak = false;

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

void loop() {
  data=analogRead(A0);
  val=map(data,0,1023,1000,0);
  if(val>700) {
     if (!inPeak)
     {
        count ++;
        inPeak = true;
     }
  }
  else
  {
      inPeak = false;
  }

  Serial.println(count);
  delay(100);
}


text:
Readings changing in hall effect sensor
I am using a A1324 hall effect sensor for a distance measuring.
The voltage output keeps changing even if the distance between the magnet and sensor does not change. The output changes +-0.200V and I am trying to measure the distances at steps of 0.01V.

What values do you see? What is the range of the changes?

The output changes +-0.200V and I am trying to measure the distances at steps of 0.01V.

What variation in Gauss do you expect? What mathematic/design do you have?

I am not interested in measuring the magnetic flux in my project. The main aim is to measure the distance from a magnet. I am using a voltage divider method to  get the voltage output from the hall effect sensor.

From https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/

analogRead()
Reads the value from the specified analog pin. The Arduino board
  contains a 6 channel (8 channels on the Mini and Nano, 16 on the
  Mega), 10-bit analog to digital converter. This means that it will map
  input voltages between 0 and 5 volts into integer values between 0 and
  1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.

It is likely what you are seeing is noise and is to be expected. The source of the noise is likely multiple and could be environmental physical metallic or magnetic objects some distance away that are moving, electrical wiring (mains) nearby, and noise introduced by the power supply to the Arduino.
If you want to get a stable precise reading that close to the minimum step size, you will want to take several readings and average them. The more you read and average, the more you can eliminate the random effect of the noise, but the tradeoff is that it is slower because you are taking tens or hundreds of readings just for one result.

I was reading online that I can use filters to reduce the noise. But I have never worked with filters before could you suggest a way to start with that ?


text:
How to count the voltage pulses of a digital temperature sensor using Arduino Mega Atmega2560?
I have a digital temperature sensor which gives digital output in the form of current pulses. The number of pulses corresponds to a particular temperature.
I have converted the current pulses to voltage pulses using transistor as a level shifter. I want to count the number of pulses for a time interval of 50ms each time.
Please help me with the algo and the code.

Please give us more information such as which temperature sensor you are using, your circuit diagram, what you have tried and perhaps your code so far. See [ask].

I'm using lmt01 digital sensor . I'm a beginner in coding . So counting the no. Of current pulses is also fine .

There are function called pulseIn which probably need exactly what you want.
Just set a variable with the current 'time' (millis, start counting until the current time reaches 50 ms later.
So something like (not checked):
unsigned long timer = millis();
unsigned pulses = 0;
while (timer + 50 < millis())
{
  pulseIn(PIN, LOW);
  pulses++;
}

PIN is a constant or variable that defines the pin number to check, LOW is to check low pulses, you also can use high, and optionally you can add a timeout. For example, you can use the timeout to check the last timeout is within the 50 ms region. Or to be more precise, check if the pulse was within the same 50 ms:
unsigned long timer = millis();
unsigned pulses = 0;
while (timer + 50 < millis())
{
  pulseIn(PIN, LOW);
  if (timer + 50 < millis())
  {
    pulses++;
  }
}


text:
Using a MOSFET module to control DC LED PWM
I've seen some similar questions here for using MOSFET to control 12V LEDs
But apparently the only MOSFET currently available to us is a 2-MOSFET high power trigger module, details in the link below.
https://www.elecrow.com/high-power-mosfet-trigger-switch-drive-module.html
How do we connect this to the Arduino to send the PWM trigger (I get confused by the three holes) and how do we connect the DC power to this??? I get confused with the power connections.

Did the picture with labels that tell you what connects where not help you?

The three TRIG/PWM pins are connected to the same electrical point. The same goes for the three GND pins.
You can either solder:

A 2-pin 0.2 inch screw terminal (the very same kind of those blue connectors already in the board) to the pair of big holes closer to the edge, or
A 2-pin 0.1 inch header to the 2 holes in the centre of the 4-hole row (the smaller ones).

These will be the control input you should be connecting your Arduino to.
The DC power supply for the load that will be switched by the MOSFETS has to be connected between the VIN+ and VIN- terminals. Note that VIN- is connected internally to GND.
Your load has to be connected between the OUT+ and OUT- terminals.
That's all you need to know. In case you're in doubt, I've drawn this schematic for you (see below)

simulate this circuit – Schematic created using CircuitLab
IMPORTANT ADDITIONAL NOTES:

No flyback diodes are present in the board. If you try to switch an inductive load (a motor, a solenoid, etc.) with this board you have a high risk of damaging the MOSFETs and rend it useless.
You need at least a 5V control signal for switching high current loads with this board. Although a 3.3V control may seem able to switch the MOSFET, its internal RdsON at 3.3V could easily be high enough to produce excessive power dissipation and blow up the MOSFET. See these curves from the AOD4184 datasheet:

it seems to be a typical low-side switch (dual switches). the load goes into DC+ and DC- --> ask the manufactuer to be sure.
whether it works for you will depend on the load, driving signal and the mosfet used -> you should ask the seller for a schematic, or buy one and reverse engineer it.

I'm afraid that's wrong.


text:
Does a Sparkfun Redboard Arduino Uno have built-in RTC?
I have a Sparkfun Redboard (an Arduino Uno like board based on the Atmega328P and programmed with the Arduino bootloader).
I have been trying to make an accurate clock without an RTC with an LCD screen and it's been hard.
Does the Sparkfun Redboard have built-in RTC?

Sparkfun Redboard is NOT Arduino Uno

the schematic is right on the sparkfun.com website ... have you looked at it?

@jsotola yes I have p.s. it works like an Arduino uno

Sparkfun Redboard and Arduino Uno do not have built-in RTC.

The new "Sparkfun Redboard Turbo" does have an RTC on pins A5 and AREF


text:
Controlling an LED using SIM900A and Arduino
How can I turn the LED on and off using a received text message?
The sim card is able to receive the message but I can't change the pin status. I also can't see anything in the serial monitor upon reception of the message.
Below is my code.
#include <SoftwareSerial.h>
SoftwareSerial gsm(2,3);
String msg;
const int LED = 13;

void setup() {
  gsm.begin(9600);
  Serial.begin(9600);
  Serial.println("PUMP CONTROL");
  Serial.println("t : to receive text");
  delay(1000);

  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
}

void loop() {
  if (Serial.available()>0)
  switch(Serial.read())
  {
    case 't':
    showSMS();
    break;
  }
  if (gsm.available()>0)
  Serial.write(gsm.read());

  if ( msg == "ON")
  {
    digitalWrite(LED, HIGH);
    delay(1000);
  }
  if (msg == "OFF")
  {
    digitalWrite(LED, LOW);
    delay(1000);
  }
}

void showSMS()
{
 gsm.print("AT+CMGF=1\r");
 gsm.print("AT+CNMI=2,2,0,0,0\r");
 delay(1000);
 if (gsm.available()>0)
 {
  msg=gsm.read();
  Serial.print(msg);
 }
}

gsm.read() returns a single character not a string.

Try this code.
#include <SoftwareSerial.h>
SoftwareSerial gsm(2,3);
String msg;
const int LED = 13;

void setup() {
  gsm.begin(9600);
  Serial.begin(9600);
  Serial.println("PUMP CONTROL");
  Serial.println("t : to receive text");
  delay(1000);

  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
}

void loop() {
  if (Serial.available()>0)
  switch(Serial.read())
  {
    case 't':
    showSMS();
    break;
  }

  while(gsm.available() > 0)
  {
    Serial.write(gsm.read());
  }

  if ( msg == "ON")
  {
    digitalWrite(LED, HIGH);
    delay(1000);
  } else if (msg == "OFF")
  {
    digitalWrite(LED, LOW);
    delay(1000);
  }
  if(msg != "") msg = "";
}

void showSMS()
{
 gsm.print("AT+CMGF=1\r");
 gsm.print("AT+CNMI=2,2,0,0,0\r");
 delay(1000);
 msg = "";
 while(gsm.available() > 0)
 {
  msg += gsm.read();
 }
 Serial.println(msg);
}

This code works like charm.


text:
Controlling a 5m LED strip with a Nano or Uno
I'm wanting to control a 12V LED strip (5m, 60 LEDs per meter) with a Nano or Uno. I know from Adafruit that I'll need some power transistors but I'm not sure that I have the right type. I have 6 transistors labelled 30N06L, and I'm hoping they're equivalent to the ones used. Are mine ok to use, or do I need to buy others?

You have a lot of LEDs that you need to power so lets run through the calculations. Assuming that they are RGB LED strips, ie 3 LEDs per physical LED:
5 x 60 x 3 = 900 LEDs

Assuming each has a current draw of 20mA, that is (900 x 20mA) 18A of total current if all are on at the same time at full brightness.
Since each colour will be controlled by its own FET, each FET will be required to drive 6A at full brightness.
The FET that you have is a Fairchild FQP30N06L 60V LOGIC N-Channel MOSFET that can drive up to 32A. Of course, that would need a large heatsink at that current.
If you plan to have any of the colours on at full brightness for extended periods I would recommend putting a heat sink on the tab to help dissipate the heat.
The Arduino Uno/Nano uses a 328P microcontroller at 5V which, according to the datasheet, is suitable to drive the FET.
These FETs should do the job.

I'd add that the wiring for the strips should be carefully chosen, since letting 18A pass through a single piece of strip will cause problems... Moreover how could you say that they are RGB LEDs? They can also be white 5050, and so 18A will need to pass through the same transistor...

The assumption of RGB came from the Adafruit link in the OP's question. I could be wrong.

Please also note that I am assuming 20mA per LED. The calculations will change depending on the current draw of each LED.


text:
Transmit data to long distance (120m)
I want to transmit data from multiple sensors to an Arduino and distance would be approximately 120 meters.
What protocol or configuration should I use?
Actually I am trying to read values from 5 temperature sensors located in 5 different spots of warehouse. I want to read them and trigger some relay based on the values.
I thought about I2C but I have read somewhere that its not built for long distances. Also thought about RS-485, but I don't know if that supports bus (connect all sensors to same line).
Which solution do you suggest?

You want to transmit ~120m over wire. If wireless is adequate, see SX1278 ICs and LoRaLib (50m in dense forest, 200m in urban terrain, more with LOS). If you stick with wired, use CAT5 cable or better, it’s well insulated against EMI and cheap. CAT5E/CAT6 is better, costs a bit more. You could use coax RG6, which is just wonderful.

While thinking about RS-485, did you read about it? It is a bus. It is designed for long distances.

So if i use rs485(via max485) will i have to use microcontroller on every side between bus and sensors ? Or its enough to connect the sensor (analog sensor) to max485 directly ?

You will need some kind of controller to react to the bus. RS-485 is a digital bus specification, you cannot just put analog signals on it... Each node will have to have an address assigned to it and respond to the bus master's requests.

Thanks for your answer jose. One last question: will i need that kind of controllers if the sensors be digital?

Since this is arduino.stackexchange -- An Arduino will make an excellent bus access controller. And you will need one even if the sensor is digital. Something has to have the smarts to handle bus access.

I2C is not built for long distances (max. some meters) But you can make it via RS485, But you will need to add termination resistors to each end.


text:
Arduino SD count files and open last, How to?
I am trying to count files. I have one hidden file from Windows10 so i am doing "-1" but I want to open the last file and can't work out how, any help? Please, Thanks
#include <SD.h>
int entryCount = 0;
File root;
int total = 0;
int Lfile = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(10, OUTPUT);
  SD.begin(4);
  root = SD.open("/");
  printDirectory(root, 0);
  root.close();
  Serial.println();
  Serial.print(total-1);
  Lfile = total-1;

  File dataFile = SD.open(Lfile);
  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println();
    Serial.println("error opening last file");
  }
}

void loop()
{
  // nothing happens after setup finishes.
}

void printDirectory(File dir, int numTabs)
{
  while (true)
  {
    File entry = dir.openNextFile();
    if (! entry)
    {
      if (numTabs == 0)
      return;
    }
    for (uint8_t i = 0; i < numTabs; i++)
      Serial.print('\t');
    Serial.println(entry.name());
    total = entryCount;

    Serial.print(entryCount++);

    Serial.print('\t');

    entry.close();

  }
}

what does last file mean?

sd card have files log01.txt, log02.txt, etc. Last file is last file which was created

Consider using the exist() method found in the SD.h library you already are including in your program.  Assuming you will create no more than 99 files and the last file created will have the highest 2 digit value as part of its name, test for the existence of the file log99.txt.  If not found, decrement the 2 digit number and test for the existence of file log98.txt.  Repeat this process until you find the newest file created.


text:
WS2812 Stair lighting - not all LEDS lighting up
I'm doing a Arduino based stair light project and have a little problem with the code. I have used Simon Jowett's code from the instructable website which after a couple of tweaks works perfect. Apart from the final section, the waterfall effect. The original project used 117 WS2812 LED's I'm using 188. When the white LED's trigger running up or down the stairs they work fine on all 188, the breathe LED's light up on the first and last LED too. But the waterfall effect stops at LED 117. Can anyone see if there is somewhere else that I need to change the amount of LED's in the code apart from here Adafruit_NeoPixel strip = Adafruit_NeoPixel(188, PIN, NEO_GRB + NEO_KHZ800);? Thanks
// "Bling" up your Staircase By Simon Jowett November 2014
// Thanks to the Neopxel Library by Adafruit

#include <Adafruit_NeoPixel.h>
//#define LDRSensor 1
#define PIN 3

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(188, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

// Set up Variables
 unsigned long timeOut=60000; // timestamp to remember when the PIR was triggered.
 int downUp = 0;              // variable to rememer the direction of travel up or down the stairs
 int alarmPinTop = 5;        // PIR at the top of the stairs
 int alarmPinBottom =7;      // PIR at the bottom of the stairs
 int alarmValueTop = LOW;    // Variable to hold the PIR status
 int alarmValueBottom = LOW; // Variable to hold the PIR status
 int ledPin = 13;           // LED on the arduino board flashes when PIR activated
 int LDRSensor = A0;        // Light dependant resistor
 int LDRValue = 0;          // Variable to hold the LDR value
 int colourArray[350];      // An array to hold RGB values
 int change = 1;            // used in 'breathing' the LED's
 int breathe = 0;           // used in 'breathing' the LED's

void setup() {
   strip.begin();
   strip.show(); // Initialize all pixels to 'off'
   Serial.begin (9600);  // only requred for debugging
   pinMode(ledPin, OUTPUT);  // initilise the onboard pin 13 LED as an indicator
   pinMode(alarmPinTop, INPUT_PULLUP);     // for PIR at top of stairs initialise the input pin and use the internal restistor
   pinMode(alarmPinBottom, INPUT_PULLUP);  // for PIR at bottom of stairs initialise the input pin and use the internal restistor
   delay (100); // it takes the sensor 2 seconds to scan the area around it before it can
   //detect infrared presence.
   for (int i=0 ;i < 350; i++)  { // initilise the colourArray to zero
   colourArray[i]=0;
   }
}

void loop() {

  LDRValue = analogRead(LDRSensor);
  Serial.println(LDRValue);

  if (timeOut+57000 < millis()) {        // idle state - 'breathe' the top and bottom LED to show program is looping

     breathe = breathe + change;
     strip.setPixelColor(0,0,0,breathe);
     strip.setPixelColor(187,0,0,breathe);
     strip.show();
     if (breathe == 100 || breathe == 0) change = -change;      // breathe the LED from 0 = off to 100 = fairly bright
     if (breathe == 100 || breathe == 0) delay (300);           // Pause at beginning and end of each breath
     delay(25);
  }

  if (LDRValue > 1010) {        // only switch on LED's at night when LDR senses low light conditions - you may have to change the number for your circumstances!

    alarmValueTop = digitalRead(alarmPinTop);        // Constantly poll the PIR at the top of the stairs
    alarmValueBottom = digitalRead(alarmPinBottom);  // Constantly poll the PIR at the bottom of the stairs

    if (alarmValueTop == HIGH && downUp != 2)  {      // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it.
      timeOut=millis();  // Timestamp when the PIR is triggered.  The LED cycle wil then start.
      downUp = 1;
      topdown();         // lights up the strip from top down
    }

    if (alarmValueBottom == HIGH && downUp != 1)  {    // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it.
      timeOut=millis();    // Timestamp when the PIR is triggered.  The LED cycle wil then start.
      downUp = 2;
      bottomup();         // lights up the strip from bottom up
    }
    if (timeOut+10000 < millis() && timeOut+15000 < millis()) {    //switch off LED's in the direction of travel.
       if (downUp == 1) {
          colourWipeDown(strip.Color(0, 0, 0), 50); // Off
       }
       if (downUp == 2)  {
        colourWipeUp(strip.Color(0, 0, 0), 50);   // Off
       }
      downUp = 0;
      //   for (int i=0 ;i < 350; i++)  {          // Depending on your preference you may want to include this loop to clear out the colourArray
      //    colourArray[i]=0;
      // }
    }

    if (timeOut+15000 < millis() && timeOut+54999 > millis()) waterfall();    // Waterfall effect to play between these times after a PIR trigger.

    if (timeOut+55000 < millis() && timeOut+56999 > millis()) fade();   // Fade/switch off LED's
  }
}

 void topdown() {
    Serial.println ("detected top");                // Helpful debug message
    colourWipeDown(strip.Color(50, 50, 30), 10);    // Warm White
    for(int i=0; i<3; i++) {                        // Helpful debug indication flashes led on Arduino board twice
      digitalWrite(ledPin,HIGH);
      delay(200);
      digitalWrite(ledPin,LOW);
      delay(200);
    }
 }

 void bottomup() {
    Serial.println ("detected bottom");          // Helpful debug message
    colourWipeUp(strip.Color(50, 50, 30), 10);   // Warm White
    for(int i=0; i<3; i++) {                     // Helpful debug indication flashes led on Arduino board twice
      digitalWrite(ledPin,HIGH);
      delay(200);
      digitalWrite(ledPin,LOW);
      delay(200);
    }
  }

 // Fill the dots one after the other with a color
 void colourWipeDown(uint32_t c, uint8_t wait) {
   for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
 }

 // Fill the dots one after the other with a color
 void colourWipeUp(uint32_t c, uint8_t wait) {
   for(uint16_t i=strip.numPixels(); i < -1; i--) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
 }

 // Play the Waterfall effect
 void waterfall(){
    for(int i= 347; i>-1; i--) {            // Shift the RGB colours down in the colourArray[]
        colourArray[i+3]=colourArray[i];
        }
      colourArray[0] = random(0,20);        // Genearate the red component of the 1st LED at the top of the stairs
      colourArray[1] = random(0,40);        // Genearate the green component of the 1st LED at the top of the stairs
      colourArray[2] = random(10,70);       // Genearate the blue component of the 1st LED at the top of the stairs

      for (int k=0; k<351; k=k+3)   {       // Set and send the colours to the strip
       uint32_t c = strip.Color(colourArray[k],colourArray[k+1],colourArray[k+2]);
       strip.setPixelColor(((k+3)/3)-1,c);
       }

      strip.show();      // and display the result
      delay(35);         // delay to simulate running water
 }

 // Play the LED fade out
 void fade(){
 for (int j = 0; j <70; j++) {
   for(int i=350; i>-1; i--) {
     colourArray[i]=colourArray[i]-1;      // reduce intensity of light by 1
     if (colourArray[i] <= 0 ) colourArray[i] = 0;
   }
   for (int k=0; k<351; k=k+3)   {
     uint32_t c = strip.Color(colourArray[k],colourArray[k+1],colourArray[k+2]);
     strip.setPixelColor(((k+3)/3)-1,c);
   }
  strip.show();
  delay(60);
  }
 breathe = 0;
 change = 1;
 }

Added a link to the Instructable website.  Please comment if not correct.

Is there a specific reason, why you use an int array for the LED color values, instead of the CRGB typed array, that is used in all the NeoPixel examples?

This line in the code:
 int colourArray[350];      // An array to hold RGB values

...contains 3 values for each LED.  But 350 / 3 is 116.67.  This value should likely have been 117 * 3 = 351 for the original code.  And for the posted code using 188 LEDs this likely should be 188 * 3 = 546.
This same problem of indexing into the colourArray repeats several more times in the code where the array is cleared out, assigned random values and used to control the LEDs.  Normally, well written code uses "#define" directive to set such values once at the beginning of the code allowing the compiler to make adjustments when compiling / uploading the Arduino sketch.
The "#define" used for Arduino sketches is the same as used in C programming.  (As Arduino sketches are actually C programs.) Normally, defines are found at the top of a file.  Defines are a way of substituting an meaningful name for something a bit hard to understand at first.  We can even use a bit of math to keep errors down as the compiler will solve it for us before uploading the code:
#define LED_NUMBER_OF (3*188)

Later in the code we can use the define:
int colourArray[LED_NUMBER_OF];      // An array to hold RGB values

Still later in the code we can use the define again:
for (int i=0 ;i < LED_NUMBER_OF; i++)  { // initilise the colourArray to zero
  colourArray[i]=0;
}

Thanks st2000, I've adjusted the code as you suggested will I need to do the same for the waterfall section?

Probably.  The quick (and maybe good enough) approach is to search for the number 350 and decide if what you want can be achieved by substituting 546 or the define LED_NUMBER_OF of you went that route.

I've just tried the edited code but now the LED's won't work at all?? I'm sure its something I've done wrong.
#include <Adafruit_NeoPixel.h>

#define PIN 3

#define LED_NUMBER_OF (3*188)

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(188, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

// Set up Variables
 unsigned long timeOut=60000; // timestamp to remember when the PIR was triggered.
 int downUp = 0;              // variable to rememer the direction of travel up or down the stairs
 int alarmPinTop = 5;        // PIR at the top of the stairs
 int alarmPinBottom =7;      // PIR at the bottom of the stairs
 int alarmValueTop = LOW;    // Variable to hold the PIR status
 int alarmValueBottom = LOW; // Variable to hold the PIR status
 int ledPin = 13;           // LED on the arduino board flashes when PIR activated
 int LDRSensor = A0;        // Light dependant resistor
 int LDRValue = 0;          // Variable to hold the LDR value
 int colourArray[LED_NUMBER_OF];      // An array to hold RGB values
 int change = 1;            // used in 'breathing' the LED's
 int breathe = 0;           // used in 'breathing' the LED's

void setup() {
   strip.begin();
   strip.show(); // Initialize all pixels to 'off'
   Serial.begin (9600);  // only requred for debugging
   pinMode(ledPin, OUTPUT);  // initilise the onboard pin 13 LED as an indicator
   pinMode(alarmPinTop, INPUT_PULLUP);     // for PIR at top of stairs initialise the input pin and use the internal restistor
   pinMode(alarmPinBottom, INPUT_PULLUP);  // for PIR at bottom of stairs initialise the input pin and use the internal restistor
   delay (100); // it takes the sensor 2 seconds to scan the area around it before it can
   //detect infrared presence.
   for (int i=0 ;i < LED_NUMBER_OF; i++)  { // initilise the colourArray to zero
   colourArray[i]=0;
   }
}

void loop() {

  LDRValue = analogRead(LDRSensor);
  Serial.println(LDRValue);

  if (timeOut+57000 < millis()) {        // idle state - 'breathe' the top and bottom LED to show program is looping

     breathe = breathe + change;
     strip.setPixelColor(0,0,0,breathe);
     strip.setPixelColor(187,0,0,breathe);
     strip.show();
     if (breathe == 100 || breathe == 0) change = -change;      // breathe the LED from 0 = off to 100 = fairly bright
     if (breathe == 100 || breathe == 0) delay (300);           // Pause at beginning and end of each breath
     delay(25);
  }

  if (LDRValue > 1010) {        // only switch on LED's at night when LDR senses low light conditions - you may have to change the number for your circumstances!

    alarmValueTop = digitalRead(alarmPinTop);        // Constantly poll the PIR at the top of the stairs
    alarmValueBottom = digitalRead(alarmPinBottom);  // Constantly poll the PIR at the bottom of the stairs

    if (alarmValueTop == HIGH && downUp != 2)  {      // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it.
      timeOut=millis();  // Timestamp when the PIR is triggered.  The LED cycle wil then start.
      downUp = 1;
      topdown();         // lights up the strip from top down
    }

    if (alarmValueBottom == HIGH && downUp != 1)  {    // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it.
      timeOut=millis();    // Timestamp when the PIR is triggered.  The LED cycle wil then start.
      downUp = 2;
      bottomup();         // lights up the strip from bottom up
    }
    if (timeOut+10000 < millis() && timeOut+15000 < millis()) {    //switch off LED's in the direction of travel.
       if (downUp == 1) {
          colourWipeDown(strip.Color(0, 0, 0), 50); // Off
       }
       if (downUp == 2)  {
        colourWipeUp(strip.Color(0, 0, 0), 50);   // Off
       }
      downUp = 0;
      //   for (int i=0 ;i < 350; i++)  {          // Depending on your preference you may want to include this loop to clear out the colourArray
      //    colourArray[i]=0;
      // }
    }

    if (timeOut+15000 < millis() && timeOut+54999 > millis()) waterfall();    // Waterfall effect to play between these times after a PIR trigger.

    if (timeOut+55000 < millis() && timeOut+56999 > millis()) fade();   // Fade/switch off LED's
  }
}

 void topdown() {
    Serial.println ("detected top");                // Helpful debug message
    colourWipeDown(strip.Color(50, 50, 30), 10);    // Warm White
    for(int i=0; i<3; i++) {                        // Helpful debug indication flashes led on Arduino board twice
      digitalWrite(ledPin,HIGH);
      delay(200);
      digitalWrite(ledPin,LOW);
      delay(200);
    }
 }

 void bottomup() {
    Serial.println ("detected bottom");          // Helpful debug message
    colourWipeUp(strip.Color(50, 50, 30), 10);   // Warm White
    for(int i=0; i<3; i++) {                     // Helpful debug indication flashes led on Arduino board twice
      digitalWrite(ledPin,HIGH);
      delay(200);
      digitalWrite(ledPin,LOW);
      delay(200);
    }
  }

 // Fill the dots one after the other with a color
 void colourWipeDown(uint32_t c, uint8_t wait) {
   for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
 }

 // Fill the dots one after the other with a color
 void colourWipeUp(uint32_t c, uint8_t wait) {
   for(uint16_t i=strip.numPixels(); i < -1; i--) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
 }

 // Play the Waterfall effect
 void waterfall(){
    for(int i= 350; i>-1; i--) {            // Shift the RGB colours down in the colourArray[]
        colourArray[i+3]=colourArray[i];
        }
      colourArray[0] = random(0,20);        // Genearate the red component of the 1st LED at the top of the stairs
      colourArray[1] = random(0,40);        // Genearate the green component of the 1st LED at the top of the stairs
      colourArray[2] = random(10,70);       // Genearate the blue component of the 1st LED at the top of the stairs

      for (int k=0; k<350; k=k+3)   {       // Set and send the colours to the strip
       uint32_t c = strip.Color(colourArray[k],colourArray[k+1],colourArray[k+2]);
       strip.setPixelColor(((k+3)/3)-1,c);
       }

      strip.show();      // and display the result
      delay(35);         // delay to simulate running water
 }

 // Play the LED fade out
 void fade(){
 for (int j = 0; j <70; j++) {
   for(int i=350; i>-1; i--) {
     colourArray[i]=colourArray[i]-1;      // reduce intensity of light by 1
     if (colourArray[i] <= 0 ) colourArray[i] = 0;
   }
   for (int k=0; k<351; k=k+3)   {
     uint32_t c = strip.Color(colourArray[k],colourArray[k+1],colourArray[k+2]);
     strip.setPixelColor(((k+3)/3)-1,c);
   }
  strip.show();
  delay(60);
  }
 breathe = 0;
 change = 1;
 }
~~~~~~

Likely you needed to use the LED_NUMBER_OF define where ever you access the colourArray array.  I see you changed 350 to 351 in some places.  Perhaps if you tried using  LED_NUMBER_OF instead of 351.  Also, note there is one line of code where you need to use (LED_NUMBER_OF - 3) because you add 3 to the index of the FOR loop inside the loop.  And it is bad to access locations past the end of any array!

Try not to re-post your question as an answer. Remember that stack exchange / stack overflow web sites are trying to become a list of searchable questions and answers. This will make it really confusing for people with similar issues.

if your program is working can you do 2 things?  1. Delete this answer and if you need to edit your question should you wish to add additional information to make the question better.  2. If an answer is correct (that is, if the answer help fix the issue in the question), please mark it correct so that others can see what worked for you.  Thanks.


text:
RGBs and Potentiometers
I think my if statement can't be read here in my program. The RGBs should light up and change color when the potentiometer is turned but instead the RGBs just light up immediately and change color simultaneously. How do I fix this?
int POT1=A0;
int POT2=A1;
int POT3=A2;
int Red1=9;
int Green1=10;
int Blue1=11;
int Red2=3;
int Green2=5;
int Blue2=6;
int sValue1=0;
int sValue2=0;
int sValue3=0;
int oValue1=0;
int oValue2=0;
int oValue3=0;
int value1=0;
int value2=0;
int value3=0;
int timer(250);

void setup() {
 Serial.begin(9600);
 pinMode(Red1,OUTPUT);
 pinMode(Green1,OUTPUT);
 pinMode(Blue1,OUTPUT);
 pinMode(Red2,OUTPUT);
 pinMode(Green2,OUTPUT);
 pinMode(Blue2,OUTPUT);

}

void loop() {

sValue1=analogRead(POT1);
sValue2=analogRead(POT2);
sValue3=analogRead(POT3);

oValue1=map(sValue1,0,1023,0,255);
oValue2=map(sValue2,0,1023,0,255);
oValue3=map(sValue3,0,1023,0,255);

if ((sValue1<=127)&&(sValue2<=127)&&(sValue3<=127));
{
  setColor1(0,255,255); //red
  setColor2(255,255,0); //blue
  delay(timer);
  value1=0;
  value2=0;
  value3=0;

}

if ((sValue1<=127)&&(sValue2<=127)&&(sValue3>127));
{
  setColor1(255,255,0); //blue
  delay(timer);
  setColor2(255,0,255); //green
  delay(timer);
  value1=0;
  value2=0;
  value3=1;
}

if ((sValue1<=127)&&(sValue2>127)&&(sValue3<=127));
{
  setColor1(255,0,255); //green
  delay(timer);
  setColor2(0,255,255); //red
  delay(timer);
  value1=0;
  value2=1;
  value3=0;
}

if ((sValue1<=127)&&(sValue2>127)&&(sValue3>127));
{
  setColor1(0,255,255); //red
  delay(timer);
  setColor2(255,0,255); //green
  delay(timer);
  value1=0;
  value2=1;
  value3=1;
}

Serial.print("POT 1=");
Serial.print(value1);
Serial.print("\t POT 2=");
Serial.print(value2);
Serial.print("\t POT 3=");
Serial.print(value3);

if ((value1==0)&&(value2==0)&&(value3==0))
{
 Serial.print("\t RGB1=");
 Serial.print("RED");
 Serial.print("\t RGB2=");
 Serial.print("BLUE");
}

else if ((value1==0)&&(value2==0)&&(value3==1))
{
  Serial.print("\t RGB1=");
  Serial.print("BLUE");
  Serial.print("\t RGB2=");
  Serial.println("GREEN");
  Serial.println(" ");
}

else if ((value1==0)&&(value2==1)&&(value3==0))
{
  Serial.print("\t RGB1=");
  Serial.print("GREEN");
  Serial.print("\t RGB2=");
  Serial.println("RED");
  Serial.println(" ");
}

else if ((value1==0)&&(value2==1)&&(value3==1))
{
  Serial.print("\t RGB1=");
  Serial.print("RED");
  Serial.print("\t RGB2=");
  Serial.println("GREEN");
  Serial.println(" ");
}

}

void setColor1(int red1, int green1, int blue1){
  {
    analogWrite(Red1,red1);
    analogWrite(Green1,green1);
    analogWrite(Blue1,blue1);
  }
}

void setColor2(int red2, int green2, int blue2){
  {
    analogWrite(Red2,red2);
    analogWrite(Green2,green2);
    analogWrite(Blue2,blue2);

  }
}

The code you posted is more complex than your description.  Assuming you copied and pasted it, try simplifying it.  You only need a few lines to change the color of the LEDs based on the position of a potentiometer.  Include either a description of your hardware connections, a schematic or a clear picture of your wiring. Then edit this question.

By the way, why not just use your pot values (scaled to 0-255) to set the red, green, and blue channels of your LEDs directly?

How do I do that?????

I haven't traced through your if statement logic in detail to see what you are trying to do, BECAUSE I found that you have statements like this:
//            Get rid of this semicolon in every if statement.
//            |
//            V
if (condition); {
    //        ^
    //        |

    //Code that will always be executed
}

You should NOT have a semicolon after an if statement like that. That says "if (condition) then do nothing" (A semicolon creates a blank "do-nothing" statement that becomes the code that is executed if the if statement is true. Then the code in the braces gets executed every time.)
It is parsed as:
if (condition) <empty_statement;>

{
    code that always executes
}

That is one of the hidden "nasties" of C and it's close cousins like C++, Java, and Objective-C. Another nasty is typing:
if (a=b)

...when you mean if (a==b). (The first version puts the value of b into a, and then evaluates b as a boolean. If it's 0, the if statement is treated as false. If it's non-zero, the if statement is evaluated as true.
Another one is the fall-through cases in C switch statements. If you forget to add a break statement at the end of each case it falls through to the next case.


text:
arduino is skipping the if statement
Hi guys I am new to this language and i just tested the code to control a servo motor
Can anybody help me please ? here is the code
void setup() {

  servo_test.attach(3);
  pinMode(9, INPUT);

}

void loop() {

 if ( digitalRead (9 == HIGH)) {

   for(angle = 0; angle < 180; angle += 5)    to 180 degrees
  {
    servo_test.write(angle);
    delay(5);
  }

  delay(4000);
  for(angle = 180; angle>=1; angle-=5)      to 0 degrees
  {
    servo_test.write(angle);               specified angle
    delay(5);
  }

    delay(4000);
}

}

It is just like the arduino completely ignore the if statement and start the loop wheter pin 9 is in high or low state  even if  i wire it directly to gnd

Try digitalRead(9)==HIGH

In your code this line:
 if ( digitalRead (9 == HIGH)) {

...is likely passing the function "digitalRead()" the value zero as "9 == HIGH" is likely false.
Likely what you want to do is check if the value returned by the function "digitalRead()" is high.  Try:
 if ( digitalRead (9) == HIGH) {

...instead.

Yeah, that line is wrong. That code evaluates as if (digitalRead(0)), which returns the value of pin 0. Not sure how LOW is defined in the Arduino IDE. If it's 0 then you'll get false if pin 0 is ==LOW and true if the pin is ==HIGH.

so Arduino SE becomes a typo correction site. this answer is not useful

@Juraj I don't think it's a typo. It's a newbie's syntax error that compiles. I'm sure the answer was quite useful to the OP.


text:
arduino boolean function
In the following code :-
The aim of code is " when push button is pressed , led is on and when push button is is pressed again led is of"
#define led 12
#define button 7
boolean trigger = false;
boolean previous = false;
void setup()
{
  pinMode(led , OUTPUT);
  pinMode(button , INPUT);
}
void loop()
{
  int current = digitalRead(button) ;
  if (current && !previous)
  {
    trigger = !trigger;
  }
  previous = current;
  digitalWrite(led , trigger);
}

My Questions are as follows:-

When i used digitalread(button) instead of introducing variable i.e
current. LED shows abnormal behavior. Why ?
What is the purpose of current = previous expression. Whats its
significance?
Also please explain the working of a code in a brief manner in a
loop.
Why I should use Boolean instead of int?

what is abnormal behavior   ... that description has meaning only to you

When i used digitalread(button) instead of introducing variable i.e
  current. LED shows abnormal behavior. Why ?

Likely this is because of switch bounce.  The processor is very fast compared to the bounces a mechanical switch makes when operated.  So the results can be unexpected.  You can get around this problem in software by using a state machine.  Or in hardware by using capacitors to filter out bouncing.

What is the purpose of current = previous expression. Whats its
  significance?

The program is tracking the state of the switch.  So you need to know the previous state of the switch to know if the state of the switch has changed.

Also please explain the working of a code in a brief manner in a loop.

The two fixed or reserved function names in an Arduino sketch are "setup" and "loop".  "setup" is called only once on boot up.  And "loop" is called over and over again after "setup"is called.  In "loop" the code reads that state of the button, then tests to see if the state of the button is true and the previous state is false.  If it is, then toggle the variable which tracks the state of the LED.  Then the code will always save the current state as the past state and turns on / off the LED according to the value tracking the state of the LED.
Now comes the tricky part.  Assume the switch is perfect and does not bounce.  The toggling only occurs when the switch is 1st pressed.  That is because the next time through "loop" both trigger & previous are true and the test will then be false and the LED will not be toggled.  Not until after the switch is released does the code reset previous to false.  Now if the switch is pressed again, for only 1 iteration through "loop", the test will be true and the LED will be toggled.
This approach depends on the switch not to bounce.  And is difficult to understand.  Consider using a 4 state machine (button up / LED off, button down / LED on, button up / LED on, button down/ LED off) rather than this 2 state machine (button down / LED toggle, button up / LED steady).

Why I should use Boolean instead of int?

Bools only have two states.  Integers can have many states.  It is less confusing and less error prone to use a variable that only has two states if that is the intent of the program.


text:
I have downloaded the library but not sure what went wrong
C:\Users\Dray98\AppData\Local\Temp\arduino_modified_sketch_819854\sketch_jun09a.ino:2:29: fatal error: Adafruit_Sensor.h: No such file or directory

 #include <Adafruit_Sensor.h>

                             ^

compilation terminated.

Multiple libraries were found for "DHT.h"
 Used: C:\Users\Dray98\Documents\Arduino\libraries\DHT_sensor_library
 Not used: C:\Users\Dray98\Documents\Arduino\libraries\DHT-sensor-library-master
Using library DHT_sensor_library at version 1.3.0 in folder: C:\Users\Dray98\Documents\Arduino\libraries\DHT_sensor_library
exit status 1
Error compiling for board Arduino/Genuino Uno.

Please edit your question and add an explanation of what you are working on.  Place this text before what appears to be the output of your Arduino compiler session.  Tell us how you tried to fix this problem.  Posters who have tired and fail get better responses then posters who try nothing at all.  If you do not do this soon people will likely vote to close your question and you will not get an answer.

When you encounter a No such file or directory error it usually means you need to install the library that contains the missing file (in this case Adafruit_Sensor.h).
Ideally the documentation for the code you are trying to compile will have instructions for installing dependencies.
Sometimes the author did not make the effort to write this documentation and you'll need to go searching for the missing library.
Many Arduino libraries are in the Library Manager index, which makes them quite easy to install:
Library Manager installation

(In the Arduino IDE) Sketch > Include Library > Manage Libraries.
Wait for the download to finish.
In the "Filter your search..." box, type your search query, in this case "adafruit unified sensor abstraction layer" would get you the one correct result but with a little searching through the results of a more general search like "adafruit sensor" will get you there also.
Scroll through the search results to find something that looks correct (in this case "Adafruit Unified Sensor by Adafruit"), then click on it.
Click "Install".
Wait for installation to finish.
Click "Close".

If you don't find the library you need in Library Manager you'll need to spend some time with your favorite search engine. Once you find the library and download it you'll need to install it.
.ZIP Installation

(In the Arduino IDE) Sketch > Include Library > Add .ZIP Library
Select the downloaded file (must be a .zip).
Click "Open".

The above installation instructions require the .zip file to have a specific folder structure. In some cases the library author has not been kind enough to provide the correct folder structure. If you get a "Zip doesn't contain a library" error message then you will need to do a manual installation of the library.
Manual Installation

Unzip the downloaded file
Browse through the unzipped folder until you find the library folder. This will either have a library.properties file and/or a .h file.
Copy the library folder to {Sketchbook folder}/libraries. You can find the sketchbook folder in the Arduino IDE at File > Properties > Sketchbook location.
You will need to restart the Arduino IDE before the examples sketches for manually installed libraries will appear under the File > Examples menu.

Your problem is, that you haven't installed the Adafruit_Sensor.h, which is a dependency of Adafruits DHT library. The README on Github for the DHT library also states this:

You must have the following Arduino libraries installed to use this
  class:
Adafruit Unified Sensor Library

You can find the Adafruit_Sensor.h here at Github. Install it in your libraries folder. You can refer to the answer from per1234 for instructions on installing libraries.
--
The second part in your error output is not really an error. As others stated before, the IDE only tells you, which version of the DHT library it uses. If you want to have multiple version in your libraries folder, you will have to make sure, that you always use the correct one. If they are identical, you can delete one of them, if you want to. The outcome would not be any different, except for that the IDE doesn't have to tell you, which library it uses.

Have you installed the Adafruit_Sensor library correctly? If not, at top of IDE, click  Include Library > and see if it's in the list and click it, if not, go to top of list and click Manage Libraries..., search for and click on it.


text:
I cant seem to form a code to read both DHT11 and pulse sensor
I combined both the heart pulse sensor code and the DHT11 code. I can get a decent reading from the pulse sensor however an error is given from the DHT11 sensor. I am able to get them to function normally when i set them up individually however when i combine the 2 setups, I am unable to get a reading from the DHT11 although i can get one from the pulse sensor.
I am using ArduinoUNO, DHT11 humidity and temp sensor, and the Pulse Sensor.
THE CODE:
#include <SimpleDHT.h>
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.

//  Variables
const int PulseWire = A0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13;          // The on-board Arduino LED, close to PIN 13.
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
const int pinDHT11 = 2;
SimpleDHT11 dht11(pinDHT11);                               // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
                  // Otherwise leave the default "550" value.

PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"

void setup() {

  Serial.begin(115200);          // For Serial Monitor
  // Configure the PulseSensor object, by assigning our variables to it.
  pinMode(2,INPUT);
pinMode(A0,INPUT);

  pulseSensor.analogInput(PulseWire);
  pulseSensor.blinkOnPulse(LED13);       //auto-magically blink Arduino's LED with heartbeat.
  pulseSensor.setThreshold(Threshold);

  // Double-check the "pulseSensor" object was created and "began" seeing a signal.
   if (pulseSensor.begin()) {
    Serial.println("We created a pulseSensor Object !");  //This prints one time at Arduino power-up,  or on Arduino reset.
  }
}

void loop() {

 int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
                                               // "myBPM" hold this BPM value now.

if (pulseSensor.sawStartOfBeat()) {            // Constantly test to see if "a beat happened".
 Serial.println("♥  A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
 Serial.print("BPM: ");                        // Print phrase "BPM: "
 Serial.println(myBPM);                        // Print the value inside of myBPM.

  delay(20);                    // considered best practice in a simple sketch.
}
 Serial.println("Sample DHT11...");

  // read without samples.
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
  Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
  return;

  Serial.print("Sample OK: ");
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" H");

  // DHT11 sampling rate is 1HZ.
  delay(1500);
  }
}

The code can be improved, but I don't see an obvious reason why this should not work. It is likely the 2 Arduino libraries are using the same processor resource. You might have to read through the code for the DHT and PulseSensor to determine and fix the problem.  Or you may blindly try to simplify your sketch until more features work. For example, it appears unnecessary to enable interrupts as the basic PulseSensorPlayground example does not use interrupts.

Hint: Try using the PulseSensor library without interrupts.

currently i have edited my code. the DHT11 works now but the pulse sensor still does not work. I have found that the pulse sensor requires interrupts in order for the code to work but DHT11 does not need interrupts in order for it to work. is there some way that i can detach the interrupts for DHT11 code and attach the interrupts for the pulse sensor??