Tag Archives: CODE

ARDUINO UNO Project 04: Color Mixing Lamp

Published by:

Ingredients :

1- RGB LED                   #1

2- Phototransistor         #3

3- Resistor   220Ω         #3

4- Resistor   10KΩ         #3

5- Gel Red                    #1

6- Gel Green                 #1

7- Gel Blue                    #1

8- Wire

BUILD THE CIRCUIT

ARDUINO UNO Project 04: Color Mixing Lamp

ARDUINO UNO Project 04: Color Mixing Lamp

ARDUINO UNO Project 04: Color Mixing Lamp

ARDUINO UNO Project 04: Color Mixing Lamp

Code:
const int greenLEDPin=9;
const int blueLEDPin=10;
const int redLEDPin=11;

const int redSensorPin=A0;
const int greenSensorPin=A1;
const int blueSensorPin=A2;

int redValue=0;
int greenValue=0;
int blueValue=0;

int redSensorValue=0;
int greenSensorValue=0;
int blueSensorValue=0;

void setup() {
Serial.begin(9600);

pinMode(greenLEDPin,OUTPUT);
pinMode(blueLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
}

void loop() {
redSensorValue=analogRead(redSensorPin);
delay(5);
greenSensorValue=analogRead(greenSensorPin);
delay(5);
blueSensorValue=analogRead(blueSensorPin);

Serial.print(“Raw Sensor Value \t red: “);
Serial.print(redSensorValue);
Serial.print(” \t green: “);
Serial.print(greenSensorValue);
Serial.print(” \t blue: “);
Serial.println(blueSensorValue);

redValue=redSensorValue/4;
greenValue=greenSensorValue/4;
blueValue=blueSensorValue/4;

Serial.print(“Maped Sensor Value \t red: “);
Serial.print(redValue);
Serial.print(” \t green: “);
Serial.print(greenValue);
Serial.print(” \t blue: “);
Serial.println(blueValue);

analogWrite(redLEDPin,redValue);
analogWrite(greenLEDPin,greenValue);
analogWrite(blueLEDPin,blueValue);

}

ARDUINO UNO Project 03: Love-O-Meter

Published by:

Ingredients :

1- LED – RED                            # 3

2- Tempererature Sensor          #1

3- Wire

4- Resistor   220Ω                     #3

 

BUILD THE CIRCUIT

ARDUINO UNO Project 03 Love O Meter

ARDUINO UNO Project 03 Love O Meter

ARDUINO UNO Project 03 Love O Meter

 

Code:
const int SensorPin=A0;
const float baselineTemp=24.0;

void setup() {
for (int pinNum=3; pinNum<=5;pinNum++ ){
pinMode(pinNum, OUTPUT);
}
Serial.begin(9600);
}

void loop() {
int SensorValue=analogRead(SensorPin);
float voltage=(SensorValue/1024.0)*5.0;
float temperature=(voltage-.5)*100;

if(temperature<baselineTemp+2){
for (int pinNum=3; pinNum<=5;pinNum++ ){
digitalWrite(pinNum,LOW);}
} else if(temperature>= baselineTemp+2 && temperature<= baselineTemp+4 ){
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}else if(temperature> baselineTemp+4 && temperature<= baselineTemp+6 ){
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}else if (temperature> baselineTemp+6 ){
for (int pinNum=3; pinNum<=5;pinNum++ ){
digitalWrite(pinNum,HIGH);}
}
Serial.print(“Base Line Temp: “);
Serial.print(baselineTemp);
Serial.print(” , Sensor Value: “);
Serial.print(SensorValue);
Serial.print(” , Volts: “);
Serial.print(voltage);
Serial.print(” , Temperature: “);
Serial.println(temperature);

delay(250);

}

 

ARDUINO UNO Project 02: Spaceship Interface

Published by:

Ingredients :

1- LED – RED                      # 2

2- LED – GREEN                 # 1

3- Switch                             #1

4- Wire

5- Resistor   220Ω              #3

6- Resistor   10KΩ              #1

BUILD THE CIRCUIT

ARDUINO UNO Project 02: Spaceship Interface

ARDUINO UNO Project 02: Spaceship Interface

ARDUINO UNO Project 02: Spaceship Interface

 

 

Code:

int KeyState=0;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
KeyState=digitalRead(2);
if (KeyState==0){
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}else{
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);

delay(250);

digitalWrite(4,LOW);
digitalWrite(5,HIGH);

delay(250);

}

}