6 posts tagged “sensor workshop”
Arduino code here.
Processing code here.
For this assignment I added some simple filtering to my homemade color sensor code. I added a button which you press when there is no object on top of the color sensor, and it records the color values and will stop spitting out color values serially if the red, green, and blue values are all within 10 of the value recorded when the button was pressed. So basically once you do this, if nothing is on top of the sensor it will stop sending values until you do put something on it. It works well, exactly as described, but of course it could create problems if you're testing an object that actually is that color! Being that I'm still not sure what people would use a homemade color sensor for besides various zany interactive art things I'm not sure if that's a problem.
The one project I'm planning on using this sensor for is an installation in a large room in which I'm going to mount a bunch of them all over the walls of a large empty room. I'm going to hand out flashlights of various colors and allow people to control sounds by pointing the flashlights at the sensors all over the room. For this project the filter should be useful, since I don't want any sounds happening if there isn't a bright light being pointed directly at the sensor.
DIY Color Sensor Using RGB LEDs and Photo Cell
From the beginning I of the semester I decided I would do my Sensor Report on either a color sensor or some kind of homemade sensor which had not yet been well documented. I ultimately ended up doing both.
I've had plans for a project involving color sensors since Winter Break, when some friends told me I should do a big interactive art piece using their entire loft space. I've done some other projects using flashlights and Cadmium Sulfide cells to control sound, and wanting to go further with this idea I figured an interesting way to add to it would be to control sound not only using light, but using the color of the lights for added variety (I imagine handing out flashlights with various colored gels on them. Yesterday someone suggested I somehow mount the flashlights on people's heads. Ha!). I didn't manage to work this into any of my classes so I'm planning on working on it over the Summer. I'll be sure to document the whole process on my blog.
I looked online and found some small amount of info on using RGB LEDs and photo cells, but all were written by people with significant tech know-how, and there was nothing which layed it out really thoroughly for people like us who want to be able to just plug everything in and copy some Arduino/Processing code and have a functioning sensor ready to go. So here it is.
Parts:
What you'll need:
1) 1 Adequately bright RGB LED, or adeuqately bright individual red, green, and blue LEDs
If the LEDs are not bright enough they will not reflect enough colored light off the sensed object and you won't get good values. Whereas the RGB LEDs Sparkfun sells are bright enough to work, the RGB LEDs I got from China on eBay are not more than half the brightness of the Sparkfun ones and don't work so well. The Sparkfun ones have luminosities of 800 mcd (millicandelas, which are I believe thousandths of a footcandle) for the red, 4000 mcd for the green, and 900 for the blue, so its safe to say anything at or over 800mcds will give you a good reading.
2) 1 Photocell
Obviously the stronger the photocell the better because it will give you a broader range of values.
3) 3 Switches or buttons
These aren't actually necessary but I used 2 buttons and 1 toggle switch. The buttons are for setting the white balance and black balance (more on that in a bit) and the switch is just to tell Arduino to run the color sensing function.
4) A piece of black foam
For black balancing
5) A piece of white paper of foam board
For white balancing
6) An Arduino
7) Some resistors and wires
8) A small black box with a hole in it
Not absolutely necessary, but you'll get better results from the sensor if you block out ambient light with a black box.
Putting it together:
1) Plug your photocell and RGB LED into your breadboard right next to each other so the tops of both are about vertically aligned.
2) Wrap the circumfrence of the photo cell in black electrical tape so that it reaches a little bit above the top of the photo cell so that it will block direct light coming from the LEDs.
3) Plug everything into the appropriate pins in Arduino. Photo cell into analog pin 2. Red, green, and blue pins of the LED into digital 4, 5, and 6. White and black balance into digital 2 and 3, and sensor on/off switch into pin 7. Remember your resisitors to ground for the photo cell and the switches!!
Programming Arduino and Processing:
Arduino code here
Processing data visualization code here
How it works:
Both the idea and the implementation are pretty simple. The idea is that when an LED of one color is switched on, an object placed in front of it will reflect back some amount of that color based on how much of that color the object contains. Thus by pointing a photo cell at this reflected light you can measure how much of that color the object has. Do this 3 times with red, green, and blue light and in theory you should be able to put the values together to get a color close to that of the object you're sensing.
But first....
White and Black Balancing and Normalizing the Values:
Before we start sensing we're going to need to find out what the minimum and maximum values we get from the photo cell when each LED is on so that we can normalize all of them. I built some code into the Arduino program to do this, and this is why we need buttons for setting white and black balancing as mentioned before. In the code it takes whatever the minimum and maximum are from each and makes it so any values between them will go from 0 to 255, making it as easy as possible to visualize the data in Processing.
To do this:
1) Hold your white piece of paper or foam board about an inch above the photo cell and LED, being sure its completely covering both of them.
2) Hit the White Balance button. The red, green, and blue LEDs should quickly blink one after another. When this happens the values have been recorded. These are the maximum values the photo cell can reach for each color, because nothing can reflect more red, green, and blue light than something pure white.
3) Do the same thing with the Black Balance button and the piece of black foam. This gives us our lowest possible values.
Color Sensing:
Stick the black box on top of the color sensor. Open the Processing app and set the white and black balance as described above. If it isn't already on, switch on the Sensing switch. Values should start coming into the Processing app. Put an object about an inch above the photo cell so the light from the LEDs hit it. See what values you get!
The sensor works best with objects which are NOT shiny. Foam and cloth work the best.
Right now it's far from perfect, but if you put a red, green, or blue object in front of it it will return roughly that color. Colors which are an RGB mixture are not incredibly accurate.
Uses:
1) Mobile appliances and consumer electronics
Automatic light adjustment for cell phones, displays, and such.
Code here.
I'm pretty set on using the DosOnChip as a nonvolatile storage device for my Phys Comp Studio project so I decided to use this as an opportunity to learn how to use it. I started off using Tom Igoe's DosOnChip Processing Terminal app to get comfortable with the commands before I started running it from Arduino. The code Tom provided doesn't quite explain the commands, and the User Guide is a bit cryptic, so I had to play around with it before I fully understood how to write to and read from it (no one else on the floor, or anyone I could find on the internet, seemed to fully understand it either). Here's what I gather about how it works so far:
Getting it ready to receive your commands:
You begin communication by sending 2 carriage returns (written as \r in Arduino) as bytes. As with any successful communication with it will return a byte of the greater than character >. This is it's way of telling you its ready for you to tell it to do something. After this I like to send it a q followed by /r, which quits out of any files which may be already be open. Having files open when you get started can cause problems but I'll get into that later.
Writing data to it from Arduino:
You start out by creating a new text file, or opening an existing text file.
After you receive your > byte, send it a string of ow followed by the name of the text file. If you give it the name of a text file which is on there, it will automatically create it for you. For example, send it
ow DATA1.TXT
and it will open that text file or create a new text file of that name.
It should return
1
which is now the "handle" (remember that word) for writing to DATA1.TXT for now. Once you've opened a file for reading or writing, you will tell the DosOnChip to read or write to it using it's handle, not the name of the text file.
Once we've done this, we can write to the text file with a string like this:
w #1 1
So to write bytes to a file you send it w, then the handle of the text file you want to write to (always with the pound sign in from of it), followed by the number of bytes you want to send it. Once you do this it will return a quotation mark
"
to tell you it's ready for your bytes. In the example above we tell it to get ready for 4 bytes, so we send it something like
asdf
and it returns
"
>
A close quote " to show it took what we sent it, and a fresh > to tell us it's ready for more commands.
Take the MicroSD card out and get a card reader and you should see a text file on it with the bytes you just wrote in it. Savor this moment.
You can keep using these same commands over and over and every time it will write the bytes to the end of your text file.
When I started working with it no one on the floor had had any luck getting it to work consistently. I had no idea where to even begin so I had Jeff send me his almost working code. I tested it out and it created a file and wrote to it the first time I used it, then never worked again. I emailed Jeff and told him this and he had the exact same problem. He also told me the problem might have something to do with the delay time between sending and receiving bytes, so my first impulse was to make the delays much longer. I tried using 1 second delays between every string or byte sent or received and magically everything worked! I still haven't determined what the minimum delay is, but it seems that a better way to go than cutting down the delay time until it stops working is to write code so that it can only send to the DosOnChop after its gotten the appropriate > go ahead from it.
ADJD-S371-QR999
Miniature Surface-Mount
RGB Digital Color Sensor Module
By Avago Technologies
Basic info:
-4 channels of digital output: reg, green, blue, and clear
-10 bit digital output
-I2C - 2 Wire serial bus consists of a serial clock (SCL) and a serial data (SDA) line. SDA is bi-directional and must be connected through a pull-up resistor to a positive power supply.
-Range 100-100,000 lux
Applications:
-Color detection
-Color measurement
-illumination sensing for adjusting color, contrast, and brightness enhancement in backlit displays
How to Use:
-For the Master to begin a serial communication it must a HIGH to LOW on the SCL while the SCL is HIGH. It terminates communication by sending a LOW to HIGH while SCL is HIGH.
-One bit is sent to the Master for every pulse on SCL. ONLY when a pulse on SCL has been completed and SCL is LOW can a bit be sent over SDA.
-Each data transfer is 10 bits: one bit to begin communication (from the Master), 8 bits of data from the sensor (from the Slave), and one to end the transfer (from the Master).
Questions:
Electrical Specifications (pages 2-5): Is any of this useful?
Addressing (page 10): "The slave address on ADJD-S371-QR999 is 0x74 (7-bits)." If they all have the same address, how to address multiple from one master?
Register info (pages 18-23): What does it all mean??
Arduino Code here.
Processing Code here.
I thought it would be nice to explicitly say in my Processing data visualization applet what is being graphed so I altered the Arduino-Processing code for three sensors from the Sensor Workshop wiki so that labels and the sensor values follow the actual graphed data as it moves along. You can set the labels to say whatever you want for whatever sensor or sensors you're using.
Here are the three descriptions I'm adding to the Manufacturer Descriptions Wiki:
Cosense: Digital and analog ultrasonic liquid level sensors.
Audiowell: Ultrasonic sensors and transducers, a shock sensor, and Piezo elements.
Sensicast: Does not sell individual sensors but an entire network of sensors built for commercial and industrial environments. Network consists of "Smart Sensors" which include humidity, temperature, current, vibration, pressure, and range sensors.
As of now I'm having trouble logging in and editting the wiki... but I'll post this up there when I figure it out.