EoDC teaching program

From BoSL Wiki
Revision as of 04:49, 19 July 2022 by Bshi21 (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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