⚠️ This site is now a LEGACY SITE. For the new BOSL wiki, please navigate to https://www.boslwiki.com.au
Difference between revisions of "EoDC teaching program"
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...") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| 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 <OneWire.h> |
| − | #include <DallasTemperature.h> | + | #include <DallasTemperature.h> |
| − | #include <LiquidCrystal_I2C.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 ; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | EC = | ||
| − | |||
| − | reading = sensors.getTempCByIndex(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); | ||
| + | } | ||
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);
}