Sunday, August 23, 2015

Connecting ADC PCF8591 using IsquareC bus to Arduino R3 board

PCF8591 is a 8 bit ADC using sigma-delta conversion method. The chip is i2c bus enabled, which makes it easy to communicate with Arduino R3 board.
The circuit has been wired as shown below:
The A/D converter has 4 channels which can be selected using software. More A/D converters can also be added using the same SDA/SCL lines to connect more number of inputs. The whole circuit can be a template to interface multiple real-world sensors to the Arduino Ecosystem.
The code for the above is:-
// Example 52.4 PCF8591 ADC demo
// http://tronixstuff.com/tutorials Chapter 52
// John Boxall June 2013
#include "Wire.h"
#include
#define PCF8591 (0x90 >> 1) // I2C bus address
LiquidCrystal lcd(4,5,6,7,8,9); // define our LCD and which pins to use

byte value0, value1, value2, value3;
void setup()
{
 Wire.begin();
 Serial.begin(9600);
 lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit
  lcd.clear();      // this clears the LCD. You can use this at any time
}
void loop()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Welcome!");
  // prints "Hello" at the LCD's cursor position defined above
  lcd.setCursor(0,1);
  // positions starting point on LCD, column 0, row 1 (that is, the bottom left of our LCD)
  lcd.println("This is GDS!    ");
  delay(1000);
  // note the rest of the line is padded out with spaces

 Wire.beginTransmission(PCF8591); // wake up PCF8591
 Wire.write(0x04); // control byte - read ADC0 then auto-increment
 Wire.endTransmission(); // end tranmission
 Wire.requestFrom(PCF8591, 5);
 value0=Wire.read();
 value0=Wire.read();
 value1=Wire.read();
 value2=Wire.read();
 value3=Wire.read();
 delay(1000);
 //value1 = 0x55;
 if (value1 > 50)
 {
   lcd.clear();
   lcd.home();
   lcd.print("V101 GAS > 60%!!");
   delay(3000);
   //Serial.print("manoj");
 }

 //Serial.print(value0); Serial.print(" ");
 Serial.print(value1); Serial.print(" ");
 //Serial.print(value2); Serial.print(" ");
 //Serial.print(value3); Serial.print(" ");
 //Serial.println();
 lcd.noDisplay();
 delay(1000);
 lcd.display();
 delay(1000);

}

No comments: