I am very new to Arduino and am following Jeremy Blum's book which has many projects for the beginner. I am not going chapter by Chapter but cherry picking things I am interested in. Also I am an old guy so have mercy on me please.
I was trying to set up and run the RGB Led "NightLight" project that uses a 18B20 temp sensor. I think, after re doing the breadboard over maybe 4 times I have it wired correctly. I used the proper resistors and a common GND 3 color RGB Led. I checked and rechecked that it was installed correctly
Rather than write the sketch myself I downloaded it from The books website. I checked the sketch in the IDE and it shows no errors.
Now the rub, Nothing happened. I went back and ran the blink sketch to see if possibly I had fried the UNO but blink works fine. I then hooked up the breadboard without the 18B20 and substituted a button which was a project to make the RGB turn on and once again everything checks out but nothing happened. I have many duplicate parts and I substituted all of them just to be sure.
One thing iI noticed in another project that my LCD backlight would not come on even though I had the rest of it working. I solved this problem by giving the backlight a separate power supply on the A/K pins.
What's going on here???? I am deeply puzzled
Thanks In Advance
David M.
Please post the code that you are having trouble with. Please read the "how to use the forum" stickies to see how to format and post code.
Do you have a data sheet for the LED? Can you show, with a photo or schematic, how things are wired?
Not sure I have posted this correctly.I use a Mac and sometimes the posting instructions aren't clear I am used to drag and drop.
Also I see that this material is Copyrighted but it does seem to allow this type of republishing.
/*
Exploring Arduino - Code Listing 2-6: Toggling LED Nightlight
http://www.exploringarduino.com/content/ch2
Copyright 2013 Jeremy Blum ( http://www.jeremyblum.com )
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License v3 as published by
the Free Software Foundation.
*/
const int BLED=9; //Blue LED on Pin 9
const int GLED=10; //Green LED on Pin 10
const int RLED=11; //Red LED on Pin 11
const int BUTTON=2; //The Button is connected to pin 2
boolean lastButton = LOW; //Last Button State
boolean currentButton = LOW; //Current Button State
int ledMode = 0; //Cycle between LED states
void setup()
{
pinMode (BLED, OUTPUT); //Set Blue LED as Output
pinMode (GLED, OUTPUT); //Set Green LED as Output
pinMode (RLED, OUTPUT); //Set Red LED as Output
pinMode (BUTTON, INPUT); //Set button as input (not required)
}
/*
* Debouncing Function
* Pass it the previous button state,
* and get back the current debounced button state.
*/
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON); //Read the button state
if (last != current) //if it's different...
{
delay(5); //wait 5ms
current = digitalRead(BUTTON); //read it again
}
return current; //return the current value
}
/*
* LED Mode Selection
* Pass a number for the LED state and set it accordingly
*/
void setMode(int mode)
{
//RED
if (mode == 1)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
//GREEN
else if (mode == 2)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
//BLUE
else if (mode == 3)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}
//PURPLE (RED+BLUE)
else if (mode == 4)
{
analogWrite(RLED, 127);
analogWrite(GLED, 0);
analogWrite(BLED, 127);
}
//TEAL (BLUE+GREEN)
else if (mode == 5)
{
analogWrite(RLED, 0);
analogWrite(GLED, 127);
analogWrite(BLED, 127);
}
//ORANGE (GREEN+RED)
else if (mode == 6)
{
analogWrite(RLED, 127);
analogWrite(GLED, 127);
analogWrite(BLED, 0);
}
//WHITE (GREEN+RED+BLUE)
else if (mode == 7)
{
analogWrite(RLED, 85);
analogWrite(GLED, 85);
analogWrite(BLED, 85);
}
//OFF (mode = 0)
else
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
}
void loop()
{
currentButton = debounce(lastButton); //read debounced state
if (lastButton == LOW && currentButton == HIGH) //if it was pressed...
{
ledMode++; //increment the LED value
}
lastButton = currentButton; //reset button value
//if you’ve cycled through the different options, reset the counter to 0
if (ledMode == 8) ledMode = 0;
setMode(ledMode); //change the LED state
}
Here is the schematic:
I wrote in a SerialRead and the serial monitor shows no values coming from the temp sensors data line.
So I am even more confused.The only think I can figure is that the values used for the 18B20 are far different from the TMP 36...which I don't have
David M
Wiring and code seem OK. Some breadboards have the upper and lower (power) rails split in the middle. Make sure that both ends are connected. Are you sure that the LED is common cathode?
There is no sensor in the code or Fritz.
Sorry I originally had it wired for a temp sensor. But when that did not work I went back to the button which also did not work. So just ignore that bit.
David M.