Sunday, October 30, 2011

Evil Pumpkin

I'm from Europe and we’re not celebrating Halloween, but I always wanted to carve a pumpkin.

So I’ve bought one and I carved it. At first I thought that a simple candle inside would be enough, but then I decided to go with arduino, LED, speaker and distance sensor. I’ve used my Nano, and for sensor I used my IR sensor. Here’s the video and code.


code:
int IRSense = A0;
int IRTrans = 2;
int Flick = 10;
int valueAmbient = 0;

void setup() {
 pinMode(IRSense, INPUT);
 pinMode(IRTrans, OUTPUT);
 digitalWrite(IRTrans,LOW);
}

void ambient()
{
 digitalWrite(IRTrans,HIGH);
 delay(20); 
 valueAmbient = analogRead(IRSense);
 delay(20);
}

void loop() 
{
 ambient();
 digitalWrite(IRTrans,LOW);
 delay(20);
 int value = analogRead(IRSense);
 int value2 = round(value - valueAmbient);
 int dist = (((value2+15.0)/(value2*(value2+100.0)))*2000.0);
 if(dist<20) 
  {
   analogWrite(Flick,random(0,256));
   tone(8, 38);
  }
 else
  {
   analogWrite(Flick,0);
   noTone(8);
  } 

Sunday, October 16, 2011

Arduino wireless sketch uploading via Bluetooth

Few months ago I’ve showed you my Bluetooth Xbee module. Back then I was able to send some commands through it to Arduino. But I wasn’t able to upload code wirelessly. 


I’ve been trying to solve this problem and I was successful. I found out that the issue is resetting the board. Since with this setup I’m not using USB connection I can’t use DTR pin on FTDI chip. So the trick to hold a reset button press upload and when information about size pops up just wait second or two and release the reset button. Right now I’m working on some sort of method (software or hardware) to make it automatic. I also found out that the baud rate of Bluetooth module and com port on your PC must be same as the uploading speed of the board you are using. For instance I’ve been using Arduino Duemilanove for this demonstration. Its upload speed is 57600. So I had to change baud rates of Bluetooth module and com port to 57600 as well. If you’re using laptop with a Bluetooth or pc with some USB Bluetooth module you need to buy only one module for your Arduino. You don’t even need to buy Xbee shield, because this particular one works if you connect just TX,RX,3v3 and GND pins. I was trying to use it with standalone Atmega8 but for some reason it didn’t worked so I’m also working on that. If you’re trying to achieve same thing and you’re having some issues with setup or whatever just contact me. And don’t forget to watch the video.