How to send signals from one Arduino to another by using analogue in?

Hello, I am a absolute dummy in terms of electronics and have - I think - a small problem.

I have an Arduino 2560 of which all 54 digital channels are used. Now I want this Arduino to be able to receive signals at analog inputs. These signal come from another Arduino.

This is what I want:

I need five different states to be recognized by the 2560. Now I was already starting to solder a CMOS 4066 as a four channel switch and connect them to four different analogue inputs, but then I wondered if it was not possible to do that much easier by using only one analogue channel but measuring the values at the analogue in, which then indicate the states by ranges, like this:

value 0 = state 1 value 1-250 = state 2 value 251-500 = state 3 value 501-750 = state 4 value 751-1023 = state 5

What do I have to do on the sending Arduinos side to achieve this, and what on the receiving Arduinos side?

Thanks a lot for your help!

Martin.

Why not use the analogue inputs as digital inputs, and use software serial?

What do I have to do on the sending Arduinos side to achieve this,

A PWM output going into an RC filter.:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

and what on the receiving Arduinos side?

val = analogRead(0);
if(val == 0) { // do state 1 }
if( val >0 && val <251) { // do state 2 }
if( val >250 && val < 501) { // do state 3 }
// and so on

Thanks a lot for the replies.

I think the filter would be a solution, but on the other hand the transmission and the following evaluation should be as fast as possible. And as far as I can see the filters are hardware, and when going this way I could also use the CMOS 4066.

But what about this software serial? I think I found the appropriate examples, but will this be reasonable fast?

Thank you very much!

Why bother with software serial on the analog pins of a mega.

The mega has 4 USARts so move some of the stuff from the pins for one of the USARTs to the analog pins (used as digital pins) and use the USART.

I do wonder if all 54 digital pins are usefully employed.

...R

Thanks a lot for all the suggestions, I did it the hard way via CMOS 4066, using the four analog Ins.

The 54 channels are occupied for triggering 52 cameras while leaving 0 and 1 for USB communication. That's what I do: Click

I can't think of any reason not to move the camera controls from (say) pins 18 and 19 to two of the analog pins which can also be used as digital pins. Then you could use the freed up USART.

...R

Well, all the 52 cameras are already soldered with blood and tears to the 2560, I did not want to unsolder and resolder two of them. Looks somewhat strange when all cameras are using the digital pins one by one but two of them don’t.

Also I have a nice loop in the code:

for(i=2;i<54;i++)
{
       triggerCamera(i);
}

I would need to use a map to trigger the cameras in a ordered manner if I was using two analog pins. And that would make the code less fast. I need them to trigger with the smallest delays between them.

However the CMOS 4066 solution is working very good, so I am happy with this.

Thanks for your suggestions!

In case this matters at some point for your project.

Isn't there a fast way to run the pins on an arduino?

http://arduino.cc/en/Reference/PortManipulation#.UwHwNGJdU1M http://www.instructables.com/id/Arduino-is-Slow-and-how-to-fix-it/?ALLSTEPS

I would need to use a map to trigger the cameras in a ordered manner if I was using two analog pins. And that would make the code less fast. I need them to trigger with the smallest delays between them.

It is just an array that would map the pins, the speed increase would be totally negliable.

The MEGA2560 54 digital pins include the 16 analog and 15 pwm pins.

GoForSmoke: The MEGA2560 54 digital pins include the 16 analog and 15 pwm pins.

It has 54 digital pins PLUS 16 analog Inputs, so now problem on this side, still a lot on Inputs left, I needed only four.

clockdivider: Looks somewhat strange when all cameras are using the digital pins one by one but two of them don't.

I wonder how many £billions have been wasted over the years because people have not been prepared to modify their requirements so that computer projects are easy to implement.

Treat the unsoldering pain as a lesson to plan a little farther ahead.

...R

clockdivider:

GoForSmoke: The MEGA2560 54 digital pins include the 16 analog and 15 pwm pins.

It has 54 digital pins PLUS 16 analog Inputs, so now problem on this side, still a lot on Inputs left, I needed only four.

Then it's got 70 digital pins, 16 of which are capable of analog input. And BTW, those pins will give you faster, more solid comms used as digital pins, but if you use the hardware serial and SPI ports for comms the speed can go way up.