text:
Keep Alive for Arduino
Sometimes the arduino locks up for some reason. It would be nice to know why, but the problem is more general. I have found a hardware keep alive that resets the controller if it doesn't respond:
Arduino Keep Alive with AT-Tiny
This would work, but i wonder if there are there features like this built in to any of the processors that can be used in the Arduino environment (ESP8266, ESP32, or the like).
Maybe folks know of a processor with the "Keep Alive" feature?
How would i determine if this "keep alive" feature is present for a specific processor?
Thanks for any suggestions!
Mark

Yes, it's called the "Watchdog" and most MCUs (including the ATMega328p on the Uno) have one.

you can attach that atinny to any board, but why, if the built in watchdog does the same?

"Watchdog" Got it! Thanks for the suggestions! I was stumbling on the correct jargon.

@xsk8rat That's often the problem: you know what you want, but you don't know what it's called, and googling without the magic word is nigh on impossible.

There is a WDT in the Arduino MCU but you really should be looking to solve your root cause first.  An Arduino should not lock up and when it does it's usually either a software issue where the stack overflows or it's a hardware issue where you have noise or other spurious signals interfering with the MCU.

Acknowledged that as the best solution in the question. Your point is not lost one me! This is the ugly band-aid for things i can't identify in advance.

do we agree that the linked tutorial using external MCU as 'keep alive' is nonsense?

Yes, that we do!

Reference link: https://create.arduino.cc/projecthub/rafitc/what-is-watchdog-timer-fffe20

Watchdog timers can be found in the datasheet. If there is no intervention to this module by the software, the MCU will be reset. basically, restarting all the functions.
It is a bad idea to use WDT to solve your particular topic. You should try to fix the issue
The external watchdog timers (Example: ADM8320) is more reliable than internal ones

Thanks for the link, that is helpful! Yes, i need to learn more about what is causing the units to hang and fix that. That will be the first thing i do!

personally, I have never experienced my Arduino crashing. I even have a board running for one of my university projects measuring temperature, time and resistance of a sensor and saves the data to a micro SD card that has been running for over 3 months from batteries without issues!
What do you mean by 'locks up'? If you run the blink programme, does that stop or does It work ok?
In the link you provide, the idea of resetting devices in a complex IOT project is a smart idea, but you run into the risk of having your issue repeating over and over again if you do not know what is causing the problem

Hi Luke, That's an issue, i need to find the problem. The sensors are used in production and they have reported an issue. But i haven't retrieved an data or a unit yet.


text:
Arduino LED lighting up when signal is reading low on multimeter
My code is designed to play a tone when ever pin 3 is high on my Arduino. When I am examine the pins voltage with a multimeter it is always reading below 1 volt. When I examined the voltage off of a osiliscope it is reading the voltage pretty steady at 0.2 to 0.3.
My multimeter reads at 0.26
:
My code is:
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
int input = digitalRead(3);
Serial.println(input);
if(input == 1){
  tone(A5,4000);
  }
}

My board looks like:

The bottom of the board looks like:

What pin are you measuring exactly? Pin 3 or pin A5? Is there a resistor in series with that LED? Is there a pull-up or pull-down resistor on pin 3? See Switches Tutorial.

You left pin 3 floating. The multimeter will lower the voltage, resulting the the led lighting. Try enabling the pull-up resistor in pin 3 by adding pinMode(3, INPUT_PULLUP).
PS you might want to add a resistor in series with that led, or it will burn out and/or damage pin 3 on the arduino.

source: Stack Exchange

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

sort: votes


text:
Photoresistor is not working, is there something wrong in the code?
I am trying to make the photoresistor work in a simple project.
The project is as follows:
The LED light should light up brighter and brighter as the photoresistor reads less light in the room.
The problem:
The reading is fixed on 1023. Therefore the LED never lights up. I cannot understand why.. Sometimes if I cover the sensor the readings go down to 900- 950 but never less even though it is completely dark around the sensor. Is there something wrong in the code? What could have gone wrong?
Please note that the resistor connected to the sensor is 10k Ohm as is the one connected to the LED.
Here is the code
int photoPin = 0;
int pReading; // analog readings

int LED = 11; // red LED connected to pin 11
int LEDbrightness; //

void setup()
{
  //set up the serial connection
  Serial.begin(9600);
}

void loop()
{
  pReading = analogRead(photoPin);
  Serial.print("Photocell reading = ");
  Serial.println(pReading); // Analog reading

  pReading = 1023 - pReading;
  //map 0-1023 to 0-255
  LEDbrightness = map(pReading, 0, 1023, 0, 255);

  analogWrite(LED, LEDbrightness);
  delay(50);
}

Here are the connections

thank you!

The code looks OK. It looks like it's your circuit which is the problem.
The main role of a photoresistor is to restrict the amount of current flowing through it when the light level is reduced. It won't directly affect voltage the way you're expecting (the analog pins respond to voltage).
However, it's pretty easy to make it affect voltage with a slightly different circuit. Try creating a voltage divider circuit, such that the supply voltage (5V) goes through the photoresistor, then through another resistor, and then to ground. The Arduino's analog pin should be connected between the photoresistor and resistor. (See the image below, although the resistor on the output probably isn't necessary in this case.)
This should cause the voltage on the analog pin to decrease when the light level decreases. You may need to experiment a little to find a suitable resistor value on the ground connection, although 2K Ohms is probably a good starting point. It basically affects the sensitivity of the circuit.

Image credit: Morteza Lahijanian (source)

Thanks, your comment was very useful, I fixed the problem using the circuit you suggested and everything works! thank you very much!

Your wiring is wrong.
Analog inputs are high impedance and probably the impedance isn't really linear. So what voltage do you expect on your analog input, if its inner impedance is one or more orders of magnitude greater than that of your sensor and series resistor?
The inner impedance builds up the lower part of a voltage divider and your sensor and series resistor the upper part. The voltage measured will almost anytime almost 5V.
How to fix this?
You will have to make a suitable voltage divider outside your arduino. Simly connect your input via another resistor to ground. So, how to determine the right value of the additional resistor? It strongly depends on your sensor and the brightness range you want to perceive. I recommend starting with 1kΩ. Let us know,
what your readings are for full light and darkness. Then we can give some more hints.

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


text:
Is it possible to run a binary from EEPROM?
Say I wrote a compiled sketch to EEPROM then read it. Could I run the program from EEPROM? I guess the question is: Can an Arduino run software not in flash memory in the middle of executing the software in flash?

Short answer: No; From the atmega328's data sheet (though it applies to all AVR's):

AVR uses a Harvard architecture – with
  separate memories and buses for program and data. Instructions in the program memory are
  executed with a single level pipelining. While one instruction is being executed, the next instruction is pre-fetched from the program memory
...
Program Flash memory space is divided in two sections, the Boot Program section and the
  Application Program section. Both sections have dedicated Lock bits for write and read/write
  protection. The SPM instruction that writes into the Application Flash memory section must
  reside in the Boot Program section

It's architecture prevents using external program memory, but you can load anything into program memory at boot. At that point I would venture to say you are just programming AVR and not arduino, since you would need to replace the arduino bootloader and break the arduino IDE's ability to upload programs.
Alternately you could also use an emulator or interpreter of some intermediate language; basically code that steps through and runs other code. As a general rule an emulator runs around 8x slower.
There are micro-controllers from other brands that do support this functionality, I know a couple different PIC's do.

No. The foundation of a Harvard architecture such as AVR is to only allow code that exists within program space to be executed, and EEPROM is not within program space. It is possible, however, to write a virtual machine that will run from flash. This VM can then read program-become-data from anywhere and take action based on it.

+1. Note that some MCUs use modified Harvard architecture that allows the CPU to read/write data in program space, so you can copy the code from RAM to ROM and run it like self-modifying code

For the VM thing, all you'd have to do is get the compiled C++, check the EEPROM for which instruction to be ran, and run that instruction. Of course, running it nativity on the chip would be multiple times faster and that is no easy task, but it'd be a fun project to learn about lower level stuff on the 328P...

Yeah, but if you're going to do that then you may as well run something fun like Forth or Python.


text:
Which Arduino Board should I start with?
I am interested in Arduino projects. I want to learn to develop my own Arduino based system. The problem is I am not sure which Adruino board must I start with. Any ideas are appreciated, I have searched many discussion forum but could not find a satisfactory answer.
My questions are:

Which Arduino Board should I start with?
Is it possible to work on Arduino based projects without the board; like having a simulation of the board? If so how?

Start, exactly as your question tag says, with an Uno.

And I don't know of any Arduino simulators that don't cost less than the price of 50 Unos.

@chaaarlie2 Okay that is fine, any recommendations or points I must consider to get started well?

As @rslite says, get a starter kit. But before you get anything, buy a book. It will be more educational in the first chapter alone than any answer here will be.

My advice:
 - get a model with USB port (some do not have one)
 - the DUE might seem attractive, but you have less libraries available and less examples, I'd recommend it more as follow up
 - you will get frustrated if you do not know how to code, at least a bit, so if you have not programmed before, you might want to spend some time trying simple stuff just with your PC
 - same about electronics: if you do not have previous experience, it might be preferable to play a bit with a breadboard and some components (LEDs, resistors, switches, etc.); this will reduce the likelyhood that you fry your Arduino. Remember to buy some cables MM/MF/FF, you will end up needing all of them, sooner or later. For powering the board, you can find nice power supplies that cn be powered by a USB cable.
I have bought UNOR3 clones at $4-$5 on ebay, so if you can afford it, I'd suggest you buy a couple, that will enable you playing with I2C master slave and similar configurations.

Well, thanks for the idea. I have a good programming back ground: C, VB, Java, PHP,HTML and JavaScript. As of now I am specializing with Java, C and C++, however, I lack an electronics background. I visited Ebay and found too many boards that have the same tug as one I am looking for. If please you can point for me one that I can start with from this list

this is what I would recommend:
http://www.ebay.com/itm/Hot-Sale-ATmega328P-CH340G-UNO-R3-Board-Free-USB-Cable-for-Arduino-DIY-DJNG-/351337582344?pt=LH_DefaultDomain_0&hash=item51cd5a0f08

this is a bread board (but there are many other types):
http://www.ebay.com/itm/Prototyping-Prototype-Shield-ProtoShield-Mini-Breadboard-for-Arduino-UNO-R3-Mega-/360919191173?pt=LH_DefaultDomain_77&hash=item540875ce85

this is a variant I have never used:
http://www.ebay.com/itm/UNO-R3-ATmega328P-CH340-Mini-USB-Board-for-Compatible-Arduino-NEW-/281685195762?pt=LH_DefaultDomain_0&hash=item4195befbf2

this is an example of cables, i advice buying male/male male/female female/female:
http://www.ebay.com/itm/40PCS-Dupont-Wire-Color-Jumper-Cable-2-54mm-1P-1P-Male-to-Female-20cm-WC-/221480820368?pt=LH_DefaultDomain_0&hash=item3391491e90

some rgb led:
http://www.ebay.com/itm/50pcs-Ultra-Bright-5mm-4-pin-RGB-Diffused-Common-Anode-LED-light-Red-Green-Blue-/281487760818?pt=LH_DefaultDomain_0&hash=item4189fa5db2
And don't forget the resistors (see the LED page).

Thanks very much for the ideas, I will settle for what you have recommended.

If you find the answer useful, please remember to upvote it :-)

Depending on your budget you could start with an Arduino Uno starter kit that will include the Arduino, breadboard and wires plus different sensors (like this one - but there are others with less peripherals and cheaper).
If you have a lower budget you can still buy the arduino and many separate sensors/LEDs etc from eBay.
By googling you'll find a lot of tutorials about getting started with the hardware that you bought.


text:
how to make an led turn on when something gets close to an ultrasonic sensor
Hey I just started using arduino and so far can't get any help with how to write a code for an led to turn on when someone gets in range of a three pin ultrasonic sensor, and off when they are out of a specific range.
Any help?

What have you tried so far? Have you tried lighting an LED? Have you tried getting the distance from the ultrasonic sensor?

i have already done all of that

Then you just need to do some comparisons.  Learn about the "if" command.

Try with this and check that at least you can reproduce the desired effect:
http://www.arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor
Then you can refer to this for the part related to driving the LED:
http://www.arduino.cc/en/Tutorial/Blink?from=Tutorial.BlinkingLED
Since the ultra sound demo already calculates the distance, you can do the test on that to decide when to turn ON/OFF the LED.


text:
How far can i go just with this starter kit?
I want to buy this kit: http://www.banggood.com/UNO-Basic-Starter-Learning-Kit-Upgrade-Version-For-Arduino-p-970714.html
However, as shipping stuff from China takes like 3 months to arrive, i need to be certain i won't have much else to buy.
How far can i go just with this kit, and what would you recommend me buying together with it?
Thanks in advance.

As far as your imagination can take you. That's a decently comprehensive kit.

Without knowing your goals, that is unanswerable.  I'd be quite tempted to get a few basics like the board itself from a faster supplier, and then when this arrives you will have a second.  Are you looking at such slow sources dues to cost, or because all sources are slow to ship to wherever you are?

Yeah that is a massive starter kit so for beginning and learning it will be great. You have the basics there that will open up a much larger world. I did a laser spirograph and laser night light for my kids but those parts I could not source from an Arduino supplier. So depends on your projects and ideas.

That kit is quite good and/but, if you are prepared to source some of the basics in addition, I'd recommend at least considering something like this kit . I've NOT bought this but always thought this looked like a superb idea for experimenting. | I find these people low cost & prompt and I have found their products good. Worth a look. I have no involvement except as a customer

I bought a basic original starter kit from Arduino comes with book. Gave it to my son 9 years and me both working and learning. Its very good to understand the basics and complete all chapters. If your foundation is solid then you would be able to go higher projects. Try to combine different projects and after short period of time you will be able to work on advanced projects using Arduino forums and other tons of information in net.

@RussellMcMahon. About half of the sensors are already present in the kit Igor was asking about. Though without the nice breakout board and headers. Other than that, a nice suggestion.

To answer some of your questions, shipping from China is the best option because anywhere outside Brazil takes ~3 months to arrive, and buying here is like 10x more expensive.
I do not have any experience with electronics overall, but i can read some books about it and tutorials and stuff. Basically, i'm willing to learn, haha.


text:
How to start Arduino programming?
I am totally new to and don't know where to start, I am interested in building new system with combination of hardware and software and every time I search how to make that embedded system it finally reaches to Arduino and don't know anything about that what to buy and I also have some more question like

Is one Arduino device required for each Arduino project ?
Should I have to buy more then one device for each project ?
If not then how I will make that project run without Arduino ?

An Arduino is basically a Microcontroller on a handy PCB with built-in programming interface.  It also has a simple programming environment to get you up and running quickly.
The chip on the board can be thought of as the "brain" of the system.  It's what you program and it's where you upload your software to.

Is one Arduino device required for each Arduino project?

Yes and no.  You can't "remove" your Arduino from your project and expect it to still work - it'd be like beheading someone - they cease to function without their brain.  However you can replicate the Arduino in your system fairly easily so you don't have to embed the whole Arduino into it.  You can get a blank chip the same as is on the Arduino reasonably cheaply and program the bootloader (the serial interface for programming it) into the chip using your existing Arduino, then build a new circuit around it.  More information here:

http://www.arduino.cc/en/Main/Standalone

Should I have to buy more then one device for each project?

That depends if your project is complex enough to warrant more than one "brain".  Using the "standalone" instructions above you could make multiple chips from one Arduino and embed them all in your one project.

If not then how I will make that project run without Arduino?

There are other Arduino boards available that are designed to be embedded in your project.  These are much smaller than the "development" boards like the Uno etc.  They are also cheaper, being typically the absolute bare minimum you need to get you going.  These can be a great way of saving time compared to the Standalone system above, and at the same time saving money compared to using the full blown Arduino boards.  Boards include the Mini and Nano range of boards.

http://www.arduino.cc/en/Main/ArduinoBoardMini
http://www.arduino.cc/en/Main/ArduinoBoardNano

Please add one basic tutorial form where I can start like hello world programme we write in every language

Those kind of tutorials are all included in the Arduino IDE.  The normal one is "Blink" which flashes an LED (the equivalent of "Hello World".)

Where I can buy Arduino  easily in India

I don't know, I'm not from India, nor have I ever been there, let alone shopped there.  Have you asked Google?  Try eBay for a start.

Forth mentioning the standard book to get started: "Getting Started with Arduino" http://www.makershed.com/products/make-getting-started-with-arduino-3rd-edition


text:
Flash a .hex to an ATtiny45 with Arduino
I'm trying to upload a hex file to an ATtiny45 with an Arduino. I uploaded the Arduino ISP sketch to my board. I connected the ATtiny as shown below:

Then I go to CMD and type:
avrdude -c avrisp -p t45 -b 19200 -P COM6 -U flash:w:main.hex:i

And it gives me this error:
Please define PAGEL and BS2 signals for ATtiny45!

I double checked the connections and i tried to uplad a bootloader with Arduino IDE as written in this article: Programming Hex-code on an Attiny85 with the Arduino. I can uplad sketches with ArduinoIDE with no error.

Googling the error gives this tutorial. Towards the bottom of the page they say

You’ll probably get the following message, but don’t worry, the upload should have worked anyway:
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

So it seems this can be ignored and the part has been programmed!

But the avrdude dont finish the programming, just write out the error


text:
Connecting an arduino uno to an arduino due
So I am trying to get my arduino uno to talk to my arduino due but I'm having issues getting the data outputted on the due side. My arduino uno is the master while the due is the slave. The sensor is connected to the uno and I just require the arduino due to receive and spit out the data as it has a faster sampling rate than the arduino uno. I connected them along the serial (Tx and Rx) lines. And I'm using Serial3 on my arduino due to receive the transmitted data. Both arduinos are grounded together. But powered differently by usb cables connected to my machine. On the arduino uno end ( for brevity sake) the data is sent in binary with the $ sign as the starter bit. Here is the code for the receiving end ( the slave). I just can't seem to get the data out on the serial monitor.
    byte b = '$';
    unsigned char buffer[12];
    int count =0;

    void setup() {
    Serial.begin(115200);
    Serial3.begin(115200);
    delay(5);

    }

   void loop() {
   if(Serial.available())
   {
    if (b == Serial.available())
   {
    while(Serial.available())
    {
      buffer[count++] = Serial.read();
       if(count == 12)break;
      //Send the byte to serial port three
      Serial3.write(buffer, count);
    }
 }

 if (Serial3.available()){
  //get a byte from serial port 3
  if(b == Serial3.available()){
    buffer[count++] = Serial3.read();
    //Send the byte to the USB serial port
    Serial.write(buffer, count);
  }
 }
 Serial.println("lyca");
 }
  }

Did you cross TX and RX (i.e., connect TX to RX and RX to TX) or connect them straight (TX to TX and RX to RX)?

if(Serial.available())
{
 if (b == Serial.available())
{
 while(Serial.available())
 {

I think you may be getting your knickers in a twist there.
... Is serial available? Yes. Is serial available? Still yes! But yes doesn't equal '$'!!!... WHAT?!
You really really need to rethink your understanding of serial communication.
Read this: http://hacking.majenko.co.uk/reading-serial-on-the-arduino

Thanks @Majenko ..I actually crossed it. Tx to Rx and Rx to Tx

I agree with Majenko. Comparing '$' to Serial.available() makes no sense at all. You do it more than once. And why test if serial is available twice in direct succession? Three times, even, if you count the while(Serial.available()).

There seem to be a confusion on Serial & Serial3. You say that:

Serial is used to send back debug data to the PC
Serial3 is used to get data from the master

But this is not clear/coherent to your code. Let's try to see your code with proper indentation. I added comments.
void loop() {
  if(Serial.available()) { //isnt Serial your debug port? did you mean Serial3?
    if (b == Serial.available()) { //same. Serial3? also, read() instead of available() ?
      while(Serial.available()) { //same. Serial3?
        buffer[count++] = Serial.read(); //Serial3?
        if(count == 12) {
          break; //will this work for several frames? how can count ever go back to 0?
        }
        Serial3.write(buffer, count); //isnt Serial your debug output?
      }
    }
//your indentation didnt show it, but we're still guarded by the first 'if' here.
//Also I guess you meant Serial here?
    if (Serial3.available()) {
//why check for a SoF? what do you do with data coming up fro the debug PC?
      if(b == Serial3.available()) {
//messing with data in your buffer, potentially outside of it? (count can be>11 here)
        buffer[count++] = Serial3.read();
        Serial.write(buffer, count);
      }
    }
    Serial.println("lyca");
  }
}

What about this (code below still has several flaws, but should perform better than yours)
void loop(void) {
  if(Serial3.available() > 0) { //available data from master?
    while(Serial3.available() > 0) { //if statement above for clarity, this while on its own would be enough
      inByte = Serial3.read();
      if(inByte  == SOF_BYTE) { //is this a start of frame?
        mybuff.ptr = 0; //let's say we dump everything in buff whenever we get a new SoF
        Serial.println("SoF received");
      }
      else { //let's not keep SoF
        mybuff.append(inByte);
      }
    }
  }
  if(mybuff.size >= FULLFRAME_SIZE) { //we've got a full frame, output it
    Serial.print("Full frame received:");
    Serial.println(mybuff.string);
    mybuff.ptr = 0; //now that we've consumed the frame, kill it
  }
  else {
    Serial.print(".") // no frame, show progress/still alive
  }
  delay(refreshtime);
}

Hi @CQuinson, the problem would arise as a result of the fact that, the data sent to Serial from the slave, would have to be read back from serial on the master sketch, then sent to the specified serial port (Serial1, Serial2 ...etc.). The data on that port is then re-read back to Serial from the ports before it is written on the master side. Initially , I thought it was unnecessary and just a waste of my time, but when i tried it as suggested, no data was received, I had to go the long haul to get the data out. But maybe , I was missing something, I'll have a look. thanks for the feedback


text:
Controlling flexinol with an arduino board?
I am looking to wire up 16 pieces of flexinol (http://www.musclewires.com/MWFlexinol.php)  using an arduino board. Ideally I would like to be able to activate them independently, meaning that they could all be on, off or in any combination in between. My understanding that they would need to draw more current than the board could handle so some type of shield would be necessary?
Any suggestions would be greatly appreciated.

First thing's first, this just seems to be a wire that has special characteristics. If so, we just need to find out the resistance and use Ohm's law.
From the product page, I found this image:

I can tell from that that it has a resistance of 20 ohms and a recommended current of 1 amp. First, let's see how much current it would draw with a 5V supply. I prefer using a Ohm's law triangle, just because I'm a very visual person. So with this math:

5 / 20 = 0.25

That's 250 mA, but an Arduino can only provide 40 mA! Furthermore, it is only 1/4 of the recommended current that the manufacturer specifies.
To get the full current the OEM specifies you'll need a 20 V power supply capable of at least 1A. Even then, you might want to put in a power resistor to limit the current.
Driving this with Arduino: So, we have a few problems here:

It is 20W, which is quite a bit in the Arduino world
We need to control the current/voltage dynamically
You need 16 of them, so we don't want something too costly
You probably can't find something to fit your needs that is one shield.

What comes to mind is a transistor. I'm not skilled with picking them out, but there are a lot of guides online. You'd then want to add a capacitor and a resistor to make some sort of filter and connect it to a PWM pin to send a varied voltage to the transistor, which will vary the amount of power going through it.
Alternatively, you could use a relay. However, that only does ON or OFF. A solid state relay (SSR) would allow you to use PWM on the relay and then you could add a capacitor/resistor combo on the other end of it, but you'd need a pretty large capacitor or a pretty large frequency for the PWM (which you can modify).

"You'd then want to add a capacitor and a resistor to make some sort of filter and connect it to a PWM pin to send a varied voltage to the transistor" - NO.  This is both unnecessary and highly inefficient.  The thermal mass of the wire will average out the PWM quite well, and it is far more efficient to use a transistor (or better FET) switch which is (to the greatest degree possible) only ever all the way on or all the way off, so keep the control signal to the transistor digital and do not average it with a filter which would cause it to spend time in the lossy "somewhat on" region.


text:
Two or More Arduinos Handshaking
research would show that there are numerous ways for two arduinos to talk to one another. But i was looking for a 'basic robust protocol' (..it doesn't sound basic ....I know!), to allow for two arduinos to talk to one another. The idea is , Arduino One(slave), is linked to a sensor and it reads data from the sensor and sends the data  to Arduino Two on 'request' of the data by Arduino Two(master). Arduino Two would have to 'request' for the data from Arduino One, before it can read the data, if its available. A popular method on most sites (e.g https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing/shaking-hands-part-1) is the use of the method below. I added a comment in search of clarity.
              void establishContact()
                     {  //This while loop does baffle me as it suggests that
                        //while there is nothing in serial, send A???
                        while (Serial.available() <= 0)
                       {
                         Serial.println("A");   // send a capital A
                         delay(300);
                       }
                     }

Now this method was used in handshaking between Arduino and processing. This method was called on the Arduino sketch. On the processing sketch, a method there just checks to see if 'A' was received. If it is, it reads in the data from serial, clears the serial buffer and  writes 'A' back to Serial. I tried using this method on both of my arduinos as i felt it was 'basic' enough, but it didn't work at all. Does anyone has a better idea on how my arduinos could handshake?.

That while loop makes perfect sense.  It' basically nudging the other end repeatedly until it replies with something - anything.
It's like sitting next to someone and poking them in the ribs every 300ms until they respond to you. Once they have responded you can then react to that response - be that to run very fast or tell them your important news.
The idea of handshaking like that is all to do with synchronisation. It ensures that both ends are ready for communication at the same time.  Once synchronised you know, to a high probability, that what you are sending will be interpreted properly, and any replies you get back will be correct.
For basic communication between two Arduinos it's really not necessary.
The simplest call-and-response protocol involves Arduino A sending a single byte as a request and Arduino B replying with a single byte. It is up to you what those bytes represent, but ASCII letters for requests are ideal since they are understandable by a human, and numbers between 0 and 255 or -128 and +127 fit in to one byte (unsigned or signed respectively). Should you want bigger numbers being sent back then the reply will have to be delimited in some way. The simplest way of doing that is to format the response as ASCII data and send it with a CR and/or LF.
Something like:
if (Serial.available()) {
    char command = Serial.read();
    switch (command) {
        case 'T':
            Serial.println(temperature);
            break;
        case 'P':
            Serial.println(pressure);
            break;
    }
}

The master end then sends either 'T' or 'P' to request temperature or pressure. It then reads characters up to a line feed and stores them in a string which it can then convert into the desired numeric data type depending on what temperature and pressure are (integer or floating point).

Always to the rescue @Majenko....Thanks alot


text:
Arduino port recognition
New Arduino Uno, Arduino 1.6.3, MBP running 10.10.5.
The Arduino IDE is running, I connect to the laptop via usb. The green LED is on the amber light is on but it's not blinking.
I attempted to upload the blink file from File>Example>Basic>Blink. It compiles without issue but won't upload. I get the can't open device "/dev/cu.usbmodem1421" : No such file or directory...
I have attempted using the reset button, changing ports, cycling the IDE and the computer. The killer is that I've had an Arduino on this laptop before.
Any suggests for getting the Arduino linked and operational.

If the serial port is correct (it looks odd to me, check that /dev/cu.usbmodem1421 is the right port), then I think that the problem is the bootloader. Try flashing it again if you have a programmer or another working arduino (search for ArduinoISP tutorials)...

Have you confirmed you have the right Arduino and Port selected in the IDE Tools menu?

Sorry to dredge up an old thread (well, really only replying to one that got robo-dredged :), but maybe this will help someone someday.
A /dev/cu.<something> is a unix port designation. "cu." meant a port used for modems, back in the mists of time but probably isn't relevant today. But what we do learn from it is that the OP is probably using a Mac, and for sure, not Windows.
"/dev/cu.usbmodem1421" is a typical device name for an Arduino as seen by a Mac on a particular one of its USB ports - the numeric part varies according to which Mac USB port the Arduino is connected to each time.
Arduinos & FTDI devices do not need additional drivers on Mac OS (that may not be true for other, non-FTDI USB-to-serial devices).
In this case, the OS already reports seeing (what looks like) an Arduino. The suggestion already put forward, checking the board-type and port selections in the IDE's 'Tools' menu, is the place to start.

I think you may not install arduino hardware and ftd drivers,
Follow the steps given here and then check,

Download the latest version of Arduino software and install it.
Open windows device manager - You can open windows device manager by right   clicking on 'My Computer' and choosing Properties. In the new Window, Click on    Device Manager
Now Scroll Down the List of Devices in the Device Manager till you come to a Device or expand Ports (COMM).
Now you should see Arduino hardware with warning icon or without.
Now do right click on arduino hardware name. Now, Windows will provide you two options, Choose the one that says “Locate and install drivers manually from a specific Location.”
By browsing locate arduino installed folder, then update.

If you previously done these procedure or now, then open arduino software

Go to tools and choose board as what you have like (arduino uno, mega, due etc....)
then in tools menu you should choose serial port (example comm 10, comm 21, comm 8 etc...) in which the arduino board connected, some time the board name displays with serial port otherwise you can observe from device manager ports list.
now upload blink example and check.


text:
Does the Node MCU v3 (LoLin) not have a builtin led?
Trying a simple led blinking program I could not get the builtin led on a LoLin Node MCU v3 working. The LED_BUILTIN constant is set to pin 16 / GPIO16 / D0.
Reading several articles and QA I think that the Node MCU boards are supposed to have a the on-board led on pin 16. However, if I address this port nothing happens.
With the same code I can blink the data led which is on a RX pin, pin 2.
Is the builtin led missing on the LoLin Node MCU v3, or could it be that the led on my board is broken?

the ESP8266 has a builtin led that is attached to D4 as labeled on LoLin boards which maps to GPIO2. One thing to Note is that the led is active low. In other words ... setting PIN 2 to '0' will turn the LED ON and setting PIN 2 to '1' will turn the LED OFF
Lolin Builtin_Led Picture
This is the only LED on the LoLin boards and differs from other devkits that have an LED on GPIO16.

I have been banging my head against this for a half hour. Lot's of conflicting information due to different manufacturers. The reverse logic is a bit strange but at least it works.

I have put up a blink example demonstrating pin 2 on https://gist.github.com/jhorsman/6a93191ba31a48cf0cea75acd4c20cea

Great it saved my time. I was clueless.Do you know what are the other differences in LoLin board? Any links

@JoyGeorgeKunjikkuru This was helpful to me: https://frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/

I have nodeMCU v3 and Pin 2 worked for me.
#define LED_BUILTIN 2

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because
                                    // it is acive low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

The NodeMCU with the CP2102 serial and a slightly narrower pin footprint does have 2 LEDs.
$led1 = BUILTIN_LED;  //D0, 16, BUILTIN_LED: OnBoard LED
$led2 = 2;    //Pin 5 D4/2 Internal LED for LoLin V3

The $led1 = BUILTIN_LED (on GPIO 16) is **not* on the LoLin NodeMCU v3.

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


text:
Please explain this OneWire communication with Arduino Uno and DS2502-E48
The goal is to read the MAC address from a DS2502-E48 chip.
I think I accomplished this goal too with the following code, but I can't get behind at how this works.
I had a similar program with a PIC chip as reference.
I checked several references about OneWire and the DS2502 but not the info I needed to hop to the right memory addresses.
Where'd I normally attain the information so that I know I have to write: cc ,f0 , 0, 10 , read a random byte, and then I'm at the right position for MAC.
#include <OneWire.h>

OneWire ds(2);
void setup()
{
  Serial.begin(9600);

  byte i;
  byte dataLength;
  byte present = 0;
  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
    Serial.print("No more addresses.\n");
    ds.reset_search();
    delay(250);
    return;
  }

  ds.reset();
  ds.select(addr);

  delay(1000);     // maybe 750ms is enough, maybe not

  present = ds.reset();
  if (present != 1 )
  {
    Serial.println("No device present, exiting...");
    return;
  }

    ds.write(0xCC);//SKIP_ROM
    ds.write(0xF0);//READ_MEMORY
    ds.write(0);  // ?
    ds.write(10); // ?
    ds.read();    // ?
    dataLength = ds.read();

    for ( i = 0; i < dataLength; i++) {
    data[i] = ds.read();
    if ( i>3){
      Serial.print(data[i], HEX);
      Serial.print(" ");
    }
  }
}

void loop()
{

}

From the DS2502 datasheet:

Skip ROM [CCh]
This command can save time in a single-drop bus system by allowing the bus master to access the
  memory functions without providing the 64-bit ROM code. If more than one slave is present on the bus
  and a read command is issued following the Skip ROM command, data collision will occur on the bus as
  multiple slaves transmit simultaneously (open drain pulldowns will produce a wired-AND result).
READ MEMORY [F0h]
The Read Memory command is used to read data from the 1024-bit EPROM data field. The bus master
  follows the command byte with a 2-byte address (TA1=(T7:T0), TA2=(T15:T8)) that indicates a starting
  byte location within the data field. An 8-bit CRC of the command byte and address bytes is computed by
  the DS2502 and read back by the bus master to confirm that the correct command word and starting
  address were received. If the CRC read by the bus master is incorrect, a reset pulse must be issued and the
  entire sequence must be repeated. If the CRC received by the bus master is correct, the bus master issues
  read time slots and receives data from the DS2502 starting at the initial address and continuing until the
  end of the 1024-bit data field is reached or until a reset pulse is issued. If reading occurs through the end
  of memory space, the bus master may issue eight additional read time slots and the DS2502 will respond
  with a 8-bit CRC of all data bytes read from the initial starting byte through the last byte of memory.
  After the CRC is received by the bus master, any subsequent read time slots will appear as logical 1s until
  a reset pulse is issued. Any reads ended by a reset pulse prior to reaching the end of memory will not have
  the 8-bit CRC available.

So you are telling it that you want to read the memory from whatever device is on the bus, not any one specific one (since you are not needing to provide the ROM ID to identify the exat item on the bus), starting from address ((0 << 8) |10) = 10.
From the DS2502-E48 datasheet you can see the layout of the memory:

The data record starts with a length byte (0Ah) and the 4-byte UniqueWare Project ID 00001129h. The
  next 6 bytes contain the 48-bit node address which consists of an incrementing 24-bit extension identifier
  and the IEEE-assigned 24-bit company ID value 006035h. An inverted 16-bit CRC ends the data record.
  The remaining bytes of the 32-byte memory page remain unprogrammed. Neither the 24-bit extension
  identifier nor the 24-bit company ID are related to the 64-bit ROM registration number. The ROM
  registration number is used to provide a unique address to access the DS2502-E48 when multidropped on
  a 1-Wire bus.

So translating that into something more pictorial:
// Length byte
0x00: 0x0A

// UniqueWare PID
0x01: 0x00
0x02: 0x00
0x03: 0x11
0x04: 0x29

// Serialization ("extension") number
0x05: 0x??
0x06: 0x??
0x07: 0x??

// Company ID Value
0x08: 0x??
0x09: 0x??
0x0A: 0x??

// 16-bit CRC
0x0B: 0x??
0x0C: 0x??

// All the rest is EEPROM data
0x0D - 0x7F: 0x??

So by starting at address 10 (0x0A) you are reading the last byte of the company ID, the CRC, and then whatever else is in the memory after that.
To read the entire MAC address (least significant byte first) you should be starting to read at address 5.

I found a nice writeup on this on a blog.  To quote his experimental findings:

Comparing to the OneWire spec, we can tell it’s writing 0xCC, which
  should be SKIP_ROM. Following that is 0xF0 (ReadMem), and two bytes
  starting address: 0x08, 0x00.

Based on this, the zero and 10 that you are writing are apparently an address value.


text:
Are there any ePaper modules that are bigger than 2.7 inches for arduino
I am looking for a large ePaper Display for the Arduino. The issue is is that I cannot seem to find one any larger than 4.5 inches in size. That will be compatible with arduino. Even with a controller board.
Are there any companies that sell controller boards for these displays? Is there anyone who can manufacture these epd displays upon request?
I am looking to take this project to a pcb board after I prototype it so do I need to build my own controller? If what parts would you need? Is it easy for a designer with intermediate capability?
I can find all kinds of display like at pervasivedisplays.com and Mouser.com
The end goal is to create a Arduino based project that I can score skeet with to keep track of my average score.

I would suggest you to start the other way: find a sw stack that is known to work and check if any of the controllers/displays it already supports fits your needs. This is how I would do it.
Here is a starting point.


text:
How to I measure the duration of touch with a soft potentiometer?
I'm having a soft pot meter here and I would like to register the duration of the touch event. I'm having a different variable, which keeps going from 1024 to 0 , which regularly takes 60 seconds, but for every second you touch the soft pot meter the count adds 50 up to 1024. Like returning the clock backward.
How would I register/code this?

You'll probably want to use millis (http://arduino.cc/en/reference/millis) to see how long the user touches the sensor.. that's a starting point. Post some code you've tried and we can help you figure it out.

You have to go with timer interrupts. Here is the documentation: http://playground.arduino.cc/code/timer1
Roughly, when you detect a press, an interrupt is raised and the same thing goes for releasing. Using the timer values from both these events, you can accurately measure the time that the press lasted.


text:
A LED should be lit when 'high'. Why does mine only burn with 'low'?
This is my followup question based on a serie of one project. Go my to profile to read 'm all.
So I'm building something which includes a function that has a count (1000) that decreases over time, but by pressing a soft pot meter the count increases. By every increment of 200 one LED is lit. So if the count is 837 4 LEDs are burning.
In my previous question I had issues lighting the LEDs, because they didn't burn even when the code was, as far as I could see correct. Instead it did the opposite of what I coded. Now I changed my code the opposite direction,
writing:

digitalWrite(LED1, LOW);   // turn the LED on (LOW is the voltage level)

Which actually set the LED to bright. While is I'd write it 'HIGH' it would dim.
So my actual question is: How could my LED be lit if it's set to 'low', while you have to set it to 'high' to be actually popping off light?

My complete code:
int cleanCount = 1000;
int IsItWorkingLED = 13;
int softpotPin = A0; //analog pin 0
int LED1 = 1;
int LED2 = 2;
int LED3 = 4;
int LED4 = 5;
int LED5 = 7;

void setup () {
    Serial.begin(9600);
    digitalWrite(softpotPin, HIGH); //enable pullup resistor
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
    pinMode(LED4, OUTPUT);
    pinMode(LED5, OUTPUT);

    digitalWrite(LED1, HIGH);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(LED2, HIGH);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(LED3, HIGH);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(LED4, HIGH);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(LED5, HIGH);   // turn the LED on (HIGH is the voltage level)
}

void loop() {
    int softpotReading = analogRead(softpotPin);
    if (softpotReading < 980) { // IF TOUCHED
        digitalWrite(IsItWorkingLED, HIGH);
        ++cleanCount;
        Serial.println(cleanCount);
        delay(8); // Increase 5 times as fast
    }
    else if (softpotReading > 980) { // IF NOT TOUCHED
        digitalWrite(IsItWorkingLED, LOW);
        --cleanCount;
        Serial.println(cleanCount);
        delay(32); // Decrease slowly
    }
    else {      // If there is something wrong..
        Serial.println("Something wrong!");
        digitalWrite(IsItWorkingLED, HIGH);
        delay(250);
        digitalWrite(IsItWorkingLED, LOW);
        delay(250);
    }

        if (cleanCount <= 200) {
            Serial.println("Knal 1 LED aan");
            digitalWrite(LED1, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED2, HIGH);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED3, HIGH);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED4, HIGH);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED5, HIGH);   // turn the LED on (LOW is the voltage level)
        }
        else if (cleanCount >= 201 && cleanCount <= 400) {
            Serial.println("Knal 2 LEDs aan");
            digitalWrite(LED1, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED2, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED3, HIGH);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED4, HIGH);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED5, HIGH);   // turn the LED on (LOW is the voltage level)
        }
        else if (cleanCount >= 401 && cleanCount <= 600) {
            Serial.println("Knal 3 LEDs aan");
            digitalWrite(LED1, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED2, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED3, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED4, HIGH);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED5, HIGH);   // turn the LED on (LOW is the voltage level)
        }
        else if (cleanCount >= 601 && cleanCount <= 800) {
            Serial.println("Knal 4 LEDs aan");
            digitalWrite(LED1, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED2, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED3, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED4, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(LED5, HIGH);   // turn the LED on (LOW is the voltage level)
        }
        else if (cleanCount >= 801 && cleanCount <= 1000) {
            Serial.println("Knal 5 LEDs aan");
            digitalWrite(1, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(2, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(4, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(5, LOW);   // turn the LED on (LOW is the voltage level)
            digitalWrite(7, LOW);   // turn the LED on (LOW is the voltage level)
        }
        else {
            Serial.println("Just..do nothing");
        }

}

Your assumption that a high is required to light a LED is false. All you need is to meet certain minimum voltage and current thresholds. Since the anode of the LED is tied high, the way to meet these is to bring the cathode low.

I don't got a clue what you actually mean with 'anode' and 'cathode' (beginner, as you might have guessed), but thus by setting it to 'low' it does shine. Ah okay. Thanks!

@SanderSchaeffer: Added a link and annotated symbol to hopefully make it a bit clearer.

An LED wants positive voltage to flow from the anode to the cathode (the + terminal to the - terminal)
You can wire it to a digital pin 2 different ways. (In both cases you'll also need a current limiting resistor to avoid burning out your LED and/or your digital pin, but ignore that for this discussion.)
You can wire the positive terminal of the LED to +5V, and the negative terminal to a digital pin. It sounds like this is what you've done. When you do that, if you set the digital output to HIGH, then both terminals of the LED are connected to +5V, so the LED will be off. Set the output to LOW, and it gets connected to ground. Now current flows out of the +5V rail, through the LED, into the grounded digital pin, and the LED lights up.
You can reverse that wiring instead. Connect the positive terminal of the LED to a digital pin and the negative side to ground. Now, when you set the pin to HIGH, +5V flows out of the pin, through the LED, and into the ground connection, so the LED lights. Set the pin to LOW and both sides of the LED are connected to ground, so it turns off.
Edit:
Note that you talk about voltage levels and dimming LEDs. If you're using digital outputs and HIGH or LOW, you can only turn the LED on or off. There's no way to vary its brightness.
You can, however, hook an LED to a PWM (Pulse Width Modulation) pin and set up that pin for analog output. In PWM, the Arduino switches the LED on and off rapidly. Set it to the highest output value, 255, and the LED stops flashing and is on 100% o the time. Set the output to 128, and the LED is on half the time and off half the time. Set the output to 64, and the LED is on 1/4 of the time and off 3/4 of the time, and so on.
When you flash a light fast enough, our eyes average out the brightness, and a light that's on 1/4 of the time looks 1/4 as bright as a light that's on 100% of the time.
Most Arduinos have a limited number of analog outputs. The Arduino model you're using might not have 7 analog outputs.

When you command digitalWrite LOW you are basically connecting that pin to GND.  If you command digitalWrite HIGH then you are connecting that pin to +5v.  So depending on how you have the LED wired up you can use either to turn on the LED.  Since LOW turns your LED on then you must have the long lead of the LED attached to +5v supply and the short lead to the pin on the arduino.  I don't know why the LED doesn't turn all the way off when you command digitalWrite HIGH, but it should.
If you wanted to dim the leds then you should try using the analogWrite command which will send a PWM signal and will allow you to make the LEDs any intensity you want to.


text:
Arduino turns LEDs off when set 'high', opposite direction as coded
I've got a function that decreases over time (1000 / 60 seconds) and by touching a softPotentiometer you can increase that value. By every increment of 200 a LED is lid. So for 0-200, 1 LED; 201-400, 2 LEDs; etc. And since it decreases over time while doing nothing, if it drops below a certain value, a LED is shut off.
However, I've got a (amateur) coded set up, but somehow it lids the LEDs in the opposite direction. In a way that, I've coded it that if it's above 800, lid 5 LED's. However, it will only lid one LED when it's dropped below the 800, in the area of 601-800.
That's exactly the opposite of what I want. So what am I doing wrong here?

My code:
And with amateur, I mean that I didn't use arrays and therefor write everything multiple times..
int cleanCount = 1000;
int IsItWorkingLED = 13;
int softpotPin = A0; //analog pin 0
int LED1 = 1;
int LED2 = 2;
int LED3 = 4;
int LED4 = 5;
int LED5 = 7;

void setup () {
    Serial.begin(9600);
    digitalWrite(softpotPin, HIGH); //enable pullup resistor
        pinMode(1, OUTPUT);
        pinMode(2, OUTPUT);
        pinMode(4, OUTPUT);
        pinMode(5, OUTPUT);
        pinMode(7, OUTPUT);

           digitalWrite(1, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(5, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)

}

void loop() {
    int softpotReading = analogRead(softpotPin);
    if (softpotReading < 980) { // IF TOUCHED
        digitalWrite(IsItWorkingLED, HIGH);
        ++cleanCount;
        Serial.println(cleanCount);
        delay(16); // Drain 5 times as fast
    }
    else if (softpotReading > 980) { // IF NOT DTOUCHED
        digitalWrite(IsItWorkingLED, LOW);
        --cleanCount;
        Serial.println(cleanCount);
        delay(64); // 1000 / 60 seconds
    }
    else {      // Als er een fout optreed..
        Serial.println("Something wrong!");
        digitalWrite(IsItWorkingLED, HIGH);
        delay(250);
        digitalWrite(IsItWorkingLED, LOW);
        delay(250);
    }

        if (cleanCount >= 0 && cleanCount <= 200) {
           Serial.println("Knal 1 LED aan");
           digitalWrite(LED1, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED2, LOW);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED3, LOW);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED4, LOW);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED5, LOW);   // turn the LED on (HIGH is the voltage level)
        }
        else if (cleanCount >= 201 && cleanCount <= 400) {
           Serial.println("Knal 2 LEDs aan");
           digitalWrite(LED1, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED2, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED3, LOW);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED4, LOW);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED5, LOW);   // turn the LED on (HIGH is the voltage level)
        }
        else if (cleanCount >= 401 && cleanCount <= 600) {
           Serial.println("Knal 3 LEDs aan");
           digitalWrite(LED1, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED2, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED3, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED4, LOW);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED5, LOW);   // turn the LED on (HIGH is the voltage level)
        }
        else if (cleanCount >= 601 && cleanCount <= 800) {
           Serial.println("Knal 4 LEDs aan");
           digitalWrite(LED1, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED2, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED3, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED4, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(LED5, LOW);   // turn the LED on (HIGH is the voltage level)
        }
        else if (cleanCount >= 801 && cleanCount <= 1000) {
           Serial.println("Knal 5 LEDs aan");
           digitalWrite(1, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(5, HIGH);   // turn the LED on (HIGH is the voltage level)
           digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
        }
        else {
          Serial.println("Just..do nothing");
        }

}

Ever thought of what would happen if the softpotReading is exactly 980?
But what if you switch ++cleanCount and --cleanCount. Not sure why you're using those, but switching them around might cause it to work like you expected? There would be a way more efficient way to map your potentiometer reading onto the leds. Don't have time to explain it at the moment. And I don't have an arduino at the moment...
Veel succes!

I've coded it that if it's above 800, lid 5 LED's. doesn't really map onto if (softpotReading < 980) { // IF TOUCHED

If your LEDs are connected anode to +5, cathode to i/o pin, they would behave this way. Cathode to ground, anode to i/o would behave as you expect.

@FuaZe His answer checks out to me, the LED is off when the IO pin matches the ground/power on the other side making the voltage diff 0, and on when the IO pin opposes the power connection making a voltage difference. Many LED's are wired so that they are lit when IO is LOW because of some electrical characteristics of the IO pins I couldn't fully explain.

Yeah, I didn't get it at first glance as I was sure something wasn't 100% in the code. But current will flow from the 5V to the arduino. And indeed putting negative to ground and positive (with current limiting resistor) to arduino will work.

Should I post a photo of my setup (wires and such?). Pretty sure it's correct. If there is software to create a schematic, tell me, else you've got to do it with a picture :)

Basically it comes down to this: if one side of the LED is attached to 5V instead of GND/0V then it will be 'inverted'

Try reversing the if statements.
You say:

I've coded it that if it's above 800, lid 5 LED's.

And your code is:
(softpotReading < 980) { // IF TOUCHED
The code describes: IF softpotReading IS SMALLER THAN 980, DO{ code.. }

In dutch (as OP is dutch, and to be honest his English somehow confuses me a bit, to be sure it's not the other way around also):
Ik denk dat je de IF statements verkeerd om hebt.
Je beschrijft dat bij een waarde hoger dan 800 de ledjes aan gaan...
Echter staat in je code (softpotReading < 980) { // IF TOUCHED
Wat dus zal betekenen dat de code wordt uitgevoerd als die < (kleiner dan) 980 is.

    if (softpotReading > 980) { // IF TOUCHED
    digitalWrite(IsItWorkingLED, HIGH);
    ++cleanCount;
    Serial.println(cleanCount);
    delay(16); // Drain 5 times as fast
}
else if (softpotReading <= 980) { // IF NOT DTOUCHED
    digitalWrite(IsItWorkingLED, LOW);
    --cleanCount;
    Serial.println(cleanCount);
    delay(64); // 1000 / 60 seconds
}

Yeah I'm Dutch ;) But I'll reply in English, for Site's sake. You really got to ignore the 'IF SoftpotReading < 980. Which is completely different. I've got a softPod module which reads out about 1000 if it's not touched. Once you touch it, it never goes above 980. You only have to look at the other statements. I could indeed reverse the IF statements. Thanks

Sander you could also try to do int softpotReading = 1024-analogRead(softpotPin); This way, your softpot wil give 0 for low to 1024 for high

Try to think of what your input is and what you want your output to be. Then you should use your code to bridge that gap.


text:
How should I make a UI for my arduino project?
It's easy enough to attach a display for displaying sensor data, but I'm wondering what the proper way is to have the user change variables using an user interface on the attached 2x16 display.
The only library I found for this purpose:
https://liudr.wordpress.com/libraries/phi_prompt/
Takes a lot of code just to set up. I'm wondering if there's perhaps an easier option. All thoughts appreciated!

The key question is: what do you want to do? Sometimes developing an own library with exactly this functionality you need might be a good alternative to using a large all-in-one library from another party, especially for the Arduino boards with their limited resouces. In that case you also might learn a lot.

I'm just trying to change a few variables, call some functions, give the user the output of functions, etc. Of course I could reinvent the wheel but maybe there's some library I missed.

Well, in this case, reinventing the wheel would not be rocket science. I'd start simple.


text:
Using L298N to control DC Motor
I am developing a system where I want to control the direction of the DC motor (12V) from Arduino Mega/Uno. For that, I am using L298N H-bridge chip without the board as shown below.
My question is, do I need to add extra hardware or is it enough on its own?
Thanks in advance!

Did you already read the L298 datasheet?

In theory, this particular device should work on its own.  However you should search for and read the datasheet for it. (I'll leave you to do that yourself, just to make sure you really do read it.)
You should consider a heatsink too by the way, and provision for things like a fuse on the power, and whether you will be using a separate 5V for the logic (again you need the datasheet for that).


text:
Atmega328p low voltage
I am using atmega328p in my PCB prototype, due to some reason I can use only 4 volt for power supply.
My question is that
"How to run atmega328P through 4 voltage"

Have you read the datasheet?

Your question is rather fuzzy: I could well answer it as "Connect the +4V to Vcc pin and 0V to the GND pin", that would be correct. What is your specific question?

Shouldn't be a problem. The minimal voltage required to run at 16MHz is 3.8 Volt. No extra steps required.

Having only a 4V power supply, you can insert a boost converter to step up the voltage to 5V and then supply it to VCC of atmega328p


text:
Are there any online data analysis websites for arduino IoT projects?
I am planning on making a system where multiple arduinos monitor the conditions of certain type of plant. (Each arduino monitors its own plant, but the plants are of the same species). Each plant would have a different placement in the yard(varies the light). The plants are watered as normal, without an exact amount of water. The arduinos would measure light, temperature, and soil water content. Each would send it to the cloud. My question is: Is their a cloud service that can analyze and "find" the best conditions(amount of water,light,temperature,etc) for type a plant, based on how healthy the plants are?(The health of the plants would be entered in manually by the person using the system). (Sorry if my question doesn't make sense, please ask me any questions you have ,Thanks.)

For starters, you would need to have some mechanism to send the data to the cloud since the Arduino cannot do that as standalone, WiFi or Ethernet shield. Arduino also doesn't have enough capability to interact with SQL or comparable database technology, so you would need to send the data to a PC to do the actual cloud processes.

Yes, I am aware that the arduino requires extra hardware to connect to WiFi. Why do I have to send it to a PC? Why not just send it to a cloud service which analyzes the data?(All the arduino is doing is sending data to a server)

To send data to cloud you will need an internet shield and given that the individual plants are far apart, you will need a wifi shield for each plant that you want to monitor most likely the yun shield.
Now for online services, there are a few like Temboo, Pushingbox, Initial State, Cayenne, Xively.
Each of them works differently and you will need to choose which best suit you.

Thanks for the reply. My question is kind of old so I don't remember the exact context of why I asked my question. But what I think I was trying to ask was, are there any analytics services that find trends based on data, detects patterns, etc. Since then I have seen services such as Microsoft Azure that can analyze and find trends in data. I have used Temboo before and I don't think it has analytical services or anything like that.

Temboo don't have analytics services but you can use Temboo to upload the data to Google spreadsheet and then process the data into graphs or whatever

None of these services will inherently give you an analysis, Dashboards like cayenne can help. But you would still need your business logic layer to compute which plant was in best conditions. You could also try import data into SQL tables and then into SQL CUBE to analyse the data..


text:
avrdude: verification error, first mismatch at byte 0x0000 : 0x00 != 0x16 using USBasp
I'm having this strange error, which pops up around 90% of the time. I am trying to program my attiny25 using USBasp and the Arduino IDE / library. Sometimes it works, most times it doesn't.. This error occurs on large sketches as well as new sketches, with just the empty setup() and loop() functions. The error looks quite random to me, because my program just uploaded after trying around 10 times. Compiling goes fine. The error always occurs at byte 0x0000, and always in the format 0x00 != 0x _ _. I have six wires (correctly) connected from the USBasp to the attiny25. I do not use any resistors, capacitors etc.
Could anyone tell me what could possibly cause this error, and what to do to fix it?

The cause is most likely the fact that you "... do not use any resistors, capacitors etc."
Connect a 100nF capacitor between Vcc and GND.  Connect a 10KΩ resistor between RESET and Vcc.

I have the same problem. As suggested, I have a 10k resistor between vcc and reset, and a 100nF capacitator between Vcc and ground. However, flashing is still extremely unreliable. Is there anything more I could try?

The problem has to do with the auto-reset feature, so you have to make sure the Reset pin is connected to VCC via a pull-up resistor. Generally, a 10k resistor will be just fine.

10µF capacitor between GND and RESET may also work

I had the same issue even with capacitor between Vcc and GND and resistor between RESET and Vcc. Finally, I use 5V Instead of 3.3V to power up my ATTINY and the problem was solved!


text:
Efficiently using a serial inteface
So at my school we are preapering for a competition. They asked me to do the technical side of it. And I accepted... I was thinking of using an arduino as a usb device for the buttons. I am going to use the serial port for this. But I can't think of a way to do it in the way I want. I want to recieve the button presses fair and well. But I also want to control the lights for the buttons, from my computer. I am using Serial.printLn() to send the serial data to the computer. But how can I send serial data to the arduino without delaying other things (What happens when someone presses a button while I am sending a command?)? Thanks in advance!

I was thinking of using an arduino as a usb device for the buttons. - what do you mean here? Later you talk about sending serial data to the PC. These are different things.

So will be also be doing the programming. Since I will be writing the program, I can easily implement the serial communications. All they have to do is plug the arduino in and change the port, if it needs to. That's what I meant.

Serial communication is done using interrupts, and buffers. So unless you do something weird with your program, there shouldn't be much of a problem. It would be helpful to know what it is you are trying to achieve with the buttons. Something like a gameshow, where you need to detect who pressed the button first?

Yes exactly a gameshow. I need buttons for the game. I want to be able to control the lights through the serial inteface. I cannot figure out how I am going to do it. I reckon if I call Serial.readLine() it will halt until it gets an \n

The nastiest part in what you describe is likely to be the debouncing on the button, rather than the serial communication.
One easy way out is to use some form of bounceless implementation, like an optical coupler. Another is to use HW debouncing, like the MAX 6816 family.
Then you can use a loop where you alternate between serial communications and checks for the status of the buttons.
Or you can rely on interrupts for the buttons, but it's more complex and might be overkill.

I can try to debounce the button on the computer. I am also writing the code that will be used for the competition...

The thing is the school is sourcing the parts. I am surprised they even sourced arduinos for the physics lab.


text:
Using Arduino Micro With 12V Buzzer
I have an interesting situation.  I wonder if anyone can help?
I have:

4x Arduino Micros loaded with the basic Blink sketch
5x 12 volt buzzers
A desk full of completely fresh Duracell AA and 9v batteries

If I connect (using VIN and GND) any of the Arduino Micros to either a 9v battery, or a 12v network of 8 AA batteries, then they run the blink sketch, and the appropriate LED flashes on the Arduino as expected.
If I connect any of the buzzers to either a 9v battery, or a 12v network of 8 AA batteries, then they buzz as expected.
If I connect both a buzzer and an Arduino in parallel to either a 9v battery, or a 12v network of 8 AA batteries, then the Arduino works fine, but the buzzer makes barely an inaudible whimper.
If I connect only a buzzer to the Arduino and battery, it works fine.  If whilst the buzzer is buzzing I connect the Arduino, then on every ON or OFF of the blink sketch LED, the buzzer gets quieter and quieter until it can barely be heard.
These buzzers are rated to work at 25mA, so it really astounds me that they can't be run off a battery together with an Arduino.
Any help would be appreciated!
Thanks
Dave

Connect a capacitor across the buzzer - say 100 uF or higher at 16Vor higher. If this affects the above outcomes you have electromagnetic interference.

@Russel McMahon Thanks for the suggestion that it might be electromagnetic interference. Turns out you are right!  I added a capacitor and it started working. If you put a proper answer in, I'll mark it as accepted.

Thanks for the offer. I suggest that you accept jwpat7's answer as he has incorporated my brief suggestion as part of his answer and overall his answer is informative and useful for other users with power related issues.

Attach your voltmeter across the battery, and measure the available voltage when different things are attached; or attach it in series, and measure current draws.  You probably will find that a 9V battery's voltage is under 8 volts when a mix of multiple Arduinos and buzzers is attached.  That voltage may be too low to activate the buzzer.
A powerstream.com web page called 9V Alkaline tests shows how rapidly a 9V battery's voltage drops when heavy currents (more than a few dozen milliamps) are drawn from it, and a batteriesinaflash.com web page includes the following diagram that shows battery voltage quickly falling below 8.5 V in its first minutes of life when 27 mA is drawn from it.
For some models of Arduino, eg the Uno R3, various posts on the web list currents from 25 mA up to 45 mA, depending on LED and sleep settings.  Currents for the Duemilanove from 10 mA up are reported.  The Arduino Micros in your tests probably use a little more current than Pro Mini boards (which have no USB), and although it's unlikely they will use as much or more current than the buzzers, they still may drag the voltage down to a level where the buzzers won't work.
If your system needs to be battery powered, consider using separate batteries for different devices, to avoid problems like you saw.  Alternatively, use heavier-duty batteries, eg good-sized lithium-polymer units.  Also review posts about decreasing Arduino power usage via sleep, disconnecting the power LED, and using large capacitors to buffer power surges.
Edit: Given that voltage measurements show enough voltage being available, the suggested use of capacitors or inductors to isolate circuits may be a good idea.
When adding a capacitor, locate it physically close to the power-using board or component.  For electrolytic  capacitors, attach the capacitor's + terminal to the high side, eg to the +5, +9, or +12 side, and attach its - terminal to ground.
When adding ferrite beads, wrap the supply wire through the bead several times, if there's room.  The picture below illustrates the idea.
An electrolytic capacitor across a circuit acts as a voltage reservoir.  It also gives high-frequency signals an easy path to ground, reducing interference.  A ferrite bead or other inductor impedes high frequency signals, again reducing interference.

Thanks for the answer - in reading through it and the provided links, I've learned a lot about batteries that I didn't know!  I got my volt meter out, and measured the voltage. Turns out not to be voltage related, but electromagnetic interference from the arduino.  +1 for all the interesting stuff I've learned about batteries. Thank you.

+1 - nicely detailed and presented answer. You probably would benefit from and be useful in the Stack Exchange EE group as well. I see you are involved in a wide range of groups already (quite a lot of overlap with me fwiw). Are you really as venerable as your profile page says ? ! :-)

@RussellMcMahon, not quite :) but sometimes feel like it :(.  I learned Fortran and assembly language programming using an IBM 1620 in 1965.


text:
Why Firmata Test doesn't allow me to choose a port?
I'm a beginner and, sorry, also I don't speak English very well. However, I'm going to try to explain my problem.
I'm working on Ubuntu 14.04.2 and Arduino Uno R3.
I downloaded Firmata Test binaries for Linux 64 bit, I gave it permissions with chmod 754 <file>. Also I uploaded StandardFirmata from Arduino IDE to the board. Afterwards, I quit Arduino IDE and ran Firmata Test with ./file. But, the Port menu has no items within. I tried restarting the board and the application as well.
What can I do?

If your user does not have access to serial ports, rather than running an application as root with sudo, try giving your user the appropriate permissions by adding to the dialout group before you run it.
https://askubuntu.com/questions/112568/how-do-i-allow-a-non-default-user-to-use-serial-device-ttyusb0

I had the same problem until I ran it as:
sudo ./file


text:
Is it possible for a HC-05 Bluetooth module to have multiple slaves
For a project I am interested in using the HC-05 Bluetooth module to control five LEGO Mindstorms Bricks simultaneously. For this to work the Bluetooth module will obviously have to be paired / connected with the five bricks at the same time. This means that the HC-05 Bluetooth module will have to be master in the piconet and the five bricks the slaves.
Is there anyone who has any experience with using the Arduino Uno and HC-05 Bluetooth module to send data to multiple, connected, slaves? If not, are there any alternative Bluetooth modules? And if Bluetooth modules compatible with the Arduino Uno cannot connect to multiple slaves at the same time, are there other ways that an Arduino can control multiple Bluetooth slaves at the same time?

After some research, it looks like multiple slaves aren't possible with this particular module.
According to Wikipedia the Bluetooth technology allows a master to communicate with 7 slaves, but this option isn't implemented in the HC-05.

I feared as much. Would you happen to know if there are any other Bluetooth modules or shields that support multiple slaves? Or that are worth looking into. Also, would you happen to know how long it takes for the HC-05 module to disconnect / connect to a Bluetooth device?

No I never used any Bluetooth module so I can't help you, sorry. Google is still an option though.

The connection/disconnection takes about 2/3 seconds to be achieved.

Sadly that'd take too long for it to be practical.


text:
EEPROM value reverting to 255
When I write '13' to the EEPROM and read it straight after it works correctly.
However when I comment out the write part of the code and try to just read the data, the value is no longer 13 as it used to be but reverts back to 255. Whats going on?
I am running a standalone atmega328 on a breadboard with a 16mhz crystal, programmed by a Nano R3.
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);

//EEPROM.write(1,13);
}

void loop() {
scoreBinary();

}

void scoreBinary(){

int score= EEPROM.read(1);

if(score==13){
digitalWrite(2,HIGH);
}
delay(10000);
}

By default the EEPROM in the MCU is erased (to 0xff) when the chip is erased before flash is written to. If you want to prevent this then you will need to program EESAVE in the fuse bits, which is bit 3 in the high fuse byte of the '328.

Ah! Thank you! Makes sense! Now to change the fuse bit should I change the value in boards.txt ? Currently the high fuse byte is diecimila.menu.cpu.atmega328.bootloader.high_fuses=0xDA (1101 1010 in binary) And I should change this to diecimila.menu.cpu.atmega328.bootloader.high_fuses=0xFA (1111 0111 in binary) Is that correct =/ ?

Or perhaps theres something I can type in the cmd using avrdude?

Read the current high fuse value (avrdude ... -U hfuse:r:-:h), bitwise-and it with 0xf7, and write it back out.


text:
Arduino Mega 2560 multiple slave via SPI
I'm new to Arduino and microcontroller . I want to connect my Arduino Mega to three slaves which Arduino Unos. I know that these slaves will share MISO, MOSI, and SCK lines. However, SS is unique to each slave.
For single slave, the SS is pin 53. So, for three slaves, which other two pins can I use as SS?
Thank you for your help.

Any you like. There's nothing magic about them, as long as you have the main SS pin as an output to ensure the SPI port is in master mode.

You can use any pin for the Slave Select. The SS pin on the Arduino is only used as SS when the arduino is an SPI slave, not (like in your case) when it's the master. The only thing you have to take care of is to not use the SS pin as an Input.
Just make sure the library you are using allows you to specify your own SS output pin.


text:
Arduino Orion Upload - Which Board When Compiling
I'm trying to compile and upload the example code for the arduino robotics starter kit (https://github.com/Makeblock-official/Makeblock-Library and https://raw.githubusercontent.com/Makeblock-official/Assembly-Instructions/master/Starter_Robot_Kit_IR_Instruction.pdf).
In the IDE to compile the code, you need to select the appropiate 'board' for the sketch, and the Arduino Orion isn't listed.  Should I just compile under the Arduino Uno, which I believe the Orion is based on?

Yes, the "Orion" is just an Uno in a different shape with different connectors.  Just treat it like an ordinary Uno.
Similarly the "Baseboard" is just a Leonardo in a different shape with different connectors.


text:
How to Store 2 analogRead values and read using EEPROM for Arduino Uno?
Trying to write 2 values coming from analogread(A0) and analogread(A1) by EEPROM.write  and retrieve the values by EEPROM.read. I tried the following sketch for each write and read. However, could not get the values. Any help please.
For writing to EEPROM:
#include <EEPROMex.h>
int addr = 0;
int array[] = {0, 0};
char a;
void setup() {
}
void loop() {
    array[0] = analogRead(0) / 4;
    array[1] = analogRead(1) / 4;
    EEPROM.write(addr, a);
    addr = addr + 1;

    if (addr == 512) {
        addr = 0;
    }

    delay(100);
}

For reading from EEPROM is:
#include <EEPROM.h>
int address = 0;
int value[2];
void setup() {
    Serial.begin(9600);

    while (!Serial) {
        ;
    }
}
void loop() {
    value = EEPROM.read(address);
    Serial.print(address);
    Serial.print("\t");
    Serial.print(value[0]);
    Serial.print("\t");
    Serial.print(value[1]);
    Serial.println();
    address = address + 1;

    if (address == 512) {
        address == 0;
    }

    delay(500);
}

See Reading and Writing Data Structures to EEPROM.
EEPROM.write(addr,a);

You can't directly write arrays. See the link for how to do it.
Example code:
#include <EEPROM.h>
#include <EEPROMAnything.h>

int array[2];
int addr=0;

void setup()
{
}

void loop()
{
  array[0] = analogRead(0)/4;
  array[1] = analogRead(1)/4;
  EEPROM_writeAnything(addr, array);
  addr += sizeof (array);

  if(addr >= 512)
    exit (1);

  delay(100);
}

Your posted code is a bit flawed anyway. You know EEPROM has a limited life? If you have a sketch that writes to EEPROM indefinitely you will wear it out.
My code above stops once it reaches address 512.

You write the read value directly to value, while value is actually and array. Try this instead.
void loop() {
    value[0] = EEPROM.read(address);
    value[1] = EEPROM.read(address + 1);
    Serial.print(address);
    Serial.print("\t");
    Serial.print(value[0]);
    Serial.print("\t");
    Serial.print(value[1]);
    Serial.println();
    address = address + 2;

    if (address == 512) {
        address = 0;
    } // not address==0;

    delay(500);
}

If this fails try EEPROM.write(&addr,a); and EEPROM.read(&address);

address==0; ?

@NickGammon missed that one. Nice catch.

cant do anything with EEPROM_writeAnything.

I tried with EEPROM_writeAnything but only get one analogread output data. What should I do? Apparently I try to write 2 sensors voltage output in an experiment and then retrieve the stored values for data analysis.

I think these comments are targeted at @NickGammon answer, not mine.

What should I do? - you should amend your question, and post the code you tried.

An int is two bytes so you should be doubling your address increases, n'est pas?

@CharlieHanson address = address + 2;?

The OP uses an int array yet stores only the lowest significant byte into the EEPROM. Bad practice but goes unnoticed because the maximum value ever stored is only 255 (MAX_ADC / 4). The uninitiated could be misled into thinking one call each to EEPROM.write() and EEPROM.read() will magically store and retrieve a multibyte value. In hindsight my comment should have been clearer.

EEPROM can store one byte at a location. To store value of int, it requires two consecutive location. For double, it requires four memory location. I have written code to store and read, int & double to and from built-in EEPROM. Modify as per your need.
/*
  StackExchange Question: "How to Store 2 analogRead values and read using EEPROM for Arduino uno?"
  Question Id: 15910 (http://arduino.stackexchange.com/questions/15910/how-to-store-2-analogread-values-and-read-using-eeprom-for-arduino-uno)
  Author: Anurag S. Vasanwala (AnuragVasanwala@gmail.com)

  Tested on Arduino Version 1.6.7

  Description:  This sketch helps to store and read, Integer & Double to and from built-in EEPROM.
  Objectives:
    + Write Integer @ Specified Address (Fn: EEPROM_Write_Int)
      + Conversion from Integer to Byte Array
      + Store Bytes
    + Read Integer from Specified Address (Fn: EEPROM_Read_Int)
      + Read Bytes
      + Conversion from Byte Array to Integer
    + Write Double @ Specified Address (Fn: EEPROM_Write_Double)
      + Conversion from Double to Byte Array
      + Store Bytes
    + Read Double from Specified Address (Fn: EEPROM_Read_Double)
      + Read Bytes
      + Conversion from Byte Array to Double
 */
#include <EEPROM.h>

// MACRO : Combines FROM_BYTES into TO_OBJECT of datatype "DATATYPE"
#define CombineBytes(FROM_BYTES, DATATYPE, TO_OBJECT) \
  TO_OBJECT = *((DATATYPE *)FROM_BYTES);

// MACRO : Splits FROM_DATA of DATATYPE into equivalent byte array TO_BYTES
#define GetBytes(FROM_DATA, DATATYPE, TO_BYTES) \
  *((DATATYPE *)TO_BYTES) = FROM_DATA;

// Writes Integer's equivalent bytes to Address and Address + 1
void EEPROM_Write_Int(unsigned int Address, int Data)
{
  // Get the size of datatype to write number of bytes
  const byte SizeOf_DataType = sizeof(int);

  // Create tem buffer to get Bytes of Datatype
  byte Temp_Buffer[SizeOf_DataType];

  // Call macro to store byte array into Temp_Buffer from Data
  GetBytes(Data, int, Temp_Buffer);

  // Write number of bytes to memory location specified in Address and so on
  for(byte Index = 0; Index < SizeOf_DataType; Index++)
  {
    EEPROM.write(Address + Index, Temp_Buffer[Index]);
  }
}

// Reads two bytes from Address and Address + 1 and returns equivalent int
int EEPROM_Read_Int(unsigned int Address)
{
  // Get the size of datatype to write number of bytes
  const byte SizeOf_DataType = sizeof(int);

  // Create tem buffer to get Bytes of Datatype
  byte Temp_Buffer[SizeOf_DataType];

  int Result;

  // Read number of bytes from memory location
  for(byte Index = 0; Index < SizeOf_DataType; Index++)
  {
    Temp_Buffer[Index] = EEPROM.read(Address + Index);
  }

  // Call macro to combine bytes into equivalent to int
  CombineBytes(Temp_Buffer, int, Result);

  return Result;
}

// Writes Double's equivalent bytes to Address, Address + 1, Address + 2 and Address + 3
void EEPROM_Write_Double(unsigned int Address, double Data)
{
  // Get the size of datatype to write number of bytes
  const byte SizeOf_DataType = sizeof(double);

  // Create tem buffer to get Bytes of Datatype
  byte Temp_Buffer[SizeOf_DataType];

  // Call macro to store byte array into Temp_Buffer from Data
  GetBytes(Data, double, Temp_Buffer);

  // Write number of bytes to memory location specified in Address and so on
  for(byte Index = 0; Index < SizeOf_DataType; Index++)
  {
    EEPROM.write(Address + Index, Temp_Buffer[Index]);
  }
}

// Reads four bytes from Address, Address + 1, Address + 2 and Address + 3 and returns equivalent double
double EEPROM_Read_Double(unsigned int Address)
{
  // Get the size of datatype to write number of bytes
  const byte SizeOf_DataType = sizeof(double);

  // Create tem buffer to get Bytes of Datatype
  byte Temp_Buffer[SizeOf_DataType];

  double Result;

  // Read number of bytes from memory location
  for(byte Index = 0; Index < SizeOf_DataType; Index++)
  {
    Temp_Buffer[Index] = EEPROM.read(Address + Index);
  }

  // Call macro to combine bytes into equivalent to double
  CombineBytes(Temp_Buffer, double, Result);

  return Result;
}

void setup()
{
  // Initialize Serial @ 9600 baud
  Serial.begin(9600);

  // Print size of datatype just for reference
  /* Serial.print("Size of byte = ");
  Serial.println(sizeof(byte));
  Serial.print("Size of int = ");
  Serial.println(sizeof(int));
  Serial.print("Size of float = ");
  Serial.println(sizeof(float));
  Serial.print("Size of double = ");
  Serial.println(sizeof(double)); */

  int myInt1 = -290;
  int myInt2;
  double myDbl1 = 23.41;
  double myDbl2;

  // Write myInt1 @ 100 memory location; It requires 2 consequtive memory location to store integer
  EEPROM_Write_Int(100, myInt1);

  // Read integer located @ memory location 100 and assign it to myInt2
  myInt2 = EEPROM_Read_Int(100);
  Serial.println(myInt2);

  // Write myInt1 @ 200 memory location; it requires 4 consequtive memory location to store double
  EEPROM_Write_Double(200, myDbl1);

  // Read double located @ memory location 200 and assign it to myDbl2
  myDbl2 = EEPROM_Read_Double(200);
  Serial.println(myDbl2);
}

void loop()
{

}

This code is successfully tested on Arduino Version "1.6.7".


text:
Connection of serial pin on ATMEGA328P to connector B type(female) D+ and D-
Now I am using ATMEGA328P and want to communicate with computer in serial using B connector female (also want to provide power from computer to ATMEGA328P using B connector).
So here is my question. How can I connect D+ and D- to ATMEGA328P's pin No. 2 (PD0/RX) and pin No. 3 (PD1/TX)? In other words which pin should I connect to D+ and D- ? Also is it possible to connect them directly?
Thank you in advance.

Have you examined the schematic of an Arduino device that uses the '328P?

I have seen the schematic of Arduino but  they connect D- and D+ to ATMEGA1602. But this time I want to use ATMEGA328P only.

Did you ever stop to wonder why they do that?

I'm not quite sure, maybe due to converting. But now I am asking is it possible doing that with ATMEGA328P only?

Pull up the datasheets for both devices; you don't need the complete datasheets, just the summary datasheets will do. Examine and compare the front pages.

I did. But really don't get what to see. If possible could please explain weather it is possible to use ATMEGA328P only.

Are you asking how to connect a USB "B" connector to pins 2 and 3 of the Atmega328P?

Yes. Exactly.  I want to realize serial communication with computer.

The Arduino Uno (and similar boards) have a chip on them that does serial communication via a dedicated USB chip (the ATmega16U2 chip). You can't just connect pins 2 and 3 to D+ and D- and turn that into USB.
You can conceivably do it using V-USB which does USB in software in conjunction with a few extra components.
You can also buy external serial to USB adapters which do the conversion externally. If you Google serial to usb adapter you will find quite a few for around $3.

The Adafruit Trinket Pro https://www.adafruit.com/product/2000 uses this, so does the usbasp (not Arduino code) http://www.fischl.de/usbasp/ @zalt, if you have to ask, don't do this. I has special requirements for the hardware and software, and it is something for advanced engineers. Stay away from it.

ok I did with HID-class USB Serial Communication for AVRs using V-USB. I  could monitor the incoming data to PC  by HID Serial Monitor.
However, I need to monitor the incoming data by Serial monitor such as tera-term or Arduino's serial monitor.
Is there anyway to do that with HID-class ?
I tried trinket-fake-usb-serial, but did not work at all.
Please I need help.

This sounds like a different question to me. First you ask if certain ports can be connected to a USB device, now you are asking about monitoring serial data with a HID-class USB. I suggest you make a new question. Offhand, using a HID (Human Interface Device) when there isn't a human there clicking away seems like a misuse of the hardware.

All I want to do is just getting the serial data from MCU(ATMEGAA328P)
to PC  without using serial to usb adapter.

The Atmega328P doesn't have a USB interface so what you want isn't really practical. There is no "simple wiring" that will achieve that.


text:
How to power and switch on / off multiple boards at the same time?
I have many nodes.
Each node consists of an MPU9250 and ESP32.
Each node functions independently. They don't interact with each other.
How can I power all of them at the same time, and switch them all on / off at the same time easily ?

Do they have a common power source?

@Majenko Right now they all have their own batteries. I have no electronic engineering background, so not sure how to get started in figuring out how to power all of them from the same source.

If they're not on a common power supply, and they don't communicate with each other, there's no way you can control them all together. Especially not for turning them on. To power them all from the same source, just connect them all to that source. Then you have one power switch at the source to turn them all on and off.

@Majenko that’s the design problem. If you connect them all to the same power source won’t they all draw more power? So won’t you have to design some kind of circuit to ensure they all get the same amount of power or something...

No, that's not how it works. A device only draws the power it needs. As long as the power supply can provide at least the total amount of power for all the devices together, that's fine.

So if each device is x volts and need y amperes, how do I figure out how big a battery I need?

One that provides x volts and, at a minimum, y*z amps - where z is the number of devices.

x volts and y*z * 1.2 amps (giving yourself a 20% buffer).

If you do hook them all up to a single battery then the problem is much simpler. Just wire a switch into the battery connection. Turn on the switch and power flows to all of your nodes. Turn off the switch and the flow of current stops, and they all turn off.

You need to provide more details. How many is "many"? How far apart are they physically? Can you run wires between them? Could you use radio control?
You said in the comments that they are each powered by separate batteries.
One possibility would be to put a power MOSFET transistor on each battery, switching the power supply for a given node. Then wire the gates (and grounds) all together and control them with a switch connected to the supply from one of your batteries (or from a 5V logic line.) MOSFETs draw almost no power at idle, and draw very little gate current for switching, so you should be able to drive dozens of them from a single 5V control line. However, this would require that you have a wire running from a central switch to every node, as well as a common ground to all of them.

Not more than six feet between any node. About 30 nodes. I can run wires between them. I don’t know what you mean by radio control. This is all new to me. I’m a software dude, so just trying my hand at surgery for fun. I don’t actually know much about the liver, spleen or what the pancreas does....  Any tips or guidebook I could read really fast?

There's a lot to learn. It sounds like you're fairly new to electronics and electrical circuits, so you need to learn the basics of voltage and current, power supplies, voltage regulation, and analog circuits. Then you should probably read up on CMOS, since most modern computers including Arduinos are mostly CMOS. Then you should learn about microcontrollers in general, and Arduinos and their quirks in particular.

That’s seems like a lot. I’m just going to hook up wires and see what happens.

Consider what you have to learn in order to develop software. You need the basics of programming, (data types, flow control instructions, etc) OO concepts, data structures, and algorithms. Then you need to learn the OS and application framework(s) for your target platform, and one or more programming languages. Electronics and microcontrollers are similarly complex.

Dude I’m like the obi wan of programming... I bet I could lern lectronixs super fast if I had a tutor....

With software when something crashes you just change your code and try again. The problem with "just hooking up wires and seeing what happens" in electronics is that sometimes things start smoking and never work again.

I gotta try man!!!! I just gotta!!!!!

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


text:
Can I use this board to control multiple vibration motors?
I am looking at this: https://learn.adafruit.com/16-channel-pwm-servo-driver
Although it’s meant for servos, I was wondering if I could use them to control vibration motors.
Motors like these: Diameter Flat Button Type 3V-4.5V Cellphone Micro Vibration Motor (Pack of 3) https://www.amazon.in/dp/B07CQXZBZD/ref=cm_sw_r_cp_tai_yzSvDb8V7JAF4
Any suggestions? I would like to control about 200 motors with minimal number of controllers.
Each motor should be controllable individually.

It's not really meant for servos, it's LED driver chip that can be used to drive position of servo too (with on board pull up resistors). It could be strong enough to drive low current vibration motors, but there must be snubber circuit.

And if you need on/off only, there are led drivers for that too.

@kiiv From what I have seen the board can drive 25mA max - but those motors appear to be 66mA from what I have managed to find.

Not directly, no.  Those boards are designed to generate a low power PWM signal for passing to a servo with a built-in controller. To use that output directly with a motor you will need to add a transistor to each output to control the motor.

simulate this circuit – Schematic created using CircuitLab

instead of a diode, I'd recommend a capacitor across the motor, I think that would allow finer control for a square signal, and reduces power factor for a high-frequency signal

@tuskiomi Good point. Had my head in relay mode ;)

@SimSon In the question there is this final note: Each motor should be controllable individually.

How to you control each motor individually?

Also can you run all or some of the motors at the same time? Like how you light up only some Leds in a board to spell out a message.

You have to build this circuit for every single motor. Then connect each of the MOSFET gates to a single PWM output of the used PWM boards. If you only need on off control, you should use shift registers with the circuit above.