Step 4Spray can
This version is more advanced, because it also measures the distance from the screen and the nozzle pressure. Both these things are important when you're actually spray painting. I wanted to make a training system, so it was important to make the system as "real" as possible (within my cost limits).
The circuit is pretty simple. Take a look at the attached circuit diagram to see for yourself. You need basic soldering skills and to be able to put a circuit onto veroboard. Also, you should feel happy with programming microcontrollers.
Building a circuit from scratch vs using an arduino board
option 1: if you want to use an arduino board in spray can. Use arduino as is and halve the baud rate of the radio tx in the spraycan code.
option 2: you want to save cash but you don't have a fuse programmer. Build the board and use a 16MHz external crystal. Halve the baud rate as in option 1.
option 3: you want to save even more cash and you have a fuse programmer. Build the board, but omit the external crystal. Use the fuse programmer to set the atmel to use its internal clock. I believe this DIY parallel programmer will allow you to program fuses. I use the olimex programmer.
Overview of the circuit
The microcontroller measures the output from the sharp 2d120x distance sensor (great info on this sensor here) and the linear potentiometer. It also measures the output of the LED PWM potentiometer. This is used to adjust the LED's light output. The IR LED I'm using is 100mA and peak wavelength is 950nm (ideal for wiimote).
The microcontroller uses PWM to flash the LED very fast. We use an IRF720 power mosfet so that the micro doesn't burn out its output. Also I wanted to add capacity for a brighter LED in the future.
There is a status LED that flashes everytime a data packet is broadcast on the radio. If everything is working well, this light should be flashing at around 15Hz.
Finally, the radio transmitter module is attached to pin 3 (digital pin 1 for arduino) of the microcontroller so that we can send the information we're measuring to the computer.
You also NEED an aerial attached to the receiver board. I used a 12cm long peice of wire. This is half what is recommended on this excellent info page.
Programming the microcontroller
After you've built the circuit, you'll need to upload the program (attached). I use the arduino programming environment/libaries. You can compile this with the arduino IDE, and then program it however you usually do.
My circuit is made simpler by using the internal 8MHz clock of the micro. If you use this you'll need to set the fuse settings to use the internal 8MHz calibrated RC: 1111 0010 = 0xf2
This means you'll need to have a programmer that can write fuses.
./avrdude -C ./avrdude.conf -V -p ATmega168 -P /dev/ttyACM0 -c stk500v2 -U lfuse:w:0xf2:m
If you don't have this kind of programmer (say you just have the arduino board), just use a 16MHz crystal between pins 9 and 10 and it should all work (untested - you may need a capacitor). You'll also need to modify the program code so that the transmitter baud is halved.
Testing
After you've got it all together and the program loaded, you need to adjust the IR LED brightness. I just wanted to maximise light output without toasting the LED so I blew a few up and ended up with about a 120ma draw average.
If you have a multimeter you can adjust this quite easily, otherwise just adjust the potentiometer to be quite high but not all the way! You can also check the analogue inputs on pins 26, 27 and 28 of the PWM adjust potentiometer, the distance sensor and the nozzle potentiometer.
If you have a scope you can check the pulse train coming out of pin 3 into the radio TX module. Check the pwm output of the LED on pin 11.
You can use a mobile phone camera (or most CCD cameras) to see the IR LED turn on when you press the nozzle button.
graffitiCan2.pde2 KB| « Previous Step | Download PDFView All Steps | Next Step » |













































What gives? Could you upload it again please? or mail the code over to stuchilds [at] gmail.com
Nice one, good work Matthew :)
I don't know why it changes the name. I tried uploading it again but same result.
For others: this pinout of the atmega/arduino will help:
http://arduino.cc/en/Hacking/PinMapping168
Next thing I'm struggling with is the external crystal osc:
I don't have the facilities to reset the fuse / timing on the atmega chip so thought would try to use an external 16MHz crystal.
[this one: http://uk.farnell.com/jsp/search/productdetail.jsp?CMP=i-ddd7-00001003&sku=9712526 ]
Now, as I am trying to build this circuit around an actual Arduino board I can't see a way of connecting the external osc. as pins 9/10 of the atmega chip do not have an external connection, they are linked to the onboard crystal.
Will keep updating progress.. Trying to use a pressure sensitive resistor instead of a linear pot. for the cap assembly instead in the hope that it will be a little more durable [plus I have some lying around to play with]
Lovely.
stuart
Basically, you only need to use external crystal if you're making a board from scratch and you don't have a fuse programmer.