# Using PWM to communicate between ATTiny85s

Some background: I am putting together a display to teach children about how neural circuits work. I am making a group of 'blocks' (each of which contains an ATTiny85, an indicator LED, and input/output wires) that can be connected in different configurations to represent different circuit motifs.

The problem: I am trying to use PWM to communicate between the ATTiny85s. My original idea, simply reading input PWM signals with analogRead and generating a PWM output with analogWrite, worked fine while all the ATTiny85s were running off a 5V power supply from an Arduino. However, now that I've switched to using a 4.5V battery pack for each ATTiny85, the PWM communication no longer works.

I expected the PWM outputs to change somewhat (given that HIGH is now limited to 4.5V), but what I am finding is that the output values (when read into an Arduino using analogRead OR pulseIn) now jump around hugely (e.g. pulseIn read out between 50 and 15000 from PWM output analogWrite(250)). Even averaging over up to 1000 pulses doesn't do much to smooth out the value.

Am I missing something?

• PWM is digital (analogWrite is badly named since there is nothing analogue about it). You'll need to filter (e.g. RC low pass) the PWM signal to get an analogue voltage. – Tom Carpenter Jun 14 '17 at 9:52
• I don't need an actual analog voltage, I just need some way for the ATTiny85s to communicate in different configurations. The analogRead to get the PWM input was a bit of a cheat, but I'm having the same problem using pulseIn. – fminl Jun 14 '17 at 9:55
• You will have to explain your signal protocol better. Do you just want to detect whether there's a PWM output or not, or does the PWM actually contain data? If so, how is it encoded? – Dampmaskin Jun 14 '17 at 10:38
• Have you got a shared ground between all your nodes? Ie negative of all batteries shorted. If each ATTiny has its own battery they will all have different ADC references based on their battery state. – Colin Jun 14 '17 at 11:32
• As Tom Carpenter said, you should low pass filter the PWM so that it becomes a stable voltage. The ADC can't make sense of raw PWM, and I have no idea why it seemed to work for you at 5V. – Dampmaskin Jun 14 '17 at 12:03