Pages: 1 [2]   Go Down
Author Topic: Will this basic LED circuit work?  (Read 1897 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int analogPin = 0;
int readValue = 0;
int redOne = 13;
int redTwo = 12;
int redThree = 11;
int redFour = 10;
int yellowOne = 9;
int yellowTwo = 8;
int yellowThree = 7;
int yellowFour = 6;
int greenOne = 5;
int greenTwo = 4;
int greenThree = 3;
int greenFour = 2;

float temperature = 0;
float temperatureF = 0;
void setup() {
 Serial.begin(9600);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}

void loop() {
 

  readValue = analogRead(analogPin);
  //Serial.println(readValue);
  temperature = (readValue * 0.0049);
  temperature = temperature * 100;
  temperatureF = (temperature * 1.8) + 32;
  Serial.print(temperature);
  delay(1000);

  if (temperature < 3)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,HIGH);
 
  delay(1000);
}

  if (temperature >= 3 && temperature < 6)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,HIGH);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 6 && temperature < 9)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,HIGH);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 9 && temperature < 12)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,HIGH);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 12 && temperature < 15)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,HIGH);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 15 && temperature < 18)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,HIGH);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 18 && temperature < 21)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,HIGH);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 21 && temperature < 24)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,HIGH);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 24 && temperature < 27)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,HIGH);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 27 && temperature < 30)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,HIGH);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 30 && temperature < 33)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,HIGH);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 33 && temperature < 36)
 
{
 
  digitalWrite(redOne,HIGH);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

}
Logged

Offline Offline
Faraday Member
**
Karma: 65
Posts: 2530
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Uploading...
Code:
byte index;
int readValue = 0;
int redOne = 13;
int redTwo = 12;
int redThree = 11;
int redFour = 10;
int yellowOne = 9;
int yellowTwo = 8;
int yellowThree = 7;
int yellowFour = 6;
int greenOne = 5;
int greenTwo = 4;
int greenThree = 3;
int greenFour = 2;

float temperature = 0;
float temperatureF = 0;
void setup()
{
 Serial.begin(9600);
 pinMode(2,OUTPUT);
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);
 pinMode(6,OUTPUT);
 pinMode(7,OUTPUT);
 pinMode(8,OUTPUT);
 pinMode(9,OUTPUT);
 pinMode(10,OUTPUT);
 pinMode(11,OUTPUT);
 pinMode(12,OUTPUT);
 pinMode(13,OUTPUT);
 trialrun();
}

void loop()
{
  readValue = analogRead(A0);
  //Serial.println(readValue);
  temperature = (readValue * 0.0049);
  temperature = temperature * 100;
  temperatureF = (temperature * 1.8) + 32;
  Serial.print(temperature);
  delay(1000);

  if (temperature < 3)   
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,HIGH);
   delay(1000);
  }

  if (temperature >= 3 && temperature < 6)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,HIGH);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 6 && temperature < 9)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,HIGH);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 9 && temperature < 12)
  {
 
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,HIGH);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 12 && temperature < 15)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,HIGH);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 15 && temperature < 18)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,HIGH);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 18 && temperature < 21)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,HIGH);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 21 && temperature < 24)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,HIGH);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 24 && temperature < 27)   
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,HIGH);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 27 && temperature < 30)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,HIGH);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 30 && temperature < 33)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,HIGH);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 33 && temperature < 36)
  {
   digitalWrite(redOne,HIGH);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }
}

void trialrun ()
{
  for (index = 2; index < 14; index++)
  {
    digitalWrite(index, HIGH);
    delay(500);
    digitalWrite(index, LOW);
    delay(500);
  }
}


... results?
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Problem solved  smiley thanks for your help!
Logged

Offline Offline
Faraday Member
**
Karma: 65
Posts: 2530
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Karma++ ?
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a perfect opportunity to ask the question. How do you give someone karma on this forum? Thanks  smiley-cool
Logged


Offline Offline
Faraday Member
**
Karma: 65
Posts: 2530
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pedro147,
Over on the left, with the personal stuff (stats), there's a Green Dot -- click on that when you find a post of value / "meritorious".
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry to labour over this but
Quote
Over on the left, with the personal stuff (stats), there's a Green Dot -- click on that
the left of what page? Thanks
Logged


Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

See attachment ...


* karma.gif (18.24 KB, 937x323 - viewed 28 times.)
Logged

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you KirAsh4. I should give you a karma point for showing me how to give karma points  smiley-cool
Logged


Offline Offline
Faraday Member
**
Karma: 65
Posts: 2530
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wherever did I go wrong?
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nowhere Runaway Pancake, I just needed to be shown exactly where. Thanks for your help too  smiley-lol
Logged


Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Runaway, you didn't go wrong anywhere.  Some of us, myself included, can, at times, be staring at something that's right in front of us, and still not see it.
Logged

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

KirAsh4 - Guilty as accused... I hang my head in shame  smiley-red
Logged


Pages: 1 [2]   Go Up
Jump to: