CEB Automation Sensor Code: Difference between revisions

From Open Source Ecology
Jump to navigation Jump to search
Line 6: Line 6:
//note - digital pins 0-13
//note - digital pins 0-13
//note - analog pins 14-19
//note - analog pins 14-19
//define initial function (void because it creates no output)
//define initial function (called void because it creates no real output?)


void setup(){
void setup(){
Line 13: Line 13:
   pinMode(6, OUTPUT);
   pinMode(6, OUTPUT);
   digitalWrite(5, HIGH);
   digitalWrite(5, HIGH);
}
//define ongoing loop
void loop(){}
//end
=Simple Test 2 - Move cylinder until it detects a sensor=
//begin
//note - digital pins 0-13
//note - analog pins 14-19
//define initial function (called void because it creates no real output?)
int val;
void setup(){
  pinMode(14,INPUT);//corresponds to analog input 0
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  digitalWrite(5, HIGH);
  val = analogRead(14);
  if (val < 500){
    digitalWrite(5,LOW)
}
}



Revision as of 04:10, 12 March 2010

Here is Arduino programming language (sketch) for the analog Hall effect sensors:

Simple Test 1

//begin //note - digital pins 0-13 //note - analog pins 14-19 //define initial function (called void because it creates no real output?)

void setup(){

 pinMode(14,INPUT);//corresponds to analog input 0
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 digitalWrite(5, HIGH);

}

//define ongoing loop void loop(){} //end

Simple Test 2 - Move cylinder until it detects a sensor

//begin //note - digital pins 0-13 //note - analog pins 14-19 //define initial function (called void because it creates no real output?)

int val;

void setup(){

 pinMode(14,INPUT);//corresponds to analog input 0
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 digitalWrite(5, HIGH);
 val = analogRead(14);
 if (val < 500){
   digitalWrite(5,LOW)

}

//define ongoing loop void loop(){} //end

Working Test Code for the Main Cylinder: bouncing up and down between two sensors

Note: the logic of this code is based on this straightforward tutorial

//begin int val;

void setup(){

 pinMode(14,INPUT);//corresponds to analog input 0
 pinMode(5, OUTPUT);//corresponds to solenoid - cylinder up
 pinMode(6, OUTPUT);//corresponds to solenoid - cylinder down

}

//define ongoing loop void loop(){

 val = analogRead(14)
   if (val < 500){
   digitalWrite(5, HIGH);
   digitalWrite(6, LOW);
   }
   else{
   digitalWrite(5, LOW);
   digitialWrite(6,HIGH)
   }

}

//en