Good morning all,
I am a 9th grader working on a science project (www.instructables.com/id/Air-quality-balloons/) where I built a sensor to detect VOCs and an LED to react to the data to turn green, yellow, or red based on the low, average, and high values. I am trying to shift code from PICAXE Editor to Ardunio but it doesn't cross over well.
PICAXE code:
main:
'w5 = 448 'VOC GREEN'
'w6 = 470 'VOC RED'
goto runsensor
runsensor:
readadc10 4, w3'SENSOR VALUE'
if w3 < w5 then 'GREEN'
high 1
low 2
endif
if w3 >= w5 and w3 < w6 then 'YELLOW'
high 1
High 2
if w3 >= w6 the 'RED'
low 1
high 2
endif
pause 500
goto runsensor
Any ideas??? Thanks! (ps this code I got from the instructables website so I am hoping it is correct; I am shifting from PICAXE because PICAXE doesn't want to read the Tiny AVR Programmer that I purchased) doesn't want
Of course it doesn't. The picaxe is not programmed using C++. The Arduino is.
Any ideas???
Ditch the whole idea of trying to port the code. Understand what it actually does, and write the same thing in C++. Or, get the hardware that the destructable site actually used.
Start by looking at the examples in the IDE. They will show you how to read the state of a pin (either analogue or digital) and drive an LED pin HIGH or LOW.
Write out the logic of your program in pseudo code before writing it for real.
So, you need to find out how to read an analogue sensor, how to compare the value returned to some constants and how to turn on LEDs
Here is an outline
declare global variables such as sensible names for pins
start of setup()
set the pinModes() for the pins
start the Serial interface to allow debug messages to be output if required
end of setup()
start of loop()
read value from sensor
if value less than 449
turn on green LED
else
if value is less than 471
turn on the yellow LED
else
if value is greater than 470 (flaw in the logic here based on your description)
turn on the red LED
end if
end of loop()
oh meant if the sensor value was between 448 and 470 (not equal to 470) then the led would turn yellow...
i want the LEDs to stay on and the color they turn. My goal is that the LEDs will be inside a balloon and the balloon will turn the color of the LED and I can take pictures of them
Using the examples you should be able to work out how to implement the program using the Arduino as all the functions you require are illustrated in them as is the syntax and program layout required for the Arduino environment.
start of setup(){
set the pinModes() for the pins
start the Serial interface to allow debug messages to be output if required
end of setup()
}
start of loop()
read value from sensor
if value less than 449
turn on green LED
else
if value is greater than 449 and less than 471
turn on the yellow LED
else
if value is greater than 471
turn on the red LED
end if
end of loop()
i am having a lot of trouble understanding how to set the pinmodes.... the tutorials have examples using LEDs but don't show the range. What am I missing?
Can someone see if this would work for what I am trying to do? (Again I am trying to get a tri-colored LED to display green, yellow, red, based on a sensor's value (g<=448; 449<y<470; r >= 470) Many thank yous!!!
const int sensorPin = A0;
const int ledPin = 8;
int sensorValue = 0;
int sensorMin = 448;
int sensorMax = 470;