Hi! Can some one help me with Arduino codes for converting analog signal to digital signal.
There four input analog signal wishing to convert each them to digital signal.
Hi! Can some one help me with Arduino codes for converting analog signal to digital signal.
There four input analog signal wishing to convert each them to digital signal.
what is your required sampling rate and resolution, also do you know the signal voltage range of the analog input is?
If you need more information about the analog inputs of the arduino look at:
http://arduino.cc/en/Tutorial/AnalogInputPins
The analogRead instruction is described here:
http://arduino.cc/en/Reference/AnalogRead
When you have your arduino IDE installed look in the examples, analog section
heliosoph
Thanx alot I have tried to code but I when I try to run my codes I encounter an error,so can any one help me to solve this issue.
int inputPins[] = {2,3,4,5}; // create an array of pins for inputs
int lcdPins[] = {0,1,2,3,4,5,6,7}; // create array of output pins for LEDs
void setup()
{
for(int index = 0; index < 3; index++)
{
pinMode(inputPins[index], INPUT); // declare inputpins
}
}
void loop(){
for(int index = 0; index < 4; index++)
{
analogRead(inputPins[index]); // read input val
}
float val0=analogRead(inputPins[0]);
float val1=analogRead(inputPins[1]);
float val2=analogRead(inputPins[2]);
float val3=analogRead(inputPins[3]);
if(val0 >=0.2){
digitalWrite( val0,HIGH);
}
else if (val1>= 1.5){
digitalWrite( val1,HIGH);
}
else if (val2>val 3){
digitalWrite(val2,HIGH);
}
else
digitalWrite( val0,LOW );
digitalWrite( val1,LOW );
digitalWrite( val2,LOW );
if (val0==LOW && val1==LOW && val2==LOW){
Serial.println("Blood group O-");
}
else if (val0==LOW && val1==LOW && val2==HIGH){
Serial.println("Blood group O+");
}
else if (val0==LOW && val1==HIGH && val2==LOW){
Serial.println("Blood group B- ");
}
else if (val0==LOW && val1==HIGH && val2==HIGH){
Serial.println("Blood group B+");
}
else if (val0==HIGH && val1==LOW && val2==LOW){
Serial.println("Blood group A-");
}
else if (val0==HIGH && val1==LOW && val2==HIGH){
Serial.println("Blood group A+");
}
else if (val0==HIGH && val1==HIGH && val2==LOW){
Serial.println("Blood group AB-");
}
else if (val0==HIGH && val1==HIGH && val2==HIGH){
Serial.println("Blood group AB+");
}
}
Hello Francis,
you have only a little typo in your code:
else if (val2>val 3){ digitalWrite(val2,HIGH); }
The space in "val 3" must be deleted:
else if (val2>val3){ digitalWrite(val2,HIGH); }
This should work. :-)
I think you have a mess with your variables:
digitalWrite( val0,HIGH);
val is your variable where you store your values from analogRead. In digitalWrite() you have to use a (digital) pin number. The pin you want to set to high.
Elektrix
I think you have a mess with your variables:
digitalWrite( val0,HIGH);
val is your variable where you store your values from analogRead. In digitalWrite() you have to use a (digital) pin number. The pin you want to set to high.
Elektrix
With this code still no change observed
#include <LiquidCrystal.h>
int inputPins[] = {2,3,4,5}; // create an array of pins for inputs
int lcdPins[] = {12,11,5,4,3,2}; // create array of output pins
LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
for(int index = 0; index < 3; index++)
{
pinMode(inputPins[index], INPUT); // declare inputpins
}
}
void loop(){
for(int index = 0; index < 4; index++)
{
analogRead(inputPins[index]); // read input val
}
float A0=analogRead(inputPins[0]);
float A1=analogRead(inputPins[1]);
float A2=analogRead(inputPins[2]);
float A3=analogRead(inputPins[3]);
if(A0 >=0.2){
digitalWrite( A0,HIGH);
}
else if (A1>= 1.5){
digitalWrite( A1,HIGH);
}
else if (A2>A3){
digitalWrite(A2,HIGH);
}
else
digitalWrite( A0,LOW );
digitalWrite( A1,LOW );
digitalWrite( A2,LOW );
if (A0==LOW && A1==LOW && A2==LOW){
lcd.println("Blood group O-");
}
else if (A0==LOW && A1==LOW && A1==HIGH){
lcd.println("Blood group O+");
}
else if (A0==LOW && A1==HIGH && A2==LOW){
lcd.println("Blood group B- ");
}
else if (A0==LOW && A1==HIGH && A2==HIGH){
lcd.println("Blood group B+");
}
else if (A0==HIGH && A1==LOW && A2==LOW){
lcd.println("Blood group A-");
}
else if (A0==HIGH && A1==LOW && A2==HIGH){
lcd.println("Blood group A+");
}
else if (A0==HIGH && A1==HIGH && A2==LOW){
lcd.println("Blood group AB-");
}
else if (A0==HIGH && A1==HIGH && A2==HIGH){
lcd.println("Blood group AB+");
}
else
lcd.println("device error");
}