21 June 2010

Major Project: Dual Sensors with Multiple Warnings - software & Serial Monitor

After a few false starts, i finally got this thing working.

It needs calibrating more accurately, but i haven't had the time to do that properly..

There's the usual warning about Blogger, as follows:

NOTE: this blogger doesn't like 'less-than' signs - it thinks they're HTML thingies..
so where you see n"10 put n 'less-than' 10
,
& where you see n""10 put n 'greater-than' 10.

VERY IMPORTANT!!
In the coding below there is a
#include EEPROM.h
statement.
Around the EEPROM.h there should be 'less-than' &
'greater-than' symbols.
these don't show up in these blog postings..
..AND - they disappear anything inside them as well, so..
..don't forget them!

/*
* Project: Major_Project_DualSensors_multiWarning
* Author: Jane-Maree Howard
* Date: Sunday 20/06/2010

* Platform: Arduino 18

* Purpose: To operate two different sensors - temperature & light -
& record their response at intervals, giving different warnings if either response moves outside pre-set limits. Results are sent to the Serial Monitor(SM).
* Operation:
Description:
Connect one end of a CdS Photocell to 5V, the other end to Analog 0. Then connect a 10K resistor from Analog 0 to ground.
This forms the light-recording voltage-divider circuit.

Connect one end of a Thermistor to 5V, the other end to Analog 1.
Then connect a 10K resistor from Analog 1 to ground.

This forms the temperature-recording voltage-divider circuit.
Connect the common cathode of a 3-colour LED to Ground,
& the Red,
Green & Blue anodes through 150-Ohm current-limiting resistors
to
digital-pins 12, 11, & 10 respectively.
Also connect one end of a buzzer to Ground,
& the other end
through a 100-Ohm resistor to digital-pin 9.
These form the light-&-sound warning circuit.

Connect one end of a push-button switch to Ground,
& the other end
to digital-pin 8.
Readings are all sent to EEPROM - the push-button
switch controls the EEPROM-reading process.
Include: EEPROM.h library

Declare: 2 Analog pins & their respective reading variables;

5 Digital pins for monitoring & warning circuitry.
Setup(): Connect to SM; initialise Analog & Digital pins;

Loop(): the program loops through its sensor data-logging,
until the push-button switch is pressed.
The program then reads all recorded data from EEPROM
& send it to the SM
* Comments: I don't know what the thermistor & photocell ranges are, but on past results I'd say more than 0-255. Rather than mess about with Hi-Lo bytes, better put in the Mapping Function
*/
#include EEPROM.h // needed for using EEPROM
byte photocellPin = 0; // the photocell and 10K pulldown are connected to a0

int photocellReading; // the analog reading from photocell voltage-divider

byte thermistorPin = 1; // the thermistor and 10K pulldown are connected to a1
int thermistorReading; // the analog reading from thermistor voltage-divider
int eepromAddress = 0; // start at EEPROM address zero

byte boardLedPin = 13; // on-board LED blinks when any reading is taken

byte redLedPin = 12; // RED LED connected to digital pin 12
byte grnLedPin = 11; // GREEN LED connected to digital pin 11
byte bluLedPin = 10; // BLUE LED connected to digital pin 10
byte buzzPin = 9; // buzzer pin

byte buttonPin = 8; // digital pin for switch connected to ground.



void setup()
{
Serial.begin(9600); // connect to SM
/* initialise the Analog recording pins as inputs */
pinMode(photocellPin,INPUT); // photocell pin

pinMode(thermistorPin,INPUT); // thermistor pin

/* initialise the Digital warning pins as outputs */

pinMode(boardLedPin, OUTPUT); // on-board LED monitors readings pinMode(redLedPin, OUTPUT); // Red LED
pinMode(grnLedPin, OUTPUT); // Green LED

pinMode(bluLedPin, OUTPUT); // Blue LED

pinMode(buzzPin, OUTPUT); // buzzer

/* initialise the push-button pin as an input & set HIGH */

pinMode(buttonPin, INPUT); // push-button pin
digitalWrite(buttonPin, HIGH); // turn on internal pull up

/* turn off all LEDs & buzzer */

digitalWrite(boardLedPin, LOW); // turn off on-board LED
digitalWrite(redLedPin, LOW); // turn off Red LED
digitalWrite(grnLedPin, LOW); // turn off Green LED
digitalWrite(bluLedPin, LOW); // turn off bluLedPin

digitalWrite(buzzPin, LOW); // turn off buzzer

}//end setup()


void loop()

{

// take readings until button pushed
while (digitalRead(buttonPin) == 1)

{

// read value on thermistor pin i.e. analog 1

thermistorReading = analogRead(thermistorPin); EEPROM.write(eepromAddress,map(thermistorReading, 0, 1023, 0, 255));

eepromAddress++;

digitalWrite(boardLedPin, HIGH);

delay(150);

readingWarning(map(thermistorReading, 0, 1023, 0, 255));
digitalWrite(boardLedPin, LOW); delay(350); // about half-a-second between readings
// read value on photocell pin i.e. analog 0

photocellReading = analogRead(photocellPin);
EEPROM.write(eepromAddress,map(photocellReading, 0, 1023, 0, 255));

eepromAddress++;

digitalWrite(boardLedPin, HIGH);

readingWarning(map(photocellReading, 0, 1023, 0, 255));

delay(150);

digitalWrite(boardLedPin, LOW);
delay(2500); // about 3 seconds before next readings
if (eepromAddress == 100)

eepromAddress = 0;

}//while()


Serial.println();

Serial.println("\tTemperature\tLight Level");

eepromAddress = 0;

while ( eepromAddress " 100)

{

Serial.print("\t\t");

Serial.print(int(EEPROM.read(eepromAddress))); //print temperature

eepromAddress++ ;

Serial.print("\t\t");

Serial.println(int(EEPROM.read(eepromAddress))); //print light level
eepromAddress++ ;

}//while()

}//end loop()



/* function copes with readings outside pre-set limits */

void readingWarning(int aReading)
{

if (aReading ""= 190)

{

blinkLEDnoise(grnLedPin,1800);

}//if()

if (aReading ""= 200)

{

blinkLEDnoise(redLedPin,2400);
}//if()
if (aReading "= 180)
{

blinkLEDnoise(grnLedPin,1200);

}//if()

if (aReading "= 170)

{ blinkLEDnoise(bluLedPin,600);
}//if()

}//end readingWarning()



/* function blinks LED & sounds buzzer */
void blinkLEDnoise(byte ledPin, int bTone)

{
tone(buzzPin,bTone,250);

for (byte n=0; n"10; n++)

{
digitalWrite(ledPin, HIGH);

delay(50);

digitalWrite(ledPin, LOW);

delay(50);
}//for(n++)
}//end blinkLEDnoise()


2 comments:

  1. finally i've got this thing done if not entirely dusted..

    ReplyDelete
  2. I was still writing this software @ Stupid O'clock on Monday morning - but then, i was wide awake, like much of NZ.
    I had a small mirror propped up beside my computer monitor so i could program AND watch the World Cup!!
    And since i grew up with 'Steam Radio', i just listened, kept half-an-eye on the mirror, & turned round whenever anything exciting happened..
    YAY, the All Whites!! :-) :-0 :-)
    Absolutely Amazing - holding world champions Italy to a 1-all draw: how good is that!!

    ReplyDelete