Difference between revisions of "EoDC teaching program"

From BoSL Wiki
Jump to navigation Jump to search
(Created page with "==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> #i...")
 
Line 8: Line 8:
 
#include <DallasTemperature.h>
 
#include <DallasTemperature.h>
 
#include <LiquidCrystal_I2C.h>
 
#include <LiquidCrystal_I2C.h>
 
 
// Data wire is connected 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  
 
// Pass our oneWire reference to Dallas Temperature sensor  
 
DallasTemperature sensors(&oneWire);
 
DallasTemperature sensors(&oneWire);
 
 
float reading;
 
float reading;
 
float EC=0 ;
 
float EC=0 ;
 
 
LiquidCrystal_I2C lcd(0x20,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
 
LiquidCrystal_I2C lcd(0x20,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
 
 
void setup()
 
void setup()
 
{
 
{
 
   // Start serial communication for debugging purposes
 
   // Start serial communication for debugging purposes
 
   Serial.begin(9600);
 
   Serial.begin(9600);
 
 
 
   // Start up the library
 
   // Start up the library
 
   sensors.begin();
 
   sensors.begin();
 
 
 
   //**************Initialize the LCD*****************
 
   //**************Initialize the LCD*****************
 
   lcd.init();                       
 
   lcd.init();                       
 
   lcd.backlight();
 
   lcd.backlight();
 
 
 
//**************set up the pins for the EC sensor*****************
 
//**************set up the pins for the EC sensor*****************
 
 
 
   pinMode(A0, INPUT);// EC analogue reading pin
 
   pinMode(A0, INPUT);// EC analogue reading pin
 
   pinMode(A1, OUTPUT);// initial EC power is A1
 
   pinMode(A1, OUTPUT);// initial EC power is A1
 
   pinMode(A2, OUTPUT);// initial EC GND is A2
 
   pinMode(A2, OUTPUT);// initial EC GND is A2
 
 
   digitalWrite(A1, HIGH);//EC power is set to HIGH
 
   digitalWrite(A1, HIGH);//EC power is set to HIGH
 
   digitalWrite(A2, LOW); //EC Ground is set to LOW
 
   digitalWrite(A2, LOW); //EC Ground is set to LOW
 
   digitalWrite(A1, LOW);//EC power is set to HIGH
 
   digitalWrite(A1, LOW);//EC power is set to HIGH
 
 
 
}
 
}
 
 
void loop(){  
 
void loop(){  
 
   // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
 
   // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
 
   sensors.requestTemperatures();  
 
   sensors.requestTemperatures();  
 
 
digitalWrite(A1, HIGH);
 
digitalWrite(A1, HIGH);
 
   EC = analogRead(A0);
 
   EC = analogRead(A0);
 
   EC = analogRead(A0);
 
   EC = analogRead(A0);
 
   digitalWrite(A1, LOW);
 
   digitalWrite(A1, LOW);
 
 
 
   reading = sensors.getTempCByIndex(0);  
 
   reading = sensors.getTempCByIndex(0);  
 
   lcd.setCursor(0,0);
 
   lcd.setCursor(0,0);
Line 64: Line 49:
 
   lcd.print("EC: ");
 
   lcd.print("EC: ");
 
   lcd.print(EC);
 
   lcd.print(EC);
 
 
 
   delay(1000);
 
   delay(1000);
 
     }
 
     }

Revision as of 04:50, 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.

  1. include <OneWire.h>
  2. include <DallasTemperature.h>
  3. include <LiquidCrystal_I2C.h>

// Data wire is connected to the Arduino digital pin 8

  1. 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);
   }