Difference between revisions of "EoDC teaching program"

From BoSL Wiki
Jump to navigation Jump to search
 
Line 5: Line 5:
 
Please use the code before for the in-class activity.
 
Please use the code before for the in-class activity.
  
 
+
  #include <OneWire.h>
 
+
  #include <DallasTemperature.h>
#include <OneWire.h>
+
  #include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
+
 
#include <LiquidCrystal_I2C.h>
+
  // Data wire is conntec to the Arduino digital pin 8
// Data wire is connected to the Arduino digital pin 8
+
  #define ONE_WIRE_BUS 8
#define ONE_WIRE_BUS 8
+
 
// Setup a oneWire instance to communicate with any OneWire devices
+
  // Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
+
  OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor  
+
 
DallasTemperature sensors(&oneWire);
+
  // Pass our oneWire reference to Dallas Temperature sensor  
float reading;
+
  DallasTemperature sensors(&oneWire);
float EC=0 ;
+
 
LiquidCrystal_I2C lcd(0x20,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
+
  float reading;
void setup()
+
  float EC=0 ;
{
+
 
  // Start serial communication for debugging purposes
+
  LiquidCrystal_I2C lcd(0x20,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
  Serial.begin(9600);
+
 
  // Start up the library
+
  void setup()
  sensors.begin();
+
  {
  //**************Initialize the LCD*****************
+
    // Start serial communication for debugging purposes
  lcd.init();                       
+
    Serial.begin(9600);
  lcd.backlight();
+
   
//**************set up the pins for the EC sensor*****************
+
    // Start up the library
  pinMode(A0, INPUT);// EC analogue reading pin
+
    sensors.begin();
  pinMode(A1, OUTPUT);// initial EC power is A1
+
   
  pinMode(A2, OUTPUT);// initial EC GND is A2
+
    //**************Initialize the LCD*****************
   digitalWrite(A1, HIGH);//EC power is set to HIGH
+
    lcd.init();                       
  digitalWrite(A2, LOW); //EC Ground is set to LOW
+
    lcd.backlight();
  digitalWrite(A1, LOW);//EC power is set to HIGH
+
   
}
+
  //**************set up the pins for the EC sensor*****************
void loop(){  
+
   
  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
+
    pinMode(A0, INPUT);// EC analogue reading pin
  sensors.requestTemperatures();  
+
    pinMode(A1, OUTPUT);// initial EC power is A1
digitalWrite(A1, HIGH);
+
    pinMode(A2, OUTPUT);// initial EC GND is A2
  EC = analogRead(A0);
+
    
  EC = analogRead(A0);
+
    digitalWrite(A1, HIGH);//EC power is set to HIGH
  digitalWrite(A1, LOW);
+
    digitalWrite(A2, LOW); //EC Ground is set to LOW
  reading = sensors.getTempCByIndex(0);  
+
    digitalWrite(A1, LOW);//EC power is set to HIGH
  lcd.setCursor(0,0);
+
   
  lcd.print("Temp: ");
+
  }
  lcd.print(reading);
+
 
  lcd.print(" °C");
+
  void loop(){  
  lcd.setCursor(0,1);
+
    // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  lcd.print("EC: ");
+
    sensors.requestTemperatures();  
  lcd.print(EC);
+
 
  delay(1000);
+
  digitalWrite(A1, HIGH);
    }
+
    EC = analogRead(A0);
 +
    EC = analogRead(A0);
 +
    digitalWrite(A1, LOW);
 +
   
 +
    reading = sensors.getTempCByIndex(0);  
 +
    lcd.setCursor(0,0);
 +
    lcd.print("Temp: ");
 +
    lcd.print(reading);
 +
    lcd.print(" °C");
 +
    lcd.setCursor(0,1);
 +
    lcd.print("EC: ");
 +
    lcd.print(EC);
 +
   
 +
    delay(1000);
 +
      }

Latest revision as of 04:55, 19 July 2022

Programming BoSL

This page is for the EoDC training course at Bayswater Secondary College.

Please use the code before for the in-class activity.

 #include <OneWire.h>
 #include <DallasTemperature.h>
 #include <LiquidCrystal_I2C.h>
 
 // Data wire is conntec to the Arduino digital pin 8
 #define ONE_WIRE_BUS 8
 
 // Setup a oneWire instance to communicate with any OneWire devices
 OneWire oneWire(ONE_WIRE_BUS);
 
 // Pass our oneWire reference to Dallas Temperature sensor 
 DallasTemperature sensors(&oneWire);
 
 float reading;
 float EC=0 ;
 
 LiquidCrystal_I2C lcd(0x20,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
 
 void setup()
 {
   // Start serial communication for debugging purposes
   Serial.begin(9600);
    
   // Start up the library
   sensors.begin();
   
   //**************Initialize the LCD*****************
   lcd.init();                      
   lcd.backlight();
   
 //**************set up the pins for the EC sensor*****************
   
   pinMode(A0, INPUT);// EC analogue reading pin
   pinMode(A1, OUTPUT);// initial EC power is A1
   pinMode(A2, OUTPUT);// initial EC GND is A2
 
   digitalWrite(A1, HIGH);//EC power is set to HIGH
   digitalWrite(A2, LOW); //EC Ground is set to LOW
   digitalWrite(A1, LOW);//EC power is set to HIGH
   
 }
 
 void loop(){ 
   // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
   sensors.requestTemperatures(); 
 
 digitalWrite(A1, HIGH);
   EC = analogRead(A0);
   EC = analogRead(A0);
   digitalWrite(A1, LOW);
   
   reading = sensors.getTempCByIndex(0); 
    lcd.setCursor(0,0);
    lcd.print("Temp: ");
    lcd.print(reading);
    lcd.print(" °C");
    lcd.setCursor(0,1);
    lcd.print("EC: ");
    lcd.print(EC);
    
    delay(1000);
     }