What is an Arduino ?
If you have ever wanted a small gadget to control something with, Arduino is the answer.
The Arduino team have taken a microcontroller which is basically a single chip computer and built an easy to use physical computing platform around it.
You already have countless microcontrollers in your life, there is one in your washing machine for instance. On thier own microcontrollers can be very difficult to use, difficult enough to be beyond the access of all but the most dedicated hobbyists. What the Arduino team have done is produce a design which reduces the learning curve to the absolute minimum while still providing a powerful platform for project development.
What is most impressive about the arduino is the range of sensors available, my own interest is in measuring the effect of setup changes on my radio controlled cars and also in providing active in car control. There are off the shelf boards and software that literally allow the sensors I need to be plugged in to the Arduino with no need to seperatley source individual electronic components or even get deep into understanding thier purpose.
Its a bit like building a PC, if I need a graphics card, I buy a graphics card, I don't need to buy 300 components or even understand what they do, I just buy and plugin a ready made solution which does what I want.
Arduino does what I want.
Tuesday, December 6, 2011
What is an Arduino ?
Labels:
Arduino,
M03,
Micro Controller,
Radio Controlled Car,
RC Car,
Tamiya
Friday, August 19, 2011
Poor Man's Colour Detector (Part 2) - The project
In this project we will be detecting the colour of 3 different Mega Blok colours (Red, Yellow and Green). We will be using an Arduino UNO connected to 2 LEDs (one Yellow and one Red LED) as light detectors, and an RGB LED to illuminate the subject. We will use a Photocell to account for varying ambient light levels.
The signals from the LED light sensors will be sent to a Processing.org program via a Serial command. The computer program will make use of my Neural Network to classify the pattern of results and hopefully provide the correct colour "answer". The program should change the colour of the computer screen background to coincide with the colour of the Mega Blok.
The Video
Parts Required:
- Arduino UNO...........x1
- Red LED .................x1
- Yellow LED.............x1
- 330 Ohm resistors... x 5 (for the LEDs)
- Photocell .................x1
- 10K Ohm resistor....x1 (for the Photocell)
- Around 11 wires and a Breadboard (or two) to put it all together
Here is the Fritzing Sketch: (made with Fritzing)
The Arduino Code
Load the following code into the Arduino.
arduino code Arduino: Colour Detector
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* Define the pin for the PhotoResistor */
#define PhotoR_Pin 0
/* Define the pins for the Red LED Sensor */
#define Red_LED_Sensor_POS 4
#define Red_LED_Sensor_NEG 5
/* Define the pins for the Yellow LED Sensor */
#define Yellow_LED_Sensor_POS 7
#define Yellow_LED_Sensor_NEG 8
/* Define the pin for the RGB LED torch */
#define RGB_LED_RedPin 11
#define RGB_LED_GreenPin 10
#define RGB_LED_BluePin 9
/* Controls the brightness of the RGB LED */
int intensity=255;
/* Define the maximum cycles/time allowed for each LED to capture light */
long max_darkness=80000;
void setup(){
/* Setup the RED LED Sensor */
pinMode(Red_LED_Sensor_POS,OUTPUT);
digitalWrite(Red_LED_Sensor_POS,LOW);
/* Setup the YELLOW LED Sensor */
pinMode(Yellow_LED_Sensor_POS,OUTPUT);
digitalWrite(Yellow_LED_Sensor_POS,LOW);
/* No need to setup the RGB LED Pins */
/* Turn on Serial Protocol */
Serial.begin(9600);
}
void loop()
{
byte byteRead;
/* check if data has been sent from the computer: */
if (Serial.available()) {
/* read the most recent byte (which will be from 0 to 255): */
byteRead = Serial.read();
if(byteRead==0){
/* Turn off if the byte Read was 0 */
set_RGB_LED(0,0,0,false);
}else{
/* set the brightness of the LED and then take readings: */
set_RGB_LED(0,0,0,false);
photoR_Read();
set_RGB_LED(0,0,0,true);
set_RGB_LED(intensity,0,0,true);
set_RGB_LED(0,intensity,0,true);
set_RGB_LED(0,0,intensity,true);
}
}
}
void photoR_Read(){
int ambiLight = analogRead(PhotoR_Pin);
ambiLight = map(ambiLight, 0, 900, 0, 50);
ambiLight = constrain(ambiLight, 0, 50);
/* Print the Ambient light level to the serial port */
Serial.println(ambiLight);
}
void set_RGB_LED(int redInt, int greenInt, int blueInt, boolean takeReadings ){
/* set the brightness and colour of the RGB LED: */
analogWrite(RGB_LED_RedPin, redInt);
analogWrite(RGB_LED_GreenPin, greenInt);
analogWrite(RGB_LED_BluePin, blueInt);
/* If takeReadings is true - then take Readings. */
if(takeReadings){
/* Read the amount of Yellow light */
read_LED('Y', Yellow_LED_Sensor_NEG);
/* Read the amount of Red light */
read_LED('R', Red_LED_Sensor_NEG);
}
}
void read_LED(char LED_Colour, int LED_Pin){
/* Charge the LED by applying voltage in the opposite direction */
pinMode(LED_Pin,OUTPUT);
digitalWrite(LED_Pin,HIGH);
/* Read the amount of Light coming into the LED sensor */
long darkness=0;
int lightLevel=0;
pinMode(LED_Pin,INPUT);
digitalWrite(LED_Pin,LOW);
while((digitalRead(LED_Pin)!=0) && darkness < max_darkness){
darkness++;
}
lightLevel=((max_darkness-darkness)+1)/80;
/* Print the light level to the serial port */
Serial.println(lightLevel);
}
The Processing Code:
The processing code is very long:
Please visit this link to copy and paste the code into your Processing sketch.
http://www.openprocessing.org/visuals/?visualID=34210
Make sure to select "Source Code" when you get there: (as displayed below)
If you have any problems with accessing the code - please let me know in the comments section of this blog.
This sketch utilises a simple feed forward Neural Network (that I developed from scratch). For more detailed information about this neural network please navigate through my previous blog postings.
Neural Network
So there you go, a simple idea, a simple outcome, and a lot of "stuff" happening in the background.
I am sorry. This project is not basic, but hopefully someone out there will get some use out of it.
Have fun !
ScottC
Labels:
Arduino,
ArduinoBasics,
best arduino blog,
code,
color,
Colour,
LED as Sensor,
Mega Bloks,
Neural Network,
PhotoCell,
Processing,
project,
UNO
Monday, August 15, 2011
Neural Network (Part 7) : Cut and Paste Code
Ok - so you don't like tutorials, and would rather just cut and paste some code.
This is for you.
http://www.openprocessing.org/visuals/?visualID=33991
Make sure to select "Source code" when you get there, otherwise it will be quite boring.
Here is an animated gif which shows the program in action.
If you want to know how it works, then you will have to go back and read part 1 to 6.
But as you can see from the example above:
Before the neural network is trained, the outputs are not even close to the expected outputs. After training, the neural network produces the desired results (or very close to it).
Please note, this neural network also allows more than one output neuron, so you are not limited to single yes no decisions. You can use this neural network to make classifications. You will soon see this with my LED colour sensor.
Feel free to use this Neural Network in your own projects, but please let me know if you do, just for curiosity sake.
The above code was formatted using hilite.me
This is for you.
http://www.openprocessing.org/visuals/?visualID=33991
Make sure to select "Source code" when you get there, otherwise it will be quite boring.
Here is an animated gif which shows the program in action.
See BELOW for the WHOLE screenshot so that you don't have to speed read.
If you want to know how it works, then you will have to go back and read part 1 to 6.
Neural Network
But as you can see from the example above:
Before the neural network is trained, the outputs are not even close to the expected outputs. After training, the neural network produces the desired results (or very close to it).
Please note, this neural network also allows more than one output neuron, so you are not limited to single yes no decisions. You can use this neural network to make classifications. You will soon see this with my LED colour sensor.
Feel free to use this Neural Network in your own projects, but please let me know if you do, just for curiosity sake.
Update: See below for the Processing Sketch (much easier than going to the open processing site). It is a bit long - but saves you from having to navigate to another site.
Processing sketch
1 | /*Neural Network created by ScottC on 15th Aug 2011 |
Subscribe to:
Posts (Atom)





