Thingspeak.com allows one to post information gathered by a networked device in real time. I decided that I would test out the system with a simple light sensor. Then, I went further by developing a new Processing application which detects motion using a webcam and posts it to a ThingSpeak channel.
I’ve been working with microcontrollers for some time, but Thingspeak.com is a great way to connect those microcontrollers to the world.
Light Sensor Development
First, I made a simple program to learn how to send an HTTP GET request to thingspeak.com: thingspeaktest.zip. The program sends any numeric key press as a value to the thingspeak server.
Then I made the circuit to interface the light sensor to the Arduino.
The code I uploaded to the Arduino couldn’t be simpler:
void setup(){ Serial.begin(9600); } void loop(){ Serial.println(analogRead(0)); delay(10000); }
Then, I modified my original processing app so that it forwards data received from the arduino to the server: click here to download
Motion Sensor Development
After making the system with the light sensor, I had the idea to make a motion sensor using a webcam.
The Processing application essentially does the following:
- Takes the difference between frames continuously for thirty seconds (at only 2 frames per second to not overload the CPU).
- At the end of the thirty seconds, takes the max difference between frames and interprets this as the movement value.
- Sends this movement value to ThingSpeak.com
Results
Click here for a live graph of the light sensor data. (Not active)
Click here for a live graph of the motion data. (Not Active)
After getting it to work, I checked the output after leaving it over night. I was surprised to find that in the dark, the output was a regular sawtooth wave. What is the source of this strange signal? Noize? No. I actually have a clock on the wall which displays the time as the number of dots illuminated for each digit. The sawtooth signal is due to the last digit of the time incrementing—pretty cool!
Hopefully I will be able to post some interesting motion sensor data snapshots soon.
The processing zip does not seem to match the screen output or description – do you have a more recent version that does this? I am attempting to send data to a thingspeak feed without luck…so far!
I’ll look into that and get back to you.
Sorry for replying so late.
There are two different files I linked to in the post: one labeledthingspeaktest.zip and the other labeled “click here to download”. Are you clicking on the second one? The first is just a test to make sure the configuration is working.
Is there an error message? I looked through the code and noticed that the API key was hardcoded instead of using the variable at the top, so I fixed that and uploaded a new version.
When you have more questions, I’m happy to help and I promise to reply sooner next time.
Keegan – thanks a lot for this tutorial and code, it’s really helpful!
After some playing around and following a lot of 301 errors returned from thingspeak.com, I found success posting by altering the main c.write line in the sendNumber function to the following:
c.write(“GET /update?key=”+APIKEY+”&”+FIELD+”=”+num+ “\n”);
Whereby I removed the HTTP/1.1 and instead just write the new line. (“\n”) I don’t get as verbose a return from thingspeak as your screengrab, however I was able to write my data reliably. I was unable to do so with the HTTP/1.1 line included.
I guess I’d ask you – why did you include the line there? Or was it unintentional?
Either way, I really appreciate the post as it was really helpful! Thanks!
Hi there everyone, it’s my first visit at this web site, and paragraph is genuinely fruitful in support of me, keep up posting these
types of articles.
Hi keegan,
Can we fuse (fusion) together light sensor with image processing data?
I’m not sure what you mean by fusing light sensor and image processing data. I graphed the light sensor data as a test and then went farther by graphing the output of a simple video motion calculation the same way.
What do you have in mind?
Hello there I am so glad I found your web site, I really found you by accident,
while I was researching on Aol for something else, Nonetheless I am
here now and would jujst like to say cheers for a tremendous post aand a all round exciting blog (I also love
the theme/design), I don’t have time to browse it all at the moment but
I have book-marked it and also added in your RSS feeds, so
when I have time I will bbe back to read more,
Please do keep up the fantastic work.
Great write-up, I’m normal visitor of one’s web site, maintain up the nice operate, and It’s going to be a regular visitor for a long time.
Thank you for sharing superb informations. Your website is very cool. I am impressed by the details that you’ve on this web site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found simply the information I already searched everywhere and simply could not come across. What a great web site.
Great web site you’ve got here.. It’s hard to find good quality writing like yours nowadays. I truly appreciate individuals like you! Take care!!