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
/* 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;
voidsetup(){ /* 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); }
voidloop() { 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); } } }
/* 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);
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.
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 you ever wondered if there was a way to store and retrieve data from a USB stick with an Arduino UNO? Most people choose SD cards to store their project data, but you may be surprised there IS a way! IC Station have a nice little module which allows you store and retrieve your Arduino (or other MCU) project data to a USB stick. I am not too sure why USB storage is not widely used in Arduino projects? These modules are not expensive, they have been around for quite a while, and are relatively simple to use. You do not need any libraries to get them to work, however, I must say that documentation for this module is not that easy to find. This site and this document proved to be very useful in my endevour to get this module working, and I hope my tutorial below will help you get started and bridge some of the information gaps. The...
Introduction Nextion is a programmable human machine interface (HMI) that can be customized and designed to simplify the interaction between you and your project. This Nextion Enhanced module (NX4827K043) with a resistive touch screen display, has some additional features not seen in previous traditional versions of the Nextion series. A built in real time clock (RTC) Accessible flash memory (32MB) GPIO functionality Faster clock speed Before you connect the Nextion Enhanced module to your project, you need to design your interface with the free Nextion Editor. The editor can be downloaded here. In this project, I will be designing a simple dynamic interface, which will allow me to interact with a stepper motor in two different ways. The first interface will let me control the direction and speed of the stepper motor through the use of a simple GUI. I will have left and right arrows for the direction, and up and down arrows for the speed. I will also map the Expansion board...
PART THREE If you happened to land on this page and missed PART ONE , and PART TWO , I would advise you go back and read those sections first. This is what you'll find in partone : Downloading and setting up the Android SDK Downloading the Processing IDE Setting up and preparing the Android device Running through a couple of Processing/Android sketches on an Andoid phone. This is what you will find in part two : Introducing Toasts (display messages) Looking out for BluetoothDevices using BroadcastReceivers Getting useful information from a discovered Bluetooth device Connecting to a Bluetooth Device An Arduino Bluetooth Sketch that can be used in this tutorial InputStream and OutputStream We will now borrow some code from the Android developers site to help us to establish communication between the Android phone and the Bluetooth shield on the Arduino. By this stage we have already scanned and discovered the bluetooth device and made a successful connection. We now need to create ...
Comments
Post a Comment