Arduino, Sensors and EEPROM

tl;dr: If you need to store just some counters related to sensor reading from your standalone Arduino, you don’t need to buy an SDcard reader, use the flipping 512 bytes that your favourite microcontroller is shipped with!

I have two parrot. They are nice pets. They fly, they speak (mostly swear in sicilian), but one of them, screams. Not really like , probably even worse.

I am Freddy, and I say “SUCA” and scream like mental for no reason

So, in order to see if it was just when I was home (trying to say that he is happy to see me), and given that I could be bad-ass programmer, I thought, that I could, perhaps put some crap together to record his screaming activity.

So BAM! There you go from Amazon a small mic sensor:

Which will give you a LOW on the Analog read, if some weird spike of noise happen to occur meanwhile 5V are between the pin +5V and GND

So well, seems fine, you just put this mic sensor in the cage of the parrot somewhere, hoping that it will not chew it as it was one of his toys, then what?

We would like to collect some data from it… don’t we?

Well, we could let our inner compulsive Amazon shoppers win, and buy all the wireless modules in the world, just in case one of them is easier to manage/make work… or… we could avoid buying crap and use whatever Arduino is already providing us.

For who does not know, yeah, this wonderful object has a small EEPROM, which can be used in your project to save stuff on, and on the Arduino-IDE there are some useful examples on how to Read,Write and Clean the abovementioned memory.

The problem (not really a huge problem, seen that I found a solution for it) is that it has just 512 bytes, so you can store just 512 times a number between 0 and 255. Which, in comparison to whatever we are used to manage nowadays, is ridiculously small.

Just a couple of minutes before giving up and go to buy an SDcard reader I told myself:

“…the computer that put man on the moon…had approximately 64Kbyte of memory and operated at 0.043MHz…”

Is way more than 512 byte (approximately shitloads more), but still… I am no astronaut, and I just need to see if my parrots does scream and when.

So I started to think, that I am not away for longer than 8 hours (for work or to buy Pringles)… and 8 hours have 480 minutes … which is ~512… and if that screaming little shit will not scream more than 255 times in a minute, I think I could manage to store those information in the EEPROM.

A chinese clone of Arduino, with some jumpers on the mic

I mounted the mic, and off we go, of course after pushing some spaghetti-arduino-code put in place for the purpose:

#include <EEPROM.h>
// start reading from the first byte (address 1) of the EEPROM,
// I reserved address 0 is for the total counter
int address = 1;
const int analogInPin = A1; // Analog input pin that the mic is attached to
int sensorValue = 0;
int cycles = 0;
int inCycles = 0;
int total = 0;
void setup()
void loop()
cycles ++;
for (int fractions = 0; fractions < 11; fractions = fractions + 1){
sensorValue = analogRead(analogInPin);
if(sensorValue < 1018){
inCycles = inCycles + 1;
total = total + 1;

if (cycles == 60){
EEPROM.write(0, total);
EEPROM.write(address, inCycles);
address= address + 1;
cycles = 0;
inCycles = 0;

Basically I am sampling every 100 ms as you can read inside the for statement, and every 10 times I got a second.

Within the for statement body, I am reading the mic, if a low is detected I count it, twice (total of the screams and just the one in the current cycles round).

When we get out of the for, I check whether 60 cycles of 1 second passed by, if they did I just record on the address 0 the updated total, and on the address n (where n is the number of cycles of 60 seconds passed by from when I turned on Arduino) the number of LOW detected in that interval.

Easy-peasy innit?

At the end, just reading the EEPROM values we would get something like

0: 15
1: 4
2: 0
3: 0
380: 7
381: 3
450: 1
512: 0

Which, starting from the number at the address 1: 4 LOWs detected… that little shit screamed ~4 times in a minute, the first minute.

… then it was good till the minute 380 and 381… then quite again.

If you remember to take the time you put your arduino on, you can then easily find out what time it was when the LOWs were detected, and do the crap you need to do with this amount of data, I don’t know make a Plot, print it and eat it in a sandwich…

Well, at the end you could ask: I don’t have a parrot, why do I need to do this?

The question is mine then, a question to myself. Why did I write this post? I don’t know, probably because I was searching around internet of someone doing something like that but there was nothing, and I hope that this post/tutorial will be helpful for someone, parrot owner or not.

Just a screenshot, before saying bye…

I end up buying it… but was st 80p, so be good with me

If you have any questions about this, just comment, I will reply as soon as possible.


Like what you read? Give Vincenzo Ciaccio a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.