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.
![]() Connecting the light sensitive resistor 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

Screenshot of the Processing app displaying in the background the motion currently occuring in the frame.
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)

My first bit of output from the system after leaving it running over night. Click for live graph of data.
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 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?