hi guys, i've seen many topics about counters but using only push buttons or digital inputs, im doing a counter using the analogs pins as inputs, my goal is that when an analog pin reach a specific value (let's say 3v) the count add 1, i was trying to adapt a digital counter sketch to this but with no results, hope that you can help me..
LarryD:
To start off:
In your words, what happens in these lines?
pinMode (viauno, INPUT);
digitalWrite(viauno,LOW);
Do you have anything connected to Digital Pins 7,8,9 or 10?
nope, in digital pins 7,8,9,10 i want a pulse (viauno = 7, viados = 8,...), that pulse in this code will generate +1 in their respective count.
basically what i wanted to do is that when the analog pin read a voltage of 4v or more, the digital pin (7,8,9,10) will read a pulse to add 1 to the count.
pinMode (viauno, INPUT); //This makes viauno (pin 7 on the arduino) an INPUT. Which allows you to read digital state on that pin.
Now you have:
if (VoltajeV1 >= 4.0){
digitalWrite (7,LOW); // You are trying to use a digitalWrite to an INPUT pin (remenber viauno=7) . Why?
delay (10);
digitalWrite (7,HIGH);
pinMode (viauno, INPUT); //This makes viauno (pin 7 on the arduino) an INPUT. Which allows you to read digital state on that pin.
Now you have:
if (VoltajeV1 >= 4.0){
digitalWrite (7,LOW); // You are trying to use a digitalWrite to an INPUT pin (remenber viauno=7) . Why?
delay (10);
digitalWrite (7,HIGH);
that was my attemp to recreate a pulse in pin 7, but i guess it doesnt work like that, what can i do? i just want a pulse in 7,8,9,10 if there’s a voltage of 4 or higher on a specific analog pin
A Pulse is defined as a voltage change on a pin from some voltage to another voltage then back again.
Example: from 0 volts to 5 volts then back to 0 volts on pin 7 if it has been set up as an Output pin.
You wait at 5 volts for the period of time you desire. Is this what you want?
A Pulse is defined as a voltage change on a pin from some voltage to another voltage then back again.
Example: from 0 volts to 5 volts then back to 0 volts on pin 7 if it has been set up as an Output pin.
exactly that is what i want, a pulse, a 5-0-5 volt change on pin 7,8,9,10, for example, if i place a push button on pin 7 grounded, when i press that button, the counting is perfect, but i want that to happen with the analog input instead of a push button
tried that code and the counting works good, but it keeps counting forever when i only need only one count for each rise to more than 4v in analog pin
for example, i want that if i have a 0v in analog pin and rise to 4.5v and stays in 4.5v (for any amount of time) the count will still remain in "1", when the voltage fall to less than 4v and rise again to 4.5v the count will add one and so on.
When the analog >=4Volts you have to disable counting after it has incremented once.
When the voltage becomes <4Volts you have to enable counting.
So you have to introduce a blocking mechanism to achieve this.
See code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int SensorV1; //Used to store the analog reading
float VoltajeV1;
int aforouno=0; //our counter
boolean lock = false; //used to disable incrementing while voltage is >=4.0V
//***************
void setup (){
// Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor (0,0);
lcd.print("V1:");
} //End of setup()
//***************
void loop()
{
SensorV1 = analogRead (A0);
VoltajeV1 = SensorV1 * (5.0 / 1023.0);
if (VoltajeV1 >= 4.0 && lock ==false)
{
aforouno++;
// Serial.println(aforouno);
lcd.setCursor (3,0);
lcd.print(aforouno);
lock = true; //prevent further incrementing of the counter
}
if (VoltajeV1 < 4.0 )
{
lock = false; //the voltage is below 4.0
//allow incrementing of the counter
}
delay(100);
} //End of loop()
the first condition allows the counting and when the voltage reach 4 or more add one and blocks the counter, and the second condition unblock the counter when the voltage is less than 4.