February 24, 2013

Siren light, or controlling 6 LEDs with a potentiometer

Introduction

Yesterday I've got a variable resistance (aka potentiometer) from an old car radio, and today morning my brother (age 5) asked me to build a robot with him. So we built a controllable siren:

As you can see there is much more wire than necessary. Well, that was my brother's part of the project :D

Purpose of the project

As seen above, if you turn the potentiometer the lights will "run" slower or faster.

What you need:

6 LEDs, if possible reds and blues
a potentiometer
an Ardunio microcontroller and a breadboard with wires

First step: wiring

Connect the 6 LEDs to the ground and to the pin 2,4,6,8,10,12.
Connect the middle pin of the potmeter to the pin A2 (analog input) and the other 2 to 5V and GND. (More info about potmeter in this tutorial: http://www.arduino.cc/en/Tutorial/Potentiometer)

Second step: programming

Here is the code:

int val = 0;       // variable to store the value coming from the sensor

void setup() {
  pinMode(2,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(6,OUTPUT); 
  pinMode(8,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(12,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  val = analogRead(2)+1000;    // read the value from the sensor, and add 1000, because if it's too small, we can't see anything
  Serial.println(val);        //write it on serial monitor

for(int i=1; i < 7; i++)
  {
   digitalWrite(i*2,HIGH);
   delay(val/15);
   digitalWrite(i*2,LOW);  
  }
for(int i=6; i > 0; i--)
  {
   digitalWrite(i*2,HIGH);
   delay(val/15);
   digitalWrite(i*2,LOW);  
  }
}

Best regards:
Mark

February 23, 2013

Scrapyard, or how to get cool stuff for free

Today I just realized, I've slept over a goldmine for years :D Because every time we bought a new car radio, or a new printer we didn't throw away the old one, just put it under my bed. So today I took out and disassembled 3 radios, and found many useful stuff. 
First of all I got 3 DC(?) motors, which used to spin the tape. I googled one of those and found that it's operating on 13.5 V. But it's working on 5 V too, so I can use them for my arduino projects.
I've also got several capacitors (2200 μF, 3300  μF, 220 μF) from the IC, and variable capacitors  variable resistor from the volume adjustments and some buttons from the front cover. I have to test them before use, but I'm sure, they're worth the effort.
So look under your bed or on your attic or basement, maybe you can find some broken devices which has useful stuff inside.

Best regards:
Mark

PS.: Here's some picture about the disassemble and the stuff I found:


LabVIEW - ardunio interface and image processing

LabVIEW Interface for Arduino Toolkit

I have started learning about LabVIEW at the uni. I made some search on it, and find some interesting stuff. First of all, it has an add-on for arduino and it isn't so hard to use it, thanks to that video:
So now I have a nice interface for my arduino, but it's still a little bit new and complicated for me to program in LabVIEW, so I'm going to stay with the original C++ coding. But it's going to be a cool example, when I'll make a presentation with my friend about serial communication in LabVIEW.

Image processing with LabVIEW

I have a big project about a shooting gallery, and for this project I need an image processing method with webcam and computer. First I thought about MATLAB, and found some very interesting videos, but afterwards I wondered, what if LabVIEW can also do this for me. And I found a video, which make my project a lot simpler:
With this tutorial I've made the half of my project in one day. There was only 2 problems during the process: first I can't find a VI, what he had used, so I googled on that and find out, it's part of an add-on  so I downloaded it. The other problem comes out, when I start to configure the Vision Assistant. It complained about my screen size/resolution. I've tried to change the resolution, but it didn't help. Finally I had to change the taskbar  to autohide to make it work. At the end I finished up here:
As you can see it sees and marks the middle of the target and the laser dot.
Now I only have to make the gun. It's a little bit complicated, because when you press the button the light should show up only for 0.1-0.2 second, and I'd like to solve it without an arduino, only with simple circuit elements. I'm going to see, what I can do.

Best regards:
Mark

February 22, 2013

First project, ardunio and distance sensor with LEDs

Introduction

This is my first project here, so be patient with me. I'm also sorry for my English, as you probably already noticed, I'm not a native speaker :D But I hope, you will find something helpfully here. If anything is not 100% clear, or need help, just ask. I will do my best, but it's impossible to make no mistakes, so if you find one, let me know.

The purpose of the project

So arduino. This project is basically for the beginners about how to control LED-s and use an ultrasonic distance meter sensor without an additional library. If there is nothing before the sensor, shows 0 led. When something is coming closer and closer at 30 cm the first led shows up, at 20 cm the second and at 10 cm the third. As you can see here:

What you need:

3 LED-s
3 220 ohm resistors (recommended, but not absolutely necessary)
1 HC-SR04 ultrasonic distance sensor
an Ardunio microcontroller and a breadboard with wires

First step: Wiring

The wiring is very simple. First you need 3 LEDs and 3 resistors. (I've used 220 ohm resistors, but you have some with other parameter, or you don't have resistance at all, it's not a so big problem. Theoretically you always have to use resistance before LED, because otherwise too many current is going to flow through the LED and it will kill it. But I tried this without any resistance, and it worked fine and none of my LEDs died.)  So connect the resistors to the arduino ground (GND) pin, then connect each resistance to a LED lastly connect the LED-s to 2, 4, 6 pin. Now the LED-s are ready, you need to wire the ultrasonic sensor. I've used a HC-SR04 module, because it's cheap and more than enough for this function.  Here it is:

As you can see, it has 4 pin. Connect the Vcc to 5V and GND to the ground pin. Connect the trig pin to 12 and echo  pin to 13. (Of course you can change these numbers in the code)
And here is the breadboard:


Second step: programming the microcontroller

If you are ready with wiring, you have only one job left: just copy and upload the code to your ardunio. The code also available here: http://codepad.org/TvZQ2v7O

//3 leds on pin 2, 4, 6
int a = 2;
int b = 4;
int c = 6;

//the ultrasonic sensors trig and echo are connected to pin 12 and 13
#define trigPin 12 
#define echoPin 13

//run only once at the beginning. Define pinMode-s depending on we gonna send or recive data from that
void setup() {
  //LEDs
    pinMode(a, OUTPUT);    
    pinMode(b, OUTPUT);  
    pinMode(c, OUTPUT);  
   //distance sensor
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT); 
}

// the loop routine runs over and over again forever:
void loop() {
  int duration, distance;
  //send the sound
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000); //wait a little bit
  digitalWrite(trigPin, LOW); //turn off the sound
  //perceive when it come back
  duration = pulseIn(echoPin, HIGH);
  //convert from time to distance (in cm)
  distance = (duration/2) / 29.1;
  //first turn off all the leds
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
 if(distance < 10) //if very close: 3 leds on
  {
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
  }
  else if(distance < 20) //if close: 2 leds on
  {
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
  }
  else if(distance < 30) //if not so far: only 1 led on
  {
     digitalWrite(a, HIGH); 
  }

}

Summary

It was one of my first project, and I recommend it for absolute beginners too. If you get stuck, just let me know, and I'm going to try to help you. More complicated projects are coming soon :P

Best regards:
Mark